public void Test_GetCoordinates_GetOriginDestination() { // Init Game CustomGame customGame = InitGame(); // Position of cell int xOrigin = 0; int yOrigin = 0; // Set Cell cellOrigin = (Cell)customGame.Board.Board[xOrigin, yOrigin]; cellOrigin.FishCount = 1; // Position of cell int xDestination = 1; int yDestination = 1; // Set Destination Cell cellDestination = (Cell)customGame.Board.Board[xDestination, yDestination]; cellDestination.FishCount = 3; // Launch function Movements move = new Movements(cellOrigin, cellDestination, customGame.Board); var result = move.GetCoordinates(); // Tests Assert.IsTrue(result["origin"].X == xOrigin); Assert.IsTrue(result["origin"].Y == yOrigin); Assert.IsTrue(result["destination"].X == xDestination); Assert.IsTrue(result["destination"].Y == yDestination); }
public void Test_CheckMove_ResultDownRight_AllRow() { CustomGame customGame = InitGame(); // Position of cell int xOrigin = 0; int yOrigin = 0; Cell cellOrigin = (Cell)customGame.Board.Board[xOrigin, yOrigin]; cellOrigin.CellType = CellType.FishWithPenguin; cellOrigin.CurrentPenguin = new Penguin(new Player("Player1", PlayerType.Human)); // Position of cell int xDestination = 3; int yDestination = 7; Cell cellDestination = (Cell)customGame.Board.Board[xDestination, yDestination]; cellDestination.CellType = CellType.Fish; Movements move = new Movements(cellOrigin, cellDestination, customGame.Board); var result = move.GetCoordinates(); move.GetCoordinatesDownRight(result["origin"]); Assert.IsTrue(move.Possibilities[0].X == 0 && move.Possibilities[0].Y == 1); Assert.IsTrue(move.Possibilities[1].X == 1 && move.Possibilities[1].Y == 2); Assert.IsTrue(move.Possibilities[2].X == 1 && move.Possibilities[2].Y == 3); Assert.IsTrue(move.Possibilities[3].X == 2 && move.Possibilities[3].Y == 4); Assert.IsTrue(move.Possibilities[4].X == 2 && move.Possibilities[4].Y == 5); Assert.IsTrue(move.Possibilities[5].X == 3 && move.Possibilities[5].Y == 6); Assert.IsTrue(move.Possibilities[6].X == 3 && move.Possibilities[6].Y == 7); }
/// <summary> /// Get the destination of the penguin /// </summary> /// <returns>coordinates of the destination</returns> public Dictionary <string, Coordinates> FindOriginDestination() { Movements move = new Movements(null, null, Board); PossibilitiesOfOrigin(); Dictionary <Coordinates, ICell> bestCells = new Dictionary <Coordinates, ICell>(); foreach (var possibility in PossibilitiesOrigin) { var list = move.CheckMove(possibility); IList <ICell> resultCells = new List <ICell>(); foreach (var element in list) { resultCells.Add(Board.Board[element.X, element.Y]); } if (resultCells.Count != 0) { var resultOrderBy = resultCells.Where(cell => cell.FishCount == 3).ToList(); if (resultOrderBy.Count == 0) { bestCells.Add(possibility, resultCells[random.Next(0, resultCells.Count)]); } else { bestCells.Add(possibility, resultOrderBy[0]); } } } Coordinates greatOrigin = new Coordinates(0, 0); ICell greatDestination = new Cell(0); foreach (var couple in bestCells) { if (couple.Value.FishCount > greatDestination.FishCount) { greatDestination = couple.Value; greatOrigin = couple.Key; } } Movements getCells = new Movements(Board.Board[greatOrigin.X, greatOrigin.Y], greatDestination, Board); var coordinates = getCells.GetCoordinates(); return(coordinates); }
public void Test_CheckMove_ResultUpRight() { // Init Game CustomGame customGame = InitGame(); // Position of cell origin int xOrigin = 0; int yOrigin = 7; // Set Origin Cell cellOrigin = (Cell)customGame.Board.Board[xOrigin, yOrigin]; cellOrigin.CellType = CellType.FishWithPenguin; cellOrigin.CurrentPenguin = new Penguin(new Player("Player1", PlayerType.Human)); // Position of cell destination int xDestination = 1; int yDestination = 5; // Set Destination Cell cellDestination = (Cell)customGame.Board.Board[xDestination, yDestination]; cellDestination.CellType = CellType.Fish; // Position of cell after int xAfter = 2; int yAfter = 4; // Set After Cell cellAfter = (Cell)customGame.Board.Board[xAfter, yAfter]; cellAfter.CellType = CellType.Water; // Launch function Movements move = new Movements(cellOrigin, cellDestination, customGame.Board); var result = move.GetCoordinates(); // Tests move.CheckMove(result["origin"]); Assert.IsTrue(move.Possibilities[7].X == 1 && move.Possibilities[7].Y == 6); Assert.IsTrue(move.Possibilities[8].X == 1 && move.Possibilities[8].Y == 5); }
public void Test_CheckMove_ResultDownLeft_BlockBy() { CustomGame customGame = InitGame(); // Position of cell origin int xOrigin = 7; int yOrigin = 0; // Set origin Cell cellOrigin = (Cell)customGame.Board.Board[xOrigin, yOrigin]; cellOrigin.CellType = CellType.FishWithPenguin; cellOrigin.CurrentPenguin = new Penguin(new Player("Player1", PlayerType.Human)); // Position of cell destination int xDestination = 5; int yDestination = 3; // Set Destination Cell cellDestination = (Cell)customGame.Board.Board[xDestination, yDestination]; cellDestination.CellType = CellType.Fish; // Position of cell after int xAfter = 5; int yAfter = 4; // Set After Cell cellAfter = (Cell)customGame.Board.Board[xAfter, yAfter]; cellAfter.CellType = CellType.Water; //Launch move Movements move = new Movements(cellOrigin, cellDestination, customGame.Board); var result = move.GetCoordinates(); // Tests move.GetCoordinatesDownLeft(result["origin"]); Assert.IsTrue(move.Possibilities[0].X == 6 && move.Possibilities[0].Y == 1); Assert.IsTrue(move.Possibilities[1].X == 6 && move.Possibilities[1].Y == 2); Assert.IsTrue(move.Possibilities[2].X == 5 && move.Possibilities[2].Y == 3); }
/// <summary> /// Move penguin for human /// </summary> /// <param name="origin">Origin Cell</param> /// <param name="destination">Destination Cell</param> public void MoveManual(ICell origin, ICell destination) { // If the selected origin cell has a penguin // AND If the selected destination cell has fish if (origin.CellType == CellType.FishWithPenguin && destination.CellType == CellType.Fish) { // If the selected origin cell has a penguin which belongs to current player if (origin.CurrentPenguin.Player == CurrentPlayer) { Movements move = new Movements(origin, destination, Board); // Get coordinates of origin and destination cells Dictionary <string, Coordinates> result = move.GetCoordinates(); // Get if the destination cell belongs to the list of possibilities int numberOfResults = move.CheckMove(result["origin"]) .Count(element => element.X == result["destination"].X && element.Y == result["destination"].Y); // If the destination cell belongs to the list if (numberOfResults > 0) { // Apply changes ChangeStateMove(origin, destination); // Remove penguin if he can't move RemovePenguin(); // Check if all penguin has removed, if is true, stop the game EndGame(); // Change current player AffectedCurrentPlayer(ChangeType.Move); // Check if the player can move his penguins //RemovePenguin(); } } } }
public void Test_CheckMove_ResultUpLeft_AllRow() { CustomGame customGame = InitGame(); // Position of cell origin int xOrigin = 7; int yOrigin = 7; // Set Origin Cell cellOrigin = (Cell)customGame.Board.Board[xOrigin, yOrigin]; cellOrigin.CellType = CellType.FishWithPenguin; cellOrigin.CurrentPenguin = new Penguin(new Player("Player1", PlayerType.Human)); // Position of cell destination int xDestination = 4; int yDestination = 0; // Set Destination Cell cellDestination = (Cell)customGame.Board.Board[xDestination, yDestination]; cellDestination.CellType = CellType.Fish; // Launch move Movements move = new Movements(cellOrigin, cellDestination, customGame.Board); var result = move.GetCoordinates(); // Tests move.GetCoordinatesUpLeft(result["origin"]); Assert.IsTrue(move.Possibilities[0].X == 7 && move.Possibilities[0].Y == 6); Assert.IsTrue(move.Possibilities[1].X == 6 && move.Possibilities[1].Y == 5); Assert.IsTrue(move.Possibilities[2].X == 6 && move.Possibilities[2].Y == 4); Assert.IsTrue(move.Possibilities[3].X == 5 && move.Possibilities[3].Y == 3); Assert.IsTrue(move.Possibilities[4].X == 5 && move.Possibilities[4].Y == 2); Assert.IsTrue(move.Possibilities[5].X == 4 && move.Possibilities[5].Y == 1); Assert.IsTrue(move.Possibilities[6].X == 4 && move.Possibilities[6].Y == 0); }
public void Test_CheckMove_ResultRight_BlockBy() { CustomGame customGame = InitGame(); // Position of cell origin int xOrigin = 0; int yOrigin = 0; Cell cellOrigin = (Cell)customGame.Board.Board[xOrigin, yOrigin]; cellOrigin.CellType = CellType.FishWithPenguin; cellOrigin.CurrentPenguin = new Penguin(new Player("Player1", PlayerType.Human)); // Position of cell destination int xDestination = 2; int yDestination = 0; Cell cellDestination = (Cell)customGame.Board.Board[xDestination, yDestination]; cellDestination.CellType = CellType.Fish; // Position of cell after int xAfter = 3; int yAfter = 0; Cell cellAfter = (Cell)customGame.Board.Board[xAfter, yAfter]; cellAfter.CellType = CellType.Water; Movements move = new Movements(cellOrigin, cellDestination, customGame.Board); var result = move.GetCoordinates(); move.GetCoordinatesRight(result["origin"]); Assert.IsTrue(move.Possibilities[0].X == 1 && move.Possibilities[0].Y == 0); Assert.IsTrue(move.Possibilities[1].X == 2 && move.Possibilities[1].Y == 0); }