//modified pathfinding... assume that agent can path through destructible walls //and simply calc path public Coords calcWallToDestroy(Coords from, Coords destination) { //path to destination, counting destructible walls as pathable PathPlan pathPlan = new PathPlan (this.gs); Graph g = pathPlan.mapQuantization (this.isBombPassable, true); List<Coords> path = pathPlan.calculateMovementPlan (g, from, destination); if ((path.Count == 0) && isBombPassable) { Console.WriteLine("MAP FAIL!"); //TODO JDP ???? this.cannotExecuteStrategy = true; } for (int i = 0; i < path.Count; i++) { //foreach (Coords coord in path) { Coords coord = path[i]; //first destructible wall encountered on path is the target LocationData datum = this.gs.GetLocationData (coord); if (datum.HasDestructibleWall ()) { Console.WriteLine("BlowUpWall found wall to blow up: " + coord); //find previous coord if (i-1 < 0) { //case where we can't move anywhere but we can blow up ourselves and a wall! return from; } else { Coords bombDropCoord = path[i-1]; return bombDropCoord; } } } return null; }
public Action[] GetMoves() { getMovesCalled = true; this.allAICanPath = true; Coords player = this.gs.GetAgentCoords (0); Action[] moves = new Action[this.gs.NumberAIBombermen]; PathPlan pathPlan = new PathPlan (this.gs); //Graph g = pathPlan.mapQuantization (true, false); //always use true here... otherwise AI can get stuck repeatedly dropping bombs (and won't move due to bombs) Graph g = pathPlan.mapQuantization (this.isBombPassable, false); //always use true here... otherwise AI can get stuck repeatedly dropping bombs (and won't move due to bombs) for (int i = 0; i < moves.Length; i++) { Coords aiBotCoords = this.gs.GetAgentCoords (i + 1); //1. Check if we have open path to player... if so, we're done for this bot List<Coords> path = pathPlan.calculateMovementPlan (g, aiBotCoords, player); if (path.Count > 0) { continue; //go to next bot... } this.allAICanPath = false; //2. If not done, check if we have path through destructible walls (should always have this given valid map) Coords wallCoords = calcWallToDestroy (aiBotCoords, player); //3. Path to the first destructible wall using regular pathing if (wallCoords != null) { Console.WriteLine("BlowUpWall pathing to wall " + wallCoords); path = pathPlan.calculateMovementPlan (g, aiBotCoords, wallCoords); if (path.Count > 0) { //4. Add first move on that path moves [i] = MovementUtil.getMovementActionType(aiBotCoords, path[0]); Console.WriteLine("Found move " + moves[i] + " for ai bot " + i+1 + " to blow up wall " + wallCoords); } else { moves[i] = new Action(Action.ActionType.BOMB); } } } return moves; }
public Coords findChokePoint(bool isBombPassable, BomberAgent owner) { //calc path from player to AI agent //walk the path, looking for any "choke point" tiles, defined as //a tile with exactly 2 adjacent accessible points, and those two are the previous //and next coords on the path PathPlan pathPlan = new PathPlan (this.gs); Graph g = pathPlan.mapQuantization (this.isBombPassable, false); Coords playerCoord = this.gs.GetAgentCoords (0); //player Coords aiCoord = this.gs.GetAgentCoords (owner.AgentId + 1); List<Coords> path = pathPlan.calculateMovementPlan (g, playerCoord, aiCoord); if (path.Count > 2) { //need path of length 3 to identify choke points //found a path, so test for choke point for (int i = 1; i < path.Count-1; i++) { Coords coord = path [i]; List<Coords> adj = this.gs.GetAdjacentAccessibleTiles (coord.getTileNum (), this.isBombPassable, false); if (adj.Count != 2) { continue; } Console.WriteLine("found candidate..." + coord); bool found = true; if ((!adj [0].Equals (path [i - 1]) && (!adj [0].Equals (path [i + 1])))) { found = false; } if ((!adj [1].Equals (path [i - 1]) && (!adj [1].Equals (path [i + 1])))) { found = false; } if (found) { Console.WriteLine("found choke point!!"); return coord; } } } return null; }
public Action[] GetMoves() { getMovesCalled = true; this.allSafe = true; Action[] moves = new Action[this.gs.NumberAIBombermen]; for (int i = 0; i < moves.Length; i++) { Coords botCoords = this.gs.GetAgentCoords (i + 1); bool shouldMove = this.gs.isOnExplosionPath (botCoords); if (shouldMove) { this.allSafe = false; //find a safe spot to move to... List<Coords> visited = new List<Coords> (); visited.Add (botCoords); Func<Coords, Coords, bool> isSafe = delegate(Coords coords, Coords from) { return (!this.gs.isOnExplosionPath (coords)); }; Coords safeCoords = Searches.greedyCoordsSearch (this.gs, botCoords, isSafe, true, visited); //isBombPassable true in case we're surrounded... search for a safe location nearby! if (safeCoords != null) { //move there... PathPlan pathPlan = new PathPlan (this.gs); Graph g = pathPlan.mapQuantization (true, false); List<Coords> path = pathPlan.calculateMovementPlan (g, botCoords, safeCoords); if (path.Count > 0) { Coords[] pathCoords = path.ToArray (); Action move = MovementUtil.getMovementActionType (botCoords, pathCoords [0]); moves [i] = move; } else { //C'est la vie! } } } } return moves; }
void GetPath(Message message) { path = (PathPlan)message; check_topic = true; }