public void Test_PlacePenguin_isNearFalse() { // Mock 1;0 then 2;2 Mock <IRandom> mock = new Mock <IRandom>(); mock.SetupSequence(e => e.Next(0, 8)) .Returns(1) .Returns(0) .Returns(2) .Returns(2); //Init Game CustomGame customGame = InitGame(null); for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { // Set all cells of the board with 2 points Cell cell2 = (Cell)customGame.Board.Board[i, j]; cell2.FishCount = 2; } // Set 8 cells of the board with 1 points Cell cell = (Cell)customGame.Board.Board[i, i]; cell.FishCount = 1; } // Launch function with mock AIHard aiHard = new AIHard(customGame.Board, mock.Object, customGame.CurrentPlayer); Coordinates coordinates = aiHard.PlacePenguin(); // Test Assert.IsTrue(coordinates.X == 2 && coordinates.Y == 2); }
/// <summary> /// Place penguin for AI /// </summary> public void PlacePenguin() { // If AI is easy if (CurrentPlayer.PlayerType == PlayerType.AIEasy) { // Call AIEasy AIEasy aiEasy = new AIEasy(Board, random, CurrentPlayer); // Get coordinates Coordinates coordinates = aiEasy.PlacePenguin(); // Apply changes ChangeStatePlace(coordinates.X, coordinates.Y); // Log penguin placement ILog log = LogManager.GetLogger(GetType().ToString()); log.Info($"{CurrentPlayer.Name} placed a penguin on cell ({coordinates.X}, {coordinates.Y})"); } // If AI is medium else if (CurrentPlayer.PlayerType == PlayerType.AIMedium) { // Call AIMedium AIMedium aiMedium = new AIMedium(Board, random, CurrentPlayer); // Get coordinates Coordinates coordinates = aiMedium.PlacePenguin(); // Apply changes ChangeStatePlace(coordinates.X, coordinates.Y); // Log penguin placement ILog log = LogManager.GetLogger(GetType().ToString()); log.Info($"{CurrentPlayer.Name} placed a penguin on cell ({coordinates.X}, {coordinates.Y})"); } // If AI is hard else if (CurrentPlayer.PlayerType == PlayerType.AIHard) { // Call AIHard AIHard aiHard = new AIHard(Board, random, CurrentPlayer); // Get coordinates Coordinates coordinates = aiHard.PlacePenguin(); // Apply changes ChangeStatePlace(coordinates.X, coordinates.Y); // Log penguin placement ILog log = LogManager.GetLogger(GetType().ToString()); log.Info($"{CurrentPlayer.Name} placed a penguin on cell ({coordinates.X}, {coordinates.Y})"); } }