void processExplodedFields(int teamIdx, Team team, ExplosionFieldCollector explodedFields) { int exceptionCntr = 0; while (!explodedFields.isEmpty()) { ++exceptionCntr; if (exceptionCntr > 1000) { throw new Exception("GameController.processExplodedFields(): counter error"); } List <ExplosionFieldCollector.OrderedFields> fieldsOrderedByDistance = explodedFields.popTheLeastTimeFactor(); ExplosionFieldCollector.OrderedFields[] fieldsOrderedByDist = fieldsOrderedByDistance.ToArray(); int distance = (fieldsOrderedByDistance.Count > 0) ? (fieldsOrderedByDist[0].DistanceFactor) : 0; int distancePointCntr = 0; for (int i = 0; i < fieldsOrderedByDist.Length; ++i) { BombermanBasics.Field currentField = fieldsOrderedByDist[i].FieldP; if (currentField != null) { List <BombermanBasics.Team> killedTeams; currentField.killTeamsOnField(out killedTeams); currentField.clearBombs(); //these bombs are now exploded foreach (Team killedTeam in killedTeams) { int oldPoints = killedTeam.Points; killedTeam.Points = oldPoints + distancePointCntr; //the survived teams got their points } foreach (Team survivedTeam in m_teams) { int oldPoints = survivedTeam.Points; survivedTeam.Points = oldPoints + GetNumberOfTeamsDead(); //the survived teams got their points } } if (fieldsOrderedByDist[i].DistanceFactor > distance) { distance = fieldsOrderedByDist[i].DistanceFactor; distancePointCntr++; } } } }
/// <summary> /// /// </summary> /// <param name="nextSteps">it contains the chosen steps of the given teams</param> private void ProcessSteps(AIStep[] nextSteps) { //process the explosions first for (int i = 0; i < nextSteps.Length; ++i) { Team currentPlayer = m_teams.ToArray()[i]; if (currentPlayer == null) { continue; } if (currentPlayer.Field == null) { continue; } if (currentPlayer.IsDead) //dead players doesn't do anything { continue; } if (nextSteps[i].nextStep == AIStep.StepEnum.EXPLODE) { Bomb[] currentPlayerBombs = currentPlayer.getBombs(); ExplosionFieldCollector explodedFields = new ExplosionFieldCollector(); for (int j = 0; j < currentPlayerBombs.Length; ++j) { m_gameBoard.explodeFields(this, currentPlayerBombs[j], explodedFields); } processExplodedFields(i, currentPlayer, explodedFields); } } //process the moves after explosions for (int i = 0; i < nextSteps.Length; ++i) { Team currentPlayer = m_teams.ToArray()[i]; if (currentPlayer == null) { continue; } if (currentPlayer.Field == null) { continue; } if (currentPlayer.IsDead) //players dead from the explosions doesn't do anything { continue; } if (nextSteps[i].nextStep == AIStep.StepEnum.PUT_BOMB) { bool isValid = false; if (MaxCountOfPlayerBombs <= 0 || (MaxCountOfPlayerBombs > 0 && currentPlayer.getNumberOfBombs() < MaxCountOfPlayerBombs)) { Bomb newBomb = new Bomb(currentPlayer, m_gameBoard, currentPlayer.Field, this, getExplosiveRadius(), out isValid); } } else if (nextSteps[i].nextStep == AIStep.StepEnum.MOVE) { Field target; if (getTargetField(currentPlayer.Field.X, currentPlayer.Field.Y, nextSteps[i].nextMove, out target)) { if (isValidToMove(target, m_gameBoard, currentPlayer)) { currentPlayer.Field.removeTeam(currentPlayer); target.addTeam(currentPlayer, i); } } } } }