public void Test_PlacePenguin_NotFirstTry_FishWithPenguin() { // Mock 0;0 then 1;1 Mock <IRandom> randomMock = new Mock <IRandom>(); randomMock.SetupSequence(e => e.Next(0, 8)) .Returns(0).Returns(0) .Returns(1).Returns(1); // Init game CustomGame customGame = InitGame(null); // Position of first cell int x = 0; int y = 0; // Set first cell Cell cell1 = (Cell)customGame.Board.Board[x, y]; cell1.CellType = CellType.FishWithPenguin; // Position of second cell x = 1; y = 1; // Set second cell Cell cell2 = (Cell)customGame.Board.Board[x, y]; cell2.FishCount = 1; // Launch function with Mock AIMedium aiMedium = new AIMedium(customGame.Board, randomMock.Object, customGame.CurrentPlayer); Coordinates coordinates = aiMedium.PlacePenguin(); // Test if the penguin is place on the second cell Assert.IsTrue(coordinates.X == 1 && coordinates.Y == 1); }
/// <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})"); } }
public void Test_PlacePenguin_FirstTry() { // Mock 0;0 Mock <IRandom> randomMock = new Mock <IRandom>(); randomMock.SetupSequence(e => e.Next(0, 8)).Returns(0); // Init Game CustomGame customGame = InitGame(null); // Position of cell to place the penguin int x = 0; int y = 0; // Set cell Cell cell = (Cell)customGame.Board.Board[x, y]; cell.FishCount = 1; // Launch function with Mock AIMedium aiMedium = new AIMedium(customGame.Board, randomMock.Object, customGame.CurrentPlayer); Coordinates coordinates = aiMedium.PlacePenguin(); Assert.IsTrue(coordinates.X == 0 && coordinates.Y == 0); }