Exemple #1
0
        public IMoveResult Put(IPlayer player, int column)
        {
            for (int i = Rows - 1; i >= 0; --i)
            {
                if (GameMoves[i, column] == null)
                {
                    ConnectMove move = new ConnectMove(player, sequenceID++, i, column);
                    GameMoves[i, column] = move;
                    IMoveResult result = new MoveResult(move);

                    return(result);
                }
            }

            // Failed result;
            return(new MoveResult());
        }
Exemple #2
0
        protected bool IsOpponentNextMoveWinningMove(IGameEngine gameEngine, ICalculationResult current, char[,] boardData, char otherPlayer)
        {
            char[,] cloneData = CloneData(boardData, current);
            for (int i = 0; i < boardData.GetLength(1); ++i)
            {
                int rowIndex = GetRow(i, cloneData);
                if (rowIndex >= 0)
                {
                    IMove move = new ConnectMove(new WebPlayer("Player 1", otherPlayer), 0, rowIndex, i);
                    if (ConnectFourGameEngine.IsWinningMove(move, cloneData))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        protected override ICalculationResult CalculateResult(IGameEngine gameEngine, char otherPlayerID)
        {
            ICalculationResult max = null;

            char[,] boardData = gameEngine.BoardData;
            for (int i = 0; i < boardData.GetLength(1); ++i)
            {
                int rowIndex = GetRow(i, boardData);
                if (rowIndex >= 0)
                {
                    IMove move = new ConnectMove(this, 0, rowIndex, i);

                    if (gameEngine.IsWinningMove(move))
                    {
                        CalculationResult result = new CalculationResult(rowIndex, i, boardData.GetLength(1));
                        result.IsWinningMove = true;

                        return(result);
                    }
                }
            }
            return(base.CalculateResult(gameEngine, otherPlayerID));
        }