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); }
public void Test_PlacePenguin_getFishNearEmpty() { // Init game CustomGame customGame = InitGame(null); // Init AI Hard AIHard aiHard = new AIHard(customGame.Board, new AppRandom(), customGame.CurrentPlayer); IList <Coordinates> fishThreePointsList = new List <Coordinates>(); // Set cell origin with three points Cell cellThreePoints = (Cell)customGame.Board.Board[1, 1]; cellThreePoints.FishCount = 3; Coordinates coordinates = new Coordinates(1, 1); // Set others cells SetFish(customGame); // Add cell with 3 points to the list fishThreePointsList.Add(coordinates); // Launch function IList <Coordinates> list = aiHard.GetFishNear(fishThreePointsList); // Test Assert.IsTrue(list.Count == 0); }
public void Test_PlacePenguin_getFishNear() { // Init Game CustomGame customGame = InitGame(null); // Init AI Hard AIHard aiHard = new AIHard(customGame.Board, new AppRandom(), customGame.CurrentPlayer); IList <Coordinates> fishThreePointsList = new List <Coordinates>(); // Set origin cell with 3 points Cell cellThreePoints = (Cell)customGame.Board.Board[1, 1]; cellThreePoints.FishCount = 3; Coordinates coordinates = new Coordinates(1, 1); // Set up right cell of the origin cell Cell cellUpRight = (Cell)customGame.Board.Board[2, 0]; cellUpRight.FishCount = 1; // Set right cell of the origin cell Cell cellRight = (Cell)customGame.Board.Board[2, 1]; cellRight.FishCount = 1; // Set down right cell of the origin cell Cell cellDownRight = (Cell)customGame.Board.Board[2, 2]; cellDownRight.FishCount = 1; // Set down left cell of the origin cell Cell cellDownLeft = (Cell)customGame.Board.Board[1, 2]; cellDownLeft.FishCount = 1; // Set left cell of the origin cell Cell cellLeft = (Cell)customGame.Board.Board[0, 1]; cellLeft.FishCount = 1; //Set up left cell of the origin cell Cell cellUpLeft = (Cell)customGame.Board.Board[1, 0]; cellUpLeft.FishCount = 1; // Add cell with 3 points to the list fishThreePointsList.Add(coordinates); // Launch function IList <Coordinates> list = aiHard.GetFishNear(fishThreePointsList); // Test Assert.IsTrue(list[0].X == 0 && list[0].Y == 1); Assert.IsTrue(list[1].X == 2 && list[1].Y == 1); Assert.IsTrue(list[2].X == 1 && list[2].Y == 0); Assert.IsTrue(list[3].X == 2 && list[3].Y == 0); Assert.IsTrue(list[4].X == 1 && list[4].Y == 2); Assert.IsTrue(list[5].X == 2 && list[5].Y == 2); }
public void Test_PlacePenguin_getThreePoints() { // Init game CustomGame customGame = InitGame(null); // Init AI Hard AIHard aiHard = new AIHard(customGame.Board, new AppRandom(), customGame.CurrentPlayer); // Test Assert.IsTrue(aiHard.GetThreePoints().Count == 10); }
/// <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_FindOrigin_ApplyChange() { //Init Game CustomGame customGame = InitGame(null); // Penguin in 0;0 int x = 0; int y = 0; // Set cell with penguin Cell cell = (Cell)customGame.Board.Board[x, y]; cell.FishCount = 1; cell.CellType = CellType.FishWithPenguin; cell.CurrentPenguin = new Penguin(customGame.CurrentPlayer); // Cell water in 1;0 x = 1; y = 0; // Set cell water cell = (Cell)customGame.Board.Board[x, y]; cell.CellType = CellType.Water; // Cell water in 0;1 x = 0; y = 1; // Set cell water cell = (Cell)customGame.Board.Board[x, y]; cell.CellType = CellType.Water; // Launch function AIHard aiHard = new AIHard(customGame.Board, new AppRandom(), customGame.CurrentPlayer); Dictionary <string, Coordinates> coordinates = aiHard.FindOriginDestination(); // Tests Assert.IsTrue(coordinates.Count == 1); }
/// <summary> /// Move penguin for AI /// </summary> public void Move() { // If AI is easy if (CurrentPlayer.PlayerType == PlayerType.AIEasy) { // Call an AIEasy AIEasy aiEasy = new AIEasy(Board, random, CurrentPlayer); // Get positions of penguins of the current player PossibilitiesOfOrigin(); // Get the penguin to move Coordinates origin = aiEasy.FindOrigin(PossibilitiesOrigin); // Get the destination of the penguin Coordinates test = new Coordinates(-1, -1); if (origin.X != test.X) { Coordinates destination = aiEasy.FindDestination(origin); // Log penguin movement ILog log = LogManager.GetLogger(GetType().ToString()); log.Info($"{CurrentPlayer.Name} moved a penguin to cell ({destination.X}, {destination.Y}) and gained {Board.Board[origin.X, origin.Y].FishCount}."); // Apply changes ChangeStateMove(Board.Board[origin.X, origin.Y], Board.Board[destination.X, destination.Y]); // Remove Penguins if they can't move RemovePenguin(); // Close the game if the board contain 0 penguin EndGame(); AffectedCurrentPlayer(ChangeType.Move); } else { RemovePenguin(); EndGame(); AffectedCurrentPlayer(ChangeType.Move); } } // If AI is medium else if (CurrentPlayer.PlayerType == PlayerType.AIMedium) { // Call an AIMedium AIMedium aiMedium = new AIMedium(Board, random, CurrentPlayer); // Get positions of penguins of the current player PossibilitiesOfOrigin(); var coordinates = aiMedium.FindOriginDestination(); // Get the penguin to move Coordinates origin = coordinates["origin"]; try { Coordinates destination = coordinates["destination"]; // Log penguin movement ILog log = LogManager.GetLogger(GetType().ToString()); log.Info($"{CurrentPlayer.Name} moved a penguin to cell ({destination.X}, {destination.Y}) and gained {Board.Board[origin.X, origin.Y].FishCount}."); // Apply changes ChangeStateMove(Board.Board[origin.X, origin.Y], Board.Board[destination.X, destination.Y]); RemovePenguin(); EndGame(); AffectedCurrentPlayer(ChangeType.Move); } catch (Exception e) { // Log penguin movement ILog log = LogManager.GetLogger(GetType().ToString()); log.Warn($"Your penguins can't move : '{e}'"); RemovePenguin(); EndGame(); AffectedCurrentPlayer(ChangeType.Move); } } // If AI is hard else if (CurrentPlayer.PlayerType == PlayerType.AIHard) { // Call an AIHard AIHard aiHard = new AIHard(Board, random, CurrentPlayer); // Get positions of penguins of the current player PossibilitiesOfOrigin(); var coordinates = aiHard.FindOriginDestination(); // Get the penguin to move Coordinates origin = coordinates["origin"]; try { Coordinates destination = coordinates["destination"]; // Log penguin movement ILog log = LogManager.GetLogger(GetType().ToString()); log.Info($"{CurrentPlayer.Name} moved a penguin to cell ({destination.X}, {destination.Y}) and gained {Board.Board[origin.X, origin.Y].FishCount}."); // Apply changes ChangeStateMove(Board.Board[origin.X, origin.Y], Board.Board[destination.X, destination.Y]); RemovePenguin(); EndGame(); AffectedCurrentPlayer(ChangeType.Move); } catch (Exception e) { // Log penguin movement ILog log = LogManager.GetLogger(GetType().ToString()); log.Warn($"Your penguins can't move : '{e}'"); RemovePenguin(); EndGame(); AffectedCurrentPlayer(ChangeType.Move); } } }
public void Test_FindOriginDestination_CanMove() { //Init Game CustomGame customGame = InitGame(null); // Penguin in 0;0 int x = 0; int y = 0; // Set cell with penguin Cell cell = (Cell)customGame.Board.Board[x, y]; cell.FishCount = 1; cell.CellType = CellType.FishWithPenguin; cell.CurrentPenguin = new Penguin(customGame.CurrentPlayer); // Cell 1 fish in 1;0 x = 1; y = 0; // Set cell with 1 fish cell = (Cell)customGame.Board.Board[x, y]; cell.FishCount = 1; // Cell 3 fish in 2;0 x = 2; y = 0; // Set cell with 3 fish cell = (Cell)customGame.Board.Board[x, y]; cell.FishCount = 3; // Cell water in 3;0 x = 3; y = 0; // Set cell water cell = (Cell)customGame.Board.Board[x, y]; cell.CellType = CellType.Water; // Cell 1 fish in 0;1 x = 0; y = 1; // Set cell with 1 fish cell = (Cell)customGame.Board.Board[x, y]; cell.FishCount = 1; // Cell 2 fish in 1;2 x = 1; y = 2; // Set cell with 2 fish cell = (Cell)customGame.Board.Board[x, y]; cell.FishCount = 2; // Cell water in 1;3 x = 1; y = 3; // Set cell water cell = (Cell)customGame.Board.Board[x, y]; cell.CellType = CellType.Water; // Launch function AIHard aiHard = new AIHard(customGame.Board, new AppRandom(), customGame.CurrentPlayer); Dictionary <string, Coordinates> coordinates = aiHard.FindOriginDestination(); // Test Assert.IsTrue(coordinates["destination"].X == 2 && coordinates["destination"].Y == 0); }