private void ApplyAction(int x, int y, Action action, PlayerState state) { //Console.WriteLine (action.ActionName.ToString ()); if (!action.ActionName.Equals (Action.ActionType.BOMB)) { int xCoord = x; int yCoord = y; if (action.ActionName.Equals (Action.ActionType.NORTH)) { yCoord = y - 1; } else if (action.ActionName.Equals (Action.ActionType.SOUTH)) { yCoord = y + 1; //Console.WriteLine ("moving south!!"); } else if (action.ActionName.Equals (Action.ActionType.EAST)) { //Console.WriteLine ("moving east!!"); xCoord = x + 1; } else if (action.ActionName.Equals (Action.ActionType.WEST)) { //Console.WriteLine ("moving west!!"); xCoord = x - 1; } LocationData datum = GetLocationData (x, y); LocationData.Tile newObject = state.PlayerObject; datum.RemoveObject (newObject); LocationData target = GetLocationData (xCoord, yCoord); target.AddObject (newObject); state.Location = Coords.coordsXY (xCoord, yCoord, this.width, this.height); } else { //check that agent has enough bombs... //if (state.Bombs > 0) { LocationData datum = GetLocationData (x, y); datum.BombDropTime = DateTime.Now; datum.ExplosionRadius = EXPLOSION_RADIUS; datum.BombOwner = state; datum.AddObject (LocationData.Tile.BOMB); state.Bombs = state.Bombs - 1; this.liveBombs.Add (Coords.coordsXY (x, y, width, height)); //} } }
/* private LocationData.Tile GetPlayerTile(int playerNum) { if (playerNum == 0) { return LocationData.Tile.PLAYER; } else if (playerNum == 1) { return LocationData.Tile.AI_1; } else if (playerNum == 2) { return LocationData.Tile.AI_2; } else if (playerNum == 3) { return LocationData.Tile.AI_3; } else { return LocationData.Tile.AI_4; } } */ private bool IsLegalAction(int x, int y, Action action, PlayerState state) { //if a move in a direction, check that the tile in the direction is empty //Console.WriteLine ("checking action " + action.ActionName.ToString ()); if (!action.ActionName.Equals (Action.ActionType.BOMB)) { int xCoord = x; int yCoord = y; if (action.ActionName.Equals (Action.ActionType.NORTH)) { yCoord = y - 1; } else if (action.ActionName.Equals (Action.ActionType.SOUTH)) { //Console.WriteLine ("found south"); yCoord = y + 1; } else if (action.ActionName.Equals (Action.ActionType.EAST)) { xCoord = x + 1; } else if (action.ActionName.Equals (Action.ActionType.WEST)) { xCoord = x - 1; } if (IsInvalidLoc (xCoord, yCoord)) { //Console.WriteLine ("invalid"); return false; } else { LocationData data = GetLocationData (xCoord, yCoord); List<LocationData.Tile> objects = data.Objects; bool valid = true; //Console.WriteLine ("checking empty"); foreach (LocationData.Tile datum in objects) { //Console.WriteLine ("datum" + datum.ToString ()); if ((datum.Equals (LocationData.Tile.DESTRUCTIBLE_WALL)) || (datum.Equals (LocationData.Tile.INDESTRUCTIBLE_WALL)) || (datum.Equals(LocationData.Tile.BOMB))) { valid = false; //Console.WriteLine ("not empty!"); } if (state != null) { // Player cannot walk through AI if (state.PlayerObject.Equals(LocationData.Tile.PLAYER)) { if (datum.Equals(LocationData.Tile.AI_1) || datum.Equals(LocationData.Tile.AI_2) || datum.Equals(LocationData.Tile.AI_3) || datum.Equals(LocationData.Tile.AI_4)) { valid = false; } } // AI cannot walk through player if (state.PlayerObject.Equals(LocationData.Tile.AI_1) || state.PlayerObject.Equals(LocationData.Tile.AI_2) || state.PlayerObject.Equals(LocationData.Tile.AI_3) || state.PlayerObject.Equals(LocationData.Tile.AI_4)) { if (datum.Equals(LocationData.Tile.PLAYER)) { valid = false; } } } } //Console.WriteLine ("return valid " + valid); return valid; } } else { //if a bomb, check that the player has bombs available to place //and that there is no bomb already at the location Coords coord = Coords.coordsXY(x, y, width, height); LocationData datum = GetLocationData(coord); if ((!datum.HasBomb()) && (state.Bombs > 0)) { return true; } else { return false; } } }
//Pass in LocationData.Tile.PLAYER or LocationData.Tile.AI_1, etc. public void InitBomberman(LocationData.Tile tile, Coords coords) { PlayerState state = new PlayerState (tile); state.Bombs = 1; state.Location = coords; if (tile.Equals (LocationData.Tile.PLAYER)) { //state.Bombs = 4; this.playerState = state; this.bombermanSpawnPoints [0] = coords; } else if (tile.Equals (LocationData.Tile.AI_1)) { this.aiState [0] = state; this.bombermanSpawnPoints [1] = coords; this.numAIBombermen++; } else if (tile.Equals (LocationData.Tile.AI_2)) { this.aiState [1] = state; this.bombermanSpawnPoints [2] = coords; this.numAIBombermen++; } else if (tile.Equals (LocationData.Tile.AI_3)) { this.aiState [2] = state; this.bombermanSpawnPoints [3] = coords; this.numAIBombermen++; } else if (tile.Equals (LocationData.Tile.AI_4)) { this.aiState [3] = state; this.bombermanSpawnPoints [4] = coords; this.numAIBombermen++; } }