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 AIMedium aiMedium = new AIMedium(customGame.Board, new AppRandom(), customGame.CurrentPlayer); Dictionary <string, Coordinates> coordinates = aiMedium.FindOriginDestination(); // Tests Assert.IsTrue(coordinates.Count == 1); }
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 AIMedium aiMedium = new AIMedium(customGame.Board, new AppRandom(), customGame.CurrentPlayer); Dictionary <string, Coordinates> coordinates = aiMedium.FindOriginDestination(); // Tests Assert.IsTrue(coordinates["destination"].X == 2 && coordinates["destination"].Y == 0); }
/// <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); } } }