Exemple #1
0
        /// <summary>
        /// Returns a deep copy of this ScrabbleBoard
        /// </summary>
        /// <returns>Clone of ScrabbleBoard</returns>
        public ScrabbleBoard Clone()
        {
            string[,] newBaseBoard = (string[, ]) this.baseBoard.Clone();

            ScrabbleBoard newBoard = new ScrabbleBoard(newBaseBoard, this.dictionary, letterValues);

            newBoard.SetBoard((string[, ]) this.lettersOnBoard.Clone());
            return(newBoard);
        }
Exemple #2
0
        //generate solution
        private void button1_Click(object sender, EventArgs e)
        {
            foreach (TextBox letterBox in board)
            {
                letterBox.ForeColor = Color.Black;
            }
            int[] pos = new int[2];
            pos[0] = 5;
            pos[1] = 6;
            Move          move = new Move("hi", pos, true);
            List <string> hand = new List <string>();

            hand.Add(handLetter0.Text);
            hand.Add(handLetter1.Text);
            hand.Add(handLetter2.Text);
            hand.Add(handLetter3.Text);
            hand.Add(handLetter4.Text);
            hand.Add(handLetter5.Text);
            hand.Add(handLetter6.Text);
            while (hand.Contains(""))
            {
                hand.Remove("");
            }
            string[,] baseBoard = new string[15, 15];

            Dictionary <string, int> letters;

            if (WWFRadio.Checked)
            {
                letters = new Dictionary <string, int>()
                {
                    { "a", 1 }, { "b", 4 }, { "c", 4 }, { "d", 2 }, { "e", 1 }, { "f", 4 }, { "g", 3 }, { "h", 3 }, { "i", 1 }, { "j", 10 }, { "k", 5 }, { "l", 2 }, { "m", 4 },
                    { "n", 2 }, { "o", 1 }, { "p", 4 }, { "q", 10 }, { "r", 1 }, { "s", 1 }, { "t", 1 }, { "u", 2 }, { "v", 5 }, { "w", 4 }, { "x", 8 }, { "y", 3 }, { "z", 10 },
                };
            }
            else
            {
                letters = new Dictionary <string, int>()
                {
                    { "a", 1 }, { "b", 3 }, { "c", 3 }, { "d", 2 }, { "e", 1 }, { "f", 4 }, { "g", 2 }, { "h", 4 }, { "i", 1 }, { "j", 8 }, { "k", 5 }, { "l", 1 }, { "m", 3 },
                    { "n", 1 }, { "o", 1 }, { "p", 3 }, { "q", 10 }, { "r", 1 }, { "s", 1 }, { "t", 1 }, { "u", 1 }, { "v", 4 }, { "w", 4 }, { "x", 8 }, { "y", 4 }, { "z", 10 },
                };
            }


            string[]      lines      = System.IO.File.ReadAllLines("WWFDictionary.txt");
            List <string> dictionary = new List <string>();

            foreach (string s in lines)
            {
                dictionary.Add(s);
            }

            ScrabbleBoard scrabBoard = new ScrabbleBoard(baseBoard, dictionary, letters);

            int x = 0;
            int y = 0;

            string[,] boardl = new string[15, 15];
            while (x < 15)
            {
                y = 0;
                while (y < 15)
                {
                    boardl[x, y] = (board[x, y].Text.Equals("") ? null : board[x, y].Text);
                    y++;
                }
                x++;
            }
            scrabBoard.SetBoard(boardl);
            Solver solv = new Solver(scrabBoard);

            PlaceWord(solv.GetBestPlay(scrabBoard, hand), true);
        }