Ejemplo n.º 1
0
        /// <summary>
        /// Returns the best possible move, given a ScrabbleBoard and a list of strings representing the player's hand.
        /// </summary>
        /// <param name="board">ScrabbleBoard that the move will be played on</param>
        /// <param name="hand">List of length 1 strings that the player has in his/her hand</param>
        /// <returns></returns>
        public Move GetBestPlay(ScrabbleBoard board, List <string> hand)
        {
            List <Move> allMoves = new List <Move>();

            for (int c = 0; c < this.board.GetRow(0).Length; c++)
            {
                foreach (Move move in GetMovesInArray(board, hand, board.GetCol(c), true, c))
                {
                    allMoves.Add(move);
                }
            }
            for (int c = 0; c < this.board.GetCol(0).Length; c++)
            {
                foreach (Move move in GetMovesInArray(board, hand, board.GetRow(c), false, c))
                {
                    allMoves.Add(move);
                }
            }
            Move bestMove = new Move(null, null, true);;
            int  topScore = 0;
            int  currentScore;

            foreach (Move move in allMoves)
            {
                currentScore = board.GetPredictedScore(move.GetWord(), move.GetPosition()[0], move.GetPosition()[1], move.GetIfNorthSouth());
                if (currentScore > topScore && !board.CheckIfRetread(move))
                {
                    System.Diagnostics.Debug.WriteLine(move.ToString());
                    topScore = currentScore;
                    bestMove = move;
                }
            }
            return(bestMove);
        }