Example #1
0
        public void TestChangesContainsInitialMovesWhenGameStartesWhite()
        {
            fd.SetReturnValues(ar(1, 2));


            var changes = bg.GetChanges();

            Assert.AreEqual(1, changes.Count());


            Assert.IsTrue(changes[0].IsDiceState(), "expected true, got " + changes[0].IsDiceState());

            var ds = changes[0].AsDiceState();

            Assert.IsTrue(Enumerable.SequenceEqual(ds.GetDiceValues(), ar(1, 2)), "Expected {1,2}, was " + string.Join(",", ds.GetDiceValues()));
        }
Example #2
0
        public void TestGetPreviousTurnWhenOnlySomeMovesCouldBeUsed()
        {
            //White will roll 1 and 3, so he will only be able to move the checker on position 24 to position 21.
            //There will be no other legal moves, so the turn changes. We check that the previous turn mirrors this
            int[] board = new int[]
            {
                14, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0,
                0, 0, 0, -3, -2, -2,
                -2, -2, 0, -2, -2, 1
            };

            fd.SetReturnValues(ar(1, 3));
            bg = new BackgammonGame(board, fd);
            bg.Move(White, 24, 21);


            var turn = bg.GetPreviousTurn();

            Assert.AreEqual(White, turn.color);
            Assert.IsTrue(arrayEquals(ar(1, 3), turn.dice.ToArray()));

            var moves = turn.moves;

            Assert.AreEqual(1, moves.Count());
            Assert.AreEqual("w 24 21", moves[0].DebugString());
        }
Example #3
0
        public void TestFakeDice()
        {
            int[] CurrentDiceValues = new int[] { 1, 2 };
            //Testing that FakeDice actually returns what is specified in the constructor
            //and that the output stays the same unless otherwise specified
            for (int i = 0; i < 30; i++)
            {
                Assert.IsTrue(AreEqualArrays(CurrentDiceValues, fd.RollDice()));
            }

            //Testing that the return change if new return values are specified
            int[] NewReturnValues = new int[] { 2, 3, 4 };
            fd.SetReturnValues(NewReturnValues);
            Assert.IsTrue(AreEqualArrays(NewReturnValues, fd.RollDice()));
        }