示例#1
0
        public void FindMovesMultipleMovesSameWordTest()
        {
            var words = WordList.Load(new string[] { "cat" });

            board = Board.InitiliseBoard(words);
            // Existing word (zap) not present in word list, should still form cat
            board.GetCell(7, 4).Letter = 'a';
            board.GetCell(7, 5).Letter = 'a';
            board.GetCell(7, 6).Letter = 'a';
            Hand       hand   = new Hand("ct");
            MoveFinder finder = new MoveFinder(board, hand, words);
            var        moves  = finder.FindMoves().ToList();

            Assert.AreEqual(3, moves.Count);
            var catMove = moves[0];

            Assert.AreEqual("cat", catMove.Word);
            Assert.AreEqual(MoveOrientation.HORIZONTAL, catMove.Orientation);
            Assert.AreEqual(6, catMove.Row);
            Assert.AreEqual(6, catMove.Column);
            Assert.AreEqual(11, catMove.Score);

            Assert.AreEqual(6, moves[1].Score);
            Assert.AreEqual(5, moves[2].Score);
        }
示例#2
0
        private void PlayAGame(WordList list)
        {
            Board board = CreateBoard(list);

            while (true)
            {
                Console.WriteLine(board.ToString(true));
                Console.WriteLine(board.ToString(false));

                //Hand hand = CreateRandomHand();
                Hand hand = AskForHand();
                Console.WriteLine(hand);

                Console.Write("Enter for next move");
                Console.ReadLine();

                MoveFinder finder = new MoveFinder(board, hand, list);
                var        moves  = finder.FindMoves();
                if (!moves.Any())
                {
                    Console.WriteLine("No Moves Found");
                    continue;
                }
                var movesList = moves.Take(10).ToList();
                Console.WriteLine(movesList.ToExpandedString());
                board.Apply(movesList.First());
            }
        }
示例#3
0
        public void FindMovesBothDirectionsTest()
        {
            var words = WordList.Load(new string[] { "cat" });

            board = Board.InitiliseBoard(words);
            // Existing word (zap) not present in word list, should still form cat
            board.GetCell(7, 4).Letter = 'c';
            board.GetCell(8, 4).Letter = 'c';
            board.GetCell(9, 4).Letter = 'c';

            board.GetCell(7, 5).Letter = 'c';
            board.GetCell(8, 5).Letter = null;
            board.GetCell(9, 5).Letter = 't';

            board.GetCell(7, 6).Letter = 't';
            board.GetCell(8, 6).Letter = 't';
            board.GetCell(9, 6).Letter = 't';

            Hand       hand   = new Hand("a");
            MoveFinder finder = new MoveFinder(board, hand, words);
            var        moves  = finder.FindMoves().ToList();

            Assert.AreEqual(2, moves.Count);
            Assert.AreEqual("cat", moves[0].Word);
            Assert.AreEqual("cat", moves[1].Word);
            Assert.AreNotEqual(moves[0].Orientation, moves[1].Orientation);
            var horizontalMove = moves[0].Orientation == MoveOrientation.HORIZONTAL ? moves[0] : moves[1];
            var verticalMove   = moves[0].Orientation == MoveOrientation.VERTICAL ? moves[0] : moves[1];

            Assert.AreEqual(verticalMove.Row, 4);
            Assert.AreEqual(verticalMove.Column, 8);

            Assert.AreEqual(horizontalMove.Row, 5);
            Assert.AreEqual(horizontalMove.Column, 7);
        }
示例#4
0
        private IEnumerable <Move> FindMoves(IEnumerable <char> letters, WordList list)
        {
            Board board = CreateBoard(list);

            Console.WriteLine(board.ToString());
            Hand       hand   = CreateHand(letters);
            MoveFinder finder = new MoveFinder(board, hand, list);

            return(finder.FindMoves());
        }
示例#5
0
        public void FindMovesStartingMovesTest()
        {
            var words = WordList.Load(new string[] { "cat" });

            board = Board.InitiliseBoard(words);
            Hand       hand   = new Hand("cat");
            MoveFinder finder = new MoveFinder(board, hand, words);
            var        moves  = finder.FindMoves().ToList();

            Assert.AreEqual(6, moves.Count);
        }
示例#6
0
        public void FindMovesOrderTest()
        {
            var words = WordList.Load(new string[] { "cat", "fish", "catfish" });

            board = Board.InitiliseBoard(words);
            board.GetCell(7, 4).Letter = 'a';
            Hand       hand   = new Hand("ctfish");
            MoveFinder finder = new MoveFinder(board, hand, words);
            var        moves  = finder.FindMoves().ToList();

            Assert.AreEqual(4, moves.Count);
            // Catfish will get more points then cat.
            Assert.AreEqual("catfish", moves[0].Word);
            Assert.AreEqual("catfish", moves[1].Word);
            Assert.AreEqual("cat", moves[2].Word);
            Assert.AreEqual("cat", moves[3].Word);
        }
示例#7
0
        public void FindMovesFindSimpleHorozontalMoveTest()
        {
            var words = WordList.Load(new string[] { "cat", "zap" });

            board = Board.InitiliseBoard(words);
            board.GetCell(7, 4).Letter = 'z';
            board.GetCell(7, 5).Letter = 'a';
            board.GetCell(7, 6).Letter = 'p';
            Hand       hand   = new Hand("ct");
            MoveFinder finder = new MoveFinder(board, hand, words);
            var        moves  = finder.FindMoves().ToList();

            Assert.AreEqual(1, moves.Count);
            var catMove = moves[0];

            Assert.AreEqual("cat", catMove.Word);
            Assert.AreEqual(MoveOrientation.HORIZONTAL, catMove.Orientation);
            Assert.AreEqual(5, catMove.Row);
            Assert.AreEqual(6, catMove.Column);
        }
示例#8
0
        public void FindMovesVerticalDontCheckExistingWordsTest()
        {
            var words = WordList.Load(new string[] { "cat" });

            board = Board.InitiliseBoard(words);
            // Existing word (zap) not present in word list, should still form cat
            board.GetCell(6, 5).Letter = 'z';
            board.GetCell(7, 5).Letter = 'a';
            board.GetCell(8, 5).Letter = 'p';
            Hand       hand   = new Hand("ct");
            MoveFinder finder = new MoveFinder(board, hand, words);
            var        moves  = finder.FindMoves().ToList();

            Assert.AreEqual(1, moves.Count);
            var catMove = moves[0];

            Assert.AreEqual("cat", catMove.Word);
            Assert.AreEqual(MoveOrientation.VERTICAL, catMove.Orientation);
            Assert.AreEqual(4, catMove.Row);
            Assert.AreEqual(7, catMove.Column);
        }
        private IEnumerable <Move> FindMoves(Board board, Hand hand, WordList list)
        {
            MoveFinder finder = new MoveFinder(board.ThrowIfNull("board"), hand.ThrowIfNull("hand"), list.ThrowIfNull("list"));

            return(finder.FindMoves());
        }