/// <summary> /// Score function. Return a score for a given board. /// </summary> /// <returns>Returns a score for a given board</returns> public int Score() { int score = 0; int[,] theBoard = board.GetBoard(); int playerVal = isWhitePlayer ? 1 : 0; // Get the player value in the board array for (int i = 0; i < theBoard.GetLength(1); i++) { for (int j = 0; j < theBoard.GetLength(0); j++) { int boardValue = theBoard[j, i]; if (boardValue != -1) { if (boardValue == playerVal) { score += OthelloBoard.SCORE_MATRIX[j, i]; // Add the matrix score if is the correct player } else { score -= OthelloBoard.SCORE_MATRIX[j, i]; // Substract the matrix score if is the other player } } } } Tuple <int, int> nbPawns = OthelloBoard.CountPawn(theBoard, playerVal); score += 25 * ((nbPawns.Item1 + nbPawns.Item2 + 1) % 2); //Add a weight if the current user play the last move score += 25 * ((nbPawns.Item1 - nbPawns.Item2) / (nbPawns.Item1 + nbPawns.Item2)); //Add a weight from the pawn parity Tuple <int, int> nbCorners = OthelloBoard.CountCorner(theBoard, playerVal); if (nbCorners.Item1 + nbCorners.Item2 != 0) { score += 100 * (nbCorners.Item1 - nbCorners.Item2) / (nbCorners.Item1 + nbCorners.Item2);//Add weight from the number of captured corner } // If the state is final if (IsFinal()) { // If the score is positive, the user win if (score > 0) { return(Int32.MaxValue - 1); } else // If the score is negative, the user loose { return(Int32.MinValue + 1); } } return(score); }