예제 #1
0
        /// <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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        /// <summary>
        /// Function for remove a penguin alone
        /// </summary>
        public void RemovePenguin()
        {
            Movements move = new Movements(null, null, Board);

            PossibilitiesOfOrigin();
            foreach (var possibility in PossibilitiesOrigin)
            {
                var list = move.CheckMove(possibility);
                if (list.Count == 0)
                {
                    Player playerCurrent = (Player)CurrentPlayer;

                    // Get cell
                    Cell cell = (Cell)Board.Board[possibility.X, possibility.Y];

                    // Add to the player number of point of the cell
                    playerCurrent.Points += cell.FishCount;

                    // Cell become water
                    cell.CellType = CellType.Water;

                    // Register points for log
                    var cellPoints = cell.FishCount;

                    // Cell have no fish
                    cell.FishCount = 0;

                    // Cell have no penguin
                    cell.CurrentPenguin = null;

                    // Apply change
                    cell.ChangeState();

                    // Apply change
                    playerCurrent.ChangeState();

                    ILog log = LogManager.GetLogger(GetType().ToString());
                    log.Info($"{playerCurrent.Name} moved to cell ({possibility.X}, {possibility.Y}) and gained {cellPoints}.");
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Get randomly the destination of the penguin
        /// </summary>
        /// <param name="origin">coordinates of the origin</param>
        /// <returns>coordinates of the destination</returns>
        public Coordinates FindDestination(Coordinates origin)
        {
            Movements move = new Movements(null, null, Board);

            IList <Coordinates> result = move.CheckMove(origin);

            // Shuffle
            result = result.OrderBy(a => Guid.NewGuid()).ToList();

            try
            {
                return(result[0]);
            }
            catch (Exception e)
            {
                // Log penguin movement
                ILog log = LogManager.GetLogger(GetType().ToString());
                log.Info("Your penguins can't move : " + e);
                return(new Coordinates(-1, -1));
            }
        }
예제 #5
0
        /// <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();
                    }
                }
            }
        }