コード例 #1
0
        /// <summary>
        /// Determines where a penguin can move
        /// </summary>
        /// <param name="posX"></param>
        /// <param name="posY"></param>
        public Coordinates ChoseFinalDestinationCell(int posX, int posY)
        {
            var possibleCells = _movementManager.WhereCanIMove((Cell)MainBoard.Board[posX, posY]);

            if (possibleCells.Any())
            {
                var chosenCell = (Cell)possibleCells[new Random().Next(possibleCells.Count)];
                return(new Coordinates()
                {
                    X = chosenCell.XPos,
                    Y = chosenCell.YPos
                });
            }
            else
            {
                return(null);
            }
        }
コード例 #2
0
ファイル: AIEasy.cs プロジェクト: Mrgove10/Game.Penguins
        /// <summary>
        /// Determines where a penguin can move
        /// </summary>
        /// <param name="posX"></param>
        /// <param name="posY"></param>
        public Coordinates ChoseFinalDestinationCell(int posX, int posY)
        {
            var possibleCells = _movementManager.WhereCanIMove((Cell)MainBoard.Board[posX, posY]); //searches for an eligible cell to move to

            if (possibleCells.Any())                                                               //...if there's any, it is immediately choosen...
            {
                while (true)
                {
                    Cell chosenCell = (Cell)possibleCells[new Random().Next(possibleCells.Count)];
                    if (chosenCell.CellType == CellType.Fish)
                    {
                        return(new Coordinates() //...and its coordinates replace the origin cell's coordinates.
                        {
                            X = chosenCell.XPos,
                            Y = chosenCell.YPos
                        });
                    }
                }
            }
            else
            {
                return(null);
            }
        }