public void CountNumberOfBackwardDiagonalRunsTest() { IBoard board = BoardCreator.GetBoardWithBackwardDiagonalLine(NumberOfPiecesInALine); IBoardAnalytics boardAnalytics = new BoardAnalytics(); int numberOfRuns = boardAnalytics.NumberOfPiecesInARowOnBoard(NumberOfPiecesInALine, BoardCreator.PlayerOneGamePiece, board); Assert.AreEqual(numberOfRuns, 1); }
/// <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); }