/* private Action guardWallsMove (FSM<BomberAgent> fsm) { State<BomberAgent> current = fsm.getCurrentState (); Action move = null; State<BomberAgent> nextState = null; if (current is PredictDestinationState) { if (current.fail (this)) { nextState = new BlastWallState (this.gs, false); } else if (current.complete(this)) { nextState = new BombState(this.gs); } } else if (current is BlastWallState) { if (current.fail (this) || current.complete (this)) { nextState = new EvadeExplosionState(this.gs); } } else if (current is BombState) { if (current.fail (this) || current.complete (this)) { nextState = new EvadeExplosionState(this.gs); } } else if (current is EvadeExplosionState) { if (current.fail (this) || current.complete (this)) { nextState = new PredictDestinationState(this.gs, this.isBombPassable); } } if (nextState != null) { Console.WriteLine ("Agent " + this.agentId + " switching to " + nextState.GetType ().ToString ()); fsm.changeState (nextState); } move = fsm.getCurrentState ().getAction (this); Console.WriteLine ("Agent " + this.agentId + ", state " + fsm.getCurrentState ().GetType ().ToString () + ", move " + move); return move; } */ private Action surroundPlayerFSM(FSM<BomberAgent> fsm) { State<BomberAgent> current = fsm.getCurrentState(); Action move = null; //check if blowing up stuff and we need to evade bombs!! //if (current is BlastWallState) { //for (int i = 0; i < this.gs.NumberAIBombermen; i++) { Coords botCoords = this.gs.GetAgentCoords(this.agentId + 1); bool shouldMove = this.gs.isOnExplosionPath(botCoords); if (shouldMove) { State<BomberAgent> newState = new EvadeExplosionState(this.gs); Console.WriteLine("Agent " + this.agentId + " switching to EvadeExplosionState"); fsm.changeState(newState); move = fsm.getCurrentState().getAction(this); Console.WriteLine("Agent " + this.agentId + ", state " + fsm.getCurrentState().GetType().ToString() + ", move " + move); return move; } //} //} if (current.fail(this)) { Console.WriteLine("Failed strategy " + current.GetType()); if (current is SurroundState) { //Chaaarrge!! Blow our way to the player!!! Console.WriteLine("Switching to BlastWallState"); BlastWallState newState = new BlastWallState(this.gs, false); fsm.changeState(newState); } else if (current is BombState) { Console.WriteLine("Switching to SurroundState"); //this.current = new Surround(this.gs, this.surroundIgnoreBombs); //this.current = new Surround(this.gs, this.isBombPassable); SurroundState newState = new SurroundState(this.gs, this.isBombPassable); fsm.changeState(newState); } else if (current is BlastWallState) { //map fail.... ruh roh Console.WriteLine("AI can't move... map fail"); //switch to BombState as last-ditch resort... Console.WriteLine("Switching to BombState"); BombState newState = new BombState(this.gs); fsm.changeState(newState); } } if (current.complete(this)) { Console.WriteLine("Agent " + this.agentId + " completed strategy " + current.GetType()); if (current is SurroundState) { //this.current = new KillPlayer(this.gs); Console.WriteLine("Switching to BombState"); BombState newState = new BombState(this.gs); fsm.changeState(newState); } else { //this.current = new Surround(this.gs, this.surroundIgnoreBombs); //this.current = new Surround(this.gs, this.isBombPassable); SurroundState newState = new SurroundState(this.gs, this.isBombPassable); Console.WriteLine("Agent " + this.agentId + " switching to SurroundState"); fsm.changeState(newState); } } //fsm.getCurrentState().execute(this); //return this.current; move = fsm.getCurrentState().getAction(this); Console.WriteLine("Agent " + this.agentId + ", state " + fsm.getCurrentState().GetType().ToString() + ", move " + move); return move; }
private Action blockEscapeMove(FSM<BomberAgent> fsm) { State<BomberAgent> current = fsm.getCurrentState(); Action move = null; State<BomberAgent> nextState = null; if (current is PursueState) { if (current.fail(this)) { nextState = new BlastWallState(this.gs, false); } else { //check for four adjacent locations open near player Coords playerCoords = this.gs.GetAgentCoords(0); List<Coords> adj = this.gs.GetAdjacentAccessibleTiles(playerCoords.getTileNum(), this.isBombPassable, false); if (adj.Count == 4) { nextState = new SurroundState(this.gs, this.isBombPassable); } else { Coords choke = this.chokepoints.findChokePoint(this.isBombPassable, this); if (choke != null) { nextState = new CutOffChokePointState(this.gs, this.isBombPassable, choke); } } } } else if (current is BlastWallState) { if (current.fail(this) || current.complete(this)) { nextState = new EvadeExplosionState(this.gs); } } else if (current is CutOffChokePointState) { //Coords choke = this.chokepoints.findChokePoint(this.isBombPassable, this); //if ((choke == null) || current.fail(this)) { if (current.fail(this)) { nextState = new PursueState(this.gs, this.isBombPassable); } else if (current.complete(this)) { nextState = new BombState(this.gs); } } else if (current is BombState) { if (current.fail(this) || current.complete(this)) { nextState = new EvadeExplosionState(this.gs); } } else if (current is EvadeExplosionState) { if (current.fail(this) || current.complete(this)) { Coords choke = this.chokepoints.findChokePoint(this.isBombPassable, this); if (choke == null) { nextState = new PursueState(this.gs, this.isBombPassable); } else { nextState = new CutOffChokePointState(this.gs, this.isBombPassable, choke); } } } else if (current is SurroundState) { if (current.fail(this)) { nextState = new PursueState(this.gs, this.isBombPassable); //move to default state } else if (current.complete(this)) { nextState = new BombState(this.gs); } } if (nextState != null) { Console.WriteLine("Agent " + this.agentId + " switching to " + nextState.GetType().ToString()); fsm.changeState(nextState); } move = fsm.getCurrentState().getAction(this); Console.WriteLine("Agent " + this.agentId + ", state " + fsm.getCurrentState().GetType().ToString() + ", move " + move); return move; }