public void BuildPath(State state, ReliablePathBuilder path, int player) { len = path.len; originalLen = len; dirs[len - 1] = state.players[player].arrivePos.DirTo(path.coords[0]); coords[len - 1] = path.coords[0]; for (var i = 1; i < len; i++) { dirs[len - i - 1] = path.coords[i - 1].DirTo(path.coords[i]); coords[len - i - 1] = path.coords[i]; } }
public RandomWalkAi( IStartPathStrategy startPathStrategy, IPathEstimator estimator, bool useAllowedDirections, bool useTerritoryTtl, bool killWithMinimax) { this.startPathStrategy = startPathStrategy; this.estimator = estimator; this.useAllowedDirections = useAllowedDirections; randomPath = new RandomPathGenerator(); reliablePathBuilder = new ReliablePathBuilder(useTerritoryTtl); allowedDirectionsFinder = new AllowedDirectionsFinder(4, killWithMinimax); }
public bool Generate(State state, int player, DistanceMap distanceMap, InterestingFacts facts, ReliablePathBuilder pathBuilder, byte allowedDirectionsMask = 0xFF) { pathBuilder.Start(state, player, distanceMap); while (true) { if (pathBuilder.dir == null) { dirs[0] = Direction.Up; dirs[1] = Direction.Left; dirs[2] = Direction.Right; dirs[3] = Direction.Down; dirChances[0] = 1; dirChances[1] = 1; dirChances[2] = 1; dirChances[3] = 1; dirsCount = 4; random.Shuffle(dirs); } else { dirs[0] = pathBuilder.dir.Value; dirs[1] = (Direction)(((int)dirs[0] + 1) % 4); dirs[2] = (Direction)(((int)dirs[0] + 3) % 4); dirsCount = 3; if (random.Next(2) == 0) { var tmp = dirs[1]; dirs[1] = dirs[2]; dirs[2] = tmp; } if (random.Next(sameDirChance) == 0) { var other = random.Next(1, 3); var tmp = dirs[0]; dirs[0] = dirs[other]; dirs[other] = tmp; } } var found = false; for (var i = 0; i < dirsCount; i++) { var nextDir = dirs[i]; if (pathBuilder.len == 0 && (allowedDirectionsMask & (1 << (int)nextDir)) == 0) { continue; } var nextPos = pathBuilder.pos.NextCoord(nextDir); if (nextPos == ushort.MaxValue) { continue; } if (!pathBuilder.TryAdd(state, player, distanceMap, facts, nextPos)) { continue; } found = true; break; } if (!found) { return(false); } if (pathBuilder.started && state.territory[pathBuilder.pos] == player && (!pathBuilder.useTerritoryTtl || facts.territoryTtl[pathBuilder.pos] > pathBuilder.time)) { return(true); } } }