//deadEdge: first dead Edge to star //dir: direction where the wall will go on //wallDir: direction of the wall, left or right of the dir??? func checkForDeadWall(surface engine.Surface, deadEdge engine.Point, dir int8, wallDir int8) (bool, engine.Point) { possDead := deadEdge for { possDead = possDead.Add(engine.Direction(dir).Point()) if !surface.In(possDead) { return false, possDead } possField := surface[possDead.Y][possDead.X] possWallPos := possDead.Add(engine.Direction(wallDir).Point()) if !surface.In(possWallPos) { return false, possDead } possWall := surface[possWallPos.Y][possWallPos.X] if possField.Wall || possField.Point || !possWall.Wall { return false, possDead } else { dead, _ := DeadCorner(surface, possDead) if dead { return true, possDead } } } log.E(-1, "checkForDeadWall: end of For loop") return false, possDead }
// check, if given point is a dead corner func DeadCorner(surface engine.Surface, point engine.Point) (found bool, x int8) { var p engine.Point hit := false x = 0 found = false if surface[point.Y][point.X].Point { return } // check clockwise, if there is a wall or not. // If there is a wall two times together, corner is dead for i := 0; i < 5; i++ { x = int8(i % 4) p = point.Add(engine.Direction(x).Point()) if !surface.In(p) || surface[p.Y][p.X].Wall { if hit { found = true return } else { hit = true } } else { hit = false } } return }
func main() { log.DebugLevel = 4 runmode := false single := true level := "alevel" straightAhead := false outputFreq := int32(50000) printSurface := false threads := 1 e := engine.NewEngine() if len(os.Args) > 1 { for i, _ := range os.Args { switch os.Args[i] { case "-r": runmode = true case "-l": if len(os.Args) > i+1 { level = os.Args[i+1] } case "-i": engine.PrintInfo() case "-m": single = false case "-d": if len(os.Args) > i+1 { debuglevel, err := strconv.Atoi(os.Args[i+1]) if err == nil { log.DebugLevel = debuglevel } } case "-s": straightAhead = true case "-f": if len(os.Args) > i+1 { of, err := strconv.Atoi(os.Args[i+1]) if err == nil { outputFreq = int32(of) } } case "-p": printSurface = true case "-t": if len(os.Args) > i+1 { t, err := strconv.Atoi(os.Args[i+1]) if err != nil { panic(err) } else { threads = t } } } } } e.LoadLevel(level) log.I(e.Id, "Level: "+level) if runmode { ai.Run(e, single, outputFreq, printSurface, straightAhead, threads) return } // surface e.Print() var choice string for { choice = "" log.A("Press m for manual or r for run: ") fmt.Scanf("%s", &choice) if choice == "r" { ai.Run(e, single, outputFreq, printSurface, straightAhead, threads) break } else if choice == "m" { log.A("Manual mode\n") var input int for { fmt.Scanf("%d", &input) if input >= 0 && input <= 3 { e.Move(engine.Direction(input)) e.Print() } else { e.UndoStep() e.Print() } } break } } }