Exemple #1
0
        public void TwoNumbers()
        {
            Rack testrack = new Rack();

            testrack.Add(20);
            int[] result   = testrack.Add(10);
            int[] expected = { 10, 20 };

            Assert.AreEqual(expected, result);
        }
        public static void Add_BallOutOfOrder_SavesBallsInAscendingOrder()
        {
            // arrange
            var sut = new Rack();

            // act
            sut.Add(12);
            sut.Add(5);

            // assert
            CollectionAssert.AreEqual(new [] { 5, 12 }, sut.Balls);
        }
        public static void Add_TwoBalls_SavesBalls()
        {
            // arrange
            var sut = new Rack();

            // act
            sut.Add(12);
            sut.Add(22);

            // assert
            CollectionAssert.AreEqual(new [] { 12, 22 }, sut.Balls);
        }
        public static void Add_BallShouldGoInMiddle_SavesBallsInAscendingOrder()
        {
            // arrange
            var sut = new Rack();

            sut.Add(12);
            sut.Add(20);

            // act
            sut.Add(15);

            // assert
            CollectionAssert.AreEqual(new [] { 12, 15, 20 }, sut.Balls);
        }
Exemple #5
0
        public void OneNumber()
        {
            int[] result   = rack1.Add(20);
            int[] expected = { 20 };

            Assert.AreEqual(expected, result);
        }
        public static void Add_SingleBall_SavesBall()
        {
            // arrange
            var sut = new Rack();

            // act
            sut.Add(12);

            // assert
            CollectionAssert.AreEqual(new [] { 12 }, sut.Balls);
        }
Exemple #7
0
        static void Main(string[] args)
        {
            Rack rack = new Rack();

            Console.WriteLine("Insert a number: ");
            while (true)
            {
                int value = Convert.ToInt32(Console.ReadLine());
                rack.Add(value);
                Console.WriteLine("\n" + rack.ShowBalls() + "\n");
            }
        }
Exemple #8
0
 private void LeftPart(Word partialWord, Lib.Node root, int limit, Rack rack, Square[,] board, Square anchor)
 {
     ExtendRight(partialWord, root, board, anchor, rack, anchor);
     if (limit > 0)
     {
         foreach (var e in root.Children)
         {
             if (rack.HasLetter(e.Key))
             {
                 rack.Remove(e.Key);
                 LeftPart(partialWord.Append(e.Key, false), e.Value, limit - 1, rack, board, anchor);
                 rack.Add(e.Key);
             }
             else if (rack.HasBlank)
             {
                 rack.Remove('?');
                 LeftPart(partialWord.Append(e.Key, true), e.Value, limit - 1, rack, board, anchor);
                 rack.Add('?');
             }
         }
     }
 }
Exemple #9
0
        // TODO: Anchor shouldnt need to be known if we know the board is transposed or not. Find another way to
        // figure out if we placed a tile?
        private void ExtendRight(Word partialWord, Node root, Square[,] board, Square square, Rack rack, Square anchor)
        {
            if (!square.IsOccupied)
            {
                if (root.EndOfWord && square.Position != anchor.Position)
                {
                    // square is off one position to the right of the word, we calc start by the end of the word minus the letter count
                    // start is offset by 1 because it should be partialWord.Length - 1, leaving it just .Length accomplishes the same
                    LegalMove(partialWord, square.Offset(0, -(partialWord.Length)), square.Offset(0, -1), board, rack);
                }

                foreach (var e in root.Children)
                {
                    if (rack.HasLetter(e.Key) && square.CrossChecks.ContainsKey(e.Key))
                    {
                        rack.Remove(e.Key);
                        ExtendRight(partialWord.Append(e.Key, false), e.Value, board, board[square.Position.Y, square.Position.X + 1], rack, anchor);
                        rack.Add(e.Key);
                    }
                    else if (rack.HasBlank && square.CrossChecks.ContainsKey(e.Key))
                    {
                        rack.Remove('?');
                        ExtendRight(partialWord.Append(e.Key, true), e.Value, board, board[square.Position.Y, square.Position.X + 1], rack, anchor);
                        rack.Add('?');
                    }
                }
            }
            else
            {
                var key = square.Tile.Value;
                if (root.Children.ContainsKey(square.Tile.Value))
                {
                    ExtendRight(partialWord.Append(key, square.HasBlank), root.Children[key], board, board[square.Position.Y, square.Position.X + 1], rack, anchor);
                }
            }
        }
Exemple #10
0
        /// <summary>
        /// Metoda wyjmuje okreslona ilosc kostek z planszy i dodaje je do tabliczki
        /// </summary>
        /// <param name="Container"></param>
        /// <param name="StartIndex"></param>
        /// <param name="Word"></param>
        /// <param name="Rack"></param>
        public void RemoveTiles(Container Container, int StartIndex, int Number, Rack Rack)
        {
            for(int i = 0; i < Number; ++i)
            {
                Cell TempCell = Container.Get(StartIndex + i);

                if(!TempCell.IsVisited())
                {
                    Tile TempTile = TempCell.GetTile();
                    if(TempTile != null)
                    {
                        if(TempTile.IsBlank())
                        {
                            Rack.Add(new Tile(' ', true));
                        }
                        else
                        {
                            Rack.Add(TempTile);
                        }
                    }
                    TempCell.SetTile(null);
                }
            }
        }
Exemple #11
0
 public void One_Number_test()
 {
     int[] result   = rack.Add(10);
     int[] expected = { 10 };
     Assert.AreEqual(expected, result);
 }