Пример #1
0
        /// <summary>
        /// Returns list of moves that can be done with a specific hand
        /// </summary>
        /// <param name="board">string array of letters on the board for that</param>
        /// <param name="hand">List of length 1 strings in the player's hand</param>
        /// <param name="rowOrCol">Position</param>
        /// <param name="col">True if it runs up/down</param>
        /// <returns>List of moves, formed in an array [string word, int[1,1] position, bool NorthSouth]</returns>
        public List <Move> GetMovesInArray(ScrabbleBoard board, List <string> hand, string[] rowOrCol, bool col, int pos)
        {
            List <Move>   moves        = new List <Move>();
            List <string> boardLetters = new List <string>();
            Move          possibleMove;

            int[] position = new int[2];
            foreach (string letter in rowOrCol)
            {
                if (letter != null)
                {
                    boardLetters.Add(letter);
                }
            }
            foreach (string word in GetPossibleWordsForRow(hand, boardLetters))
            {
                for (int c = 0; c + word.Length < (col ? board.GetCol(pos).Length : board.GetRow(pos).Length); c++)
                {
                    position[0]  = (col ? pos : c);
                    position[1]  = (col ? board.GetRow(pos).Length - 1 - c : pos);
                    possibleMove = new Move(word, position, col);
                    if (board.CheckIfValidMove(word, position, col, hand))
                    {
                        moves.Add(possibleMove.Clone());
                    }
                }
            }
            return(moves);
        }
Пример #2
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);
        }