public SimulationGame() { TurnInfos = null; BestSimulation = new SimulationInfos(); NewBest = false; NumTurn = 0; ActualScore = 0; }
private SimulationResult SimulateGame(GameTurnInfos infosTurn, GameInfosForDebug gameInfosDebug) { var rand = new Random(); var sr = new SimulationResult(); var simInfos = new SimulationInfos(); var moves = new List <Tuple <int, int> >(); var gameDebug = new GameInfosForDebug(); var turnInfosDebug = new DebugInfosForEachTurn(); simInfos.SimStartingRandomMovesNum = rand.Next(GameInfos.MAX_SIMULATION_RANDOM_STARTING_MOVES + 1); ComputePlayerTarget(infosTurn, simInfos); while (!simInfos.SimZombieAllDead && !simInfos.SimFailure && simInfos.SimMovesCount < GameInfos.MAX_MOVES) { // Simulate a turn of the game. simInfos.Moves.Add(Turn(infosTurn, sr, simInfos)); #if DEBUG_MODE turnInfosDebug.Nash = infosTurn.Nash; turnInfosDebug.SetHumansOrZombies(infosTurn.Humans); turnInfosDebug.SetHumansOrZombies(infosTurn.Zombies); turnInfosDebug.Points = sr.Points; turnInfosDebug.Move = simInfos.Moves.Last(); turnInfosDebug.NumTurn = simInfos.SimMovesCount; gameDebug.DebugInfosForTurn.Add(new DebugInfosForEachTurn(turnInfosDebug)); #endif simInfos.SimMovesCount++; } if (simInfos.SimZombieAllDead && !simInfos.SimFailure && ((sr.Points + ActualScore) > BestSimulation.SimPoints || (sr.Points + ActualScore) == BestSimulation.SimPoints && (simInfos.SimMovesCount < (BestSimulation.SimMovesCount - NumTurn)))) { simInfos.SimPoints = sr.Points + ActualScore; BestSimulation = simInfos; NewBest = true; #if DEBUG_MODE gameInfosDebug.SetDebugInfosForTurn(gameDebug.DebugInfosForTurn); #endif } return(sr); }
private void ComputePlayerTarget(GameTurnInfos infosTurn, SimulationInfos simInfos) { var rand = new Random(); var zombiesThatDoNotTargetPlayer = new List <Zombie>(); // If there is some random moves, we made Nash do the moves; otherwise we set a target for Nash. if (simInfos.SimStartingRandomMovesNum > 0) { infosTurn.Nash.NextPosition = new Tuple <int, int>(rand.Next(GameInfos.MAX_X), rand.Next(GameInfos.MAX_Y)); infosTurn.Nash.Target = null; simInfos.SimStartingRandomMovesNum--; } else { zombiesThatDoNotTargetPlayer.AddRange(infosTurn.Zombies.Where(x => x.Target != null)); // Define a zombie target for Nash : target is a zombie targetting a human, if there is at least one; any zombie in the map, otherwise. infosTurn.Nash.Target = (zombiesThatDoNotTargetPlayer.Count > 0) ? zombiesThatDoNotTargetPlayer[rand.Next(zombiesThatDoNotTargetPlayer.Count)] : infosTurn.Zombies[rand.Next(infosTurn.Zombies.Count)]; infosTurn.Nash.Arrived = false; } }
private Tuple <int, int> Turn(GameTurnInfos infosTurn, SimulationResult simResult, SimulationInfos simInfos) { var move = new Tuple <int, int>(-1, -1); foreach (Zombie zombie in infosTurn.Zombies) { FindZombieTarget(zombie, infosTurn); MoveZombie(zombie, infosTurn.Nash); } move = GetPlayerDestination(infosTurn.Nash); MovePlayer(infosTurn.Nash); Evaluate(infosTurn, simResult); ZombiesEat(infosTurn); if ((infosTurn.Humans.Count) > 0 && (infosTurn.Zombies.Count > 0)) { if (infosTurn.Nash.Arrived || infosTurn.NashTargetDiedThisTurn) { ComputePlayerTarget(infosTurn, simInfos); infosTurn.NashTargetDiedThisTurn = false; } } else { simInfos.SimFailure = (infosTurn.Humans.Count <= 0); simInfos.SimZombieAllDead = (infosTurn.Zombies.Count <= 0); } return(move); }