Esempio n. 1
0
        /// <summary>
        /// Get the players self defined score of a column index as its next move.
        /// </summary>
        /// <param name="board">Game board.</param>
        /// <param name="columnIndexForPotentialMove">Column index for next potential move.</param>
        /// <returns>Score of the column choice as players next move.</returns>
        public long GetColumnScoreAfterPotentialMove(IBoard board, int columnIndexForPotentialMove)
        {
            IBoardAnalytics boardAnalytics = new BoardAnalytics();
            long            finalScore     = 0;

            // Get score for making the move
            finalScore += boardAnalytics.NumberOfPiecesInARowOnBoardFromPotentialMove(Board.Board.TwoInARow, new GameMove(GamePiece, columnIndexForPotentialMove), board)
                          * Characteristics.ScoreConnectTwo;
            finalScore += boardAnalytics.NumberOfPiecesInARowOnBoardFromPotentialMove(Board.Board.ThreeInARow, new GameMove(GamePiece, columnIndexForPotentialMove), board)
                          * Characteristics.ScoreConnectThree;
            finalScore += boardAnalytics.NumberOfPiecesInARowOnBoardFromPotentialMove(Board.Board.FourInARow, new GameMove(GamePiece, columnIndexForPotentialMove), board)
                          * Characteristics.ScoreConnectFour;

            // Setup for checking opponents potential move
            IBoard boardAfterPotentialMove = board.Clone();

            boardAfterPotentialMove.AddPiece(new GameMove(GamePiece, columnIndexForPotentialMove));
            var opponentsGamePiece = GamePiece == ConnectFourGame.PlayerOneGamePiece
                ? ConnectFourGame.PlayerTwoGamePiece
                : ConnectFourGame.PlayerOneGamePiece;

            // Subtract points for the potential move the opponent gets
            if (!boardAfterPotentialMove.IsColumnFull(columnIndexForPotentialMove))
            {
                finalScore += boardAnalytics.NumberOfPiecesInARowOnBoardFromPotentialMove(Board.Board.TwoInARow, new GameMove(opponentsGamePiece, columnIndexForPotentialMove), boardAfterPotentialMove)
                              * Characteristics.ScoreGivingConnectTwo;
                finalScore += boardAnalytics.NumberOfPiecesInARowOnBoardFromPotentialMove(Board.Board.ThreeInARow, new GameMove(opponentsGamePiece, columnIndexForPotentialMove), boardAfterPotentialMove)
                              * Characteristics.ScoreGivingConnectThree;
                finalScore += boardAnalytics.NumberOfPiecesInARowOnBoardFromPotentialMove(Board.Board.FourInARow, new GameMove(opponentsGamePiece, columnIndexForPotentialMove), boardAfterPotentialMove)
                              * Characteristics.ScoreGivingConnectFour;
            }

            return(finalScore);
        }
        public void CountNumberOfBackwardDiagonalRunsTest()
        {
            IBoard board = BoardCreator.GetBoardWithBackwardDiagonalLine(NumberOfPiecesInALine);

            IBoardAnalytics boardAnalytics = new BoardAnalytics();
            int             numberOfRuns   = boardAnalytics.NumberOfPiecesInARowOnBoard(NumberOfPiecesInALine, BoardCreator.PlayerOneGamePiece, board);

            Assert.AreEqual(numberOfRuns, 1);
        }
Esempio n. 3
0
        /// <summary>
        /// Get the players self defined score of the current state of the board.
        /// </summary>
        /// <param name="board">Game board.</param>
        /// <returns>Score of the board.</returns>
        public long GetBoardScore(IBoard board)
        {
            long            boardScore     = 0;
            IBoardAnalytics boardAnalytics = new BoardAnalytics();

            var opponentsGamePiece = GamePiece == ConnectFourGame.PlayerOneGamePiece
                ? ConnectFourGame.PlayerTwoGamePiece
                : ConnectFourGame.PlayerOneGamePiece;

            // Get score for making the move
            boardScore += boardAnalytics.NumberOfPiecesInARowOnBoard(Board.Board.TwoInARow, GamePiece, board) * Characteristics.ScoreConnectTwo;
            boardScore += boardAnalytics.NumberOfPiecesInARowOnBoard(Board.Board.ThreeInARow, GamePiece, board) * Characteristics.ScoreConnectThree;
            boardScore += boardAnalytics.NumberOfPiecesInARowOnBoard(Board.Board.FourInARow, GamePiece, board) * Characteristics.ScoreConnectFour;

            // Subtract points for the potential move the opponent gets
            boardScore += boardAnalytics.NumberOfPiecesInARowOnBoard(Board.Board.TwoInARow, opponentsGamePiece, board) * Characteristics.ScoreGivingConnectTwo;
            boardScore += boardAnalytics.NumberOfPiecesInARowOnBoard(Board.Board.ThreeInARow, opponentsGamePiece, board) * Characteristics.ScoreGivingConnectThree;
            boardScore += boardAnalytics.NumberOfPiecesInARowOnBoard(Board.Board.FourInARow, opponentsGamePiece, board) * Characteristics.ScoreGivingConnectFour;

            return(boardScore);
        }