Exemplo n.º 1
0
        public void TestCanBearCheckersOffWhenAllCheckersInHomeBoard()
        {
            int[] gameBoard = new int[] { 0, 3, 3, 3, 3, 3,
                                          0, 0, 0, 0, 0, 0,
                                          0, 0, 0, 0, 0, 0,
                                          -3, -3, -3, -3, -3, 0 };
            fd.SetReturnValues(new int[] { 2, 3 });
            bg = new BackgammonGame(gameBoard, fd);

            //With this setup, both players should be able to bear off checkers that are two, three or five positions away

            HashSet <int> expectedLegalMovesBlack = HashSetFromArray(new int[] { 22, 23, BackgammonGame.BLACK_BEAR_OFF_ID });
            HashSet <int> actualLegalMovesBlack   = bg.GetLegalMovesFor(BLACK, 20);


            Assert.IsTrue(expectedLegalMovesBlack.SetEquals(actualLegalMovesBlack));

            HashSet <int> expectedLegalMovesWhite = new HashSet <int>()
            {
                2, 3, BackgammonGame.WHITE_BEAR_OFF_ID
            };
            HashSet <int> actualLegalMovesWhite = bg.GetLegalMovesFor(WHITE, 5);

            Assert.IsTrue(expectedLegalMovesWhite.SetEquals(actualLegalMovesWhite));
        }
Exemplo n.º 2
0
        public void TestChangesRegisteredProperlyAfterOneMoveWhite()
        {
            List <int[]> moves = new List <int[]> {
                ar(1, 3)
            };

            fd = new FakeDice(moves);
            bg = new BackgammonGame(BackgammonGame.DefaultGameBoard, fd);

            bg.Move(White, 6, 3);

            var changes = bg.GetChanges();

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

            var c1 = changes[0];
            var c2 = changes[1];
            var c3 = changes[2];

            Assert.IsTrue(c1.IsDiceState(), "c1 is not dice state");
            Assert.IsTrue(c2.IsMove(), "c2 is not move");
            Assert.IsTrue(c3.IsDiceState(), "c3 is not dice state");


            Assert.IsTrue(arrayEqual(ar(1, 3), c1.AsDiceState().GetDiceValues()), "Expected 1,3 but got " + string.Join(",", c1.AsDiceState().GetDiceValues()));
            Assert.AreEqual("w 6 3", c2.AsMove().DebugString(), "Expected w 6 3, got " + c2.AsMove().DebugString());
            Assert.IsTrue(arrayEqual(new int[] { 1 }, c3.AsDiceState().GetDiceValues()));
        }
Exemplo n.º 3
0
        static Player LearnVsNaive(int gameCount)
        {
            Player white, black;
            var    game = new BackgammonGame(BackgammonGame.DefaultGameBoard, new RealDice());

            if (gameCount % 2 == 0)
            {
                white = new MachAI(game);
                black = new NaiveAI(game, Black);
            }
            else
            {
                black = new MachAI(game);
                white = new NaiveAI(game, White);
            }
            while (!TemporalDifference.GameOver(game.GetGameBoardState()))
            {
                if (game.playerToMove() == White)
                {
                    white.MakeMove();
                }
                else
                {
                    black.MakeMove();
                }
            }
            TemporalDifference.UpdateWeights(game.GetGameBoardState(), game.GetGameBoardState(), (gameCount % 2 == 0) ? White : Black);
            return((game.GetGameBoardState().getCheckersOnTarget(White) == 15) ? white : black);
        }
Exemplo n.º 4
0
        public void TestCannotMoveFromOutsideTheGameBoard()
        {
            initialGameBoard[0]++;  //Removing a black checker from position 1
            initialGameBoard[23]--; //Removing a white checker from position 24

            fd.SetReturnValues(new int[] { 3, 2 });

            //Creating a game with the above specificed game board, and one checker of each type bore offsa
            bg = new BackgammonGame(initialGameBoard, fd, 0, 1, 0, 1);

            HashSet <int> whiteMovesFromBearOff = bg.GetLegalMovesFor(WHITE, WHITE.BearOffPositionID());

            Assert.IsTrue(whiteMovesFromBearOff.Count() == 0);

            HashSet <int> whiteMovesFromOutsideBoard = bg.GetLegalMovesFor(WHITE, 26);

            Assert.IsTrue(whiteMovesFromOutsideBoard.Count() == 0);

            HashSet <int> blackMovesFromBearOff = bg.GetLegalMovesFor(BLACK, BLACK.BearOffPositionID());

            Assert.IsTrue(blackMovesFromBearOff.Count() == 0);

            HashSet <int> blackMovesFromOutsideBoard = bg.GetLegalMovesFor(BLACK, -2);

            Assert.IsTrue(blackMovesFromOutsideBoard.Count() == 0);
        }
Exemplo n.º 5
0
        public void TestCannotMoveCheckersOnBoardWhenHasCheckerOnBar()
        {
            //removing a checker white at position 6. WILL BE RESET AFTER TEST
            initialGameBoard[5] -= 1;

            //removing a black checker at position 19. WILL BE RESET AFTER TEST
            initialGameBoard[18] += 1;

            //putting one black and one white checker on the bar
            bg = new BackgammonGame(initialGameBoard, fd, 1, 0, 1, 0);

            //Ensures that any checker will reach any reachable position on the board
            fd.SetReturnValues(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 });

            //Since white player has a checker on the bar, it should not be possible to move another checker.
            //Checking that white cannot move to any positions with another checker
            HashSet <int> legalMovesWhite = bg.GetLegalMovesFor(WHITE, 13);

            Assert.AreEqual(0, legalMovesWhite.Count);

            //Since black player has a checker on the bar, it should not be possible to move another checker.
            //Checking that black cannot move to any positions with another checker
            HashSet <int> legalMovesBlack = bg.GetLegalMovesFor(BLACK, 12);

            Assert.AreEqual(0, legalMovesBlack.Count);
        }
Exemplo n.º 6
0
        public void TestCannotMoveToPositionWithTwoOrMoreEnemyCheckers()
        {
            fd.SetReturnValues(new int[] { 5, 2 });
            bg = new BackgammonGame(initialGameBoard, fd);

            //Given the initial board setup and the values 5 and 2 on the dice,
            //white can only move to position 22 from position 24,
            // due to 19 and 17 being blocked by more than 1 black checker

            HashSet <int> expectedLegalMovesWhite = new HashSet <int>();

            expectedLegalMovesWhite.Add(22);

            HashSet <int> actualLegalMovesWhite =
                bg.GetLegalMovesFor(WHITE, 24);

            Assert.IsTrue(actualLegalMovesWhite.SetEquals(expectedLegalMovesWhite));

            //Given the initial board setup and the values 5 and 2 on the dice,
            //black can only move to position 3 from position 1, due to 6 and 8 being
            //blocked by more than 1 white checker
            HashSet <int> expectedLegalMovesBlack = new HashSet <int>();

            expectedLegalMovesBlack.Add(3);

            HashSet <int> actualLegalMovesBlack =
                bg.GetLegalMovesFor(BLACK, 1);

            Assert.IsTrue(actualLegalMovesBlack.SetEquals(expectedLegalMovesBlack));
        }
Exemplo n.º 7
0
        public void TestCannotMoveCheckersOutsideGameBoard()
        {
            //Moving a black checker from position 19 to position 23. WILL BE RESET BEFORE NEXT TEST
            initialGameBoard[18] += 1;
            initialGameBoard[22] -= 1;

            //Moving a white checker from position 6 to position 2. WILL BE RESET BEFORE NEXT TEST
            initialGameBoard[5] -= 1;
            initialGameBoard[1] += 1;

            bg = new BackgammonGame(initialGameBoard, fd);

            //Setting the dice values
            fd.SetReturnValues(new int[] { 6, 2 });

            //All possible moves for the white checer on position 2 ends up outside the board, while
            //white is not bearing off his checkers. Therefore, there are no legal moves for the white checker
            HashSet <int> actualLegalMovesWhite = bg.GetLegalMovesFor(WHITE, 2);

            Assert.IsTrue(actualLegalMovesWhite.Count == 0);

            //All possible moves for the black checer on position 23 ends up outside the board, while
            //black is not bearing off his checkers. Therefore, there are no legal moves for that black checker
            HashSet <int> actualLegalMovesBlack = bg.GetLegalMovesFor(BLACK, 23);

            Assert.IsTrue(actualLegalMovesBlack.Count == 0);
        }
Exemplo n.º 8
0
        public void TestChangesRegisteredProperlyCompundMovesOfMultipleSmallerMoves()
        {
            List <int[]> moves = new List <int[]>()
            {
                ar(1, 3), ar(4, 4)
            };

            fd = new FakeDice(moves);
            bg = new BackgammonGame(BackgammonGame.DefaultGameBoard, fd);
            bg.Move(White, 13, 9);

            var changes = bg.GetChanges();

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

            var c1 = changes[0];
            var c2 = changes[1];
            var c3 = changes[2];
            var c4 = changes[3];
            var c5 = changes[4];

            Assert.IsTrue(c1.IsDiceState(), "c1 is not dice state");
            Assert.IsTrue(c2.IsMove(), "c2 is not move");
            Assert.IsTrue(c3.IsDiceState(), "c3 is not dice state");


            Assert.IsTrue(arrayEqual(ar(1, 3), c1.AsDiceState().GetDiceValues()), "Expected 1,3 but got " + string.Join(",", c1.AsDiceState().GetDiceValues()));
            Assert.AreEqual("w 13 10", c2.AsMove().DebugString());
            Assert.IsTrue(arrayEqual(new int[] { 1 }, c3.AsDiceState().GetDiceValues()));
            Assert.AreEqual("w 10 9", c4.AsMove().DebugString());
            Assert.IsTrue(arrayEqual(new int[] { 4, 4, 4, 4 }, c5.AsDiceState().GetDiceValues()));
        }
Exemplo n.º 9
0
        public void TestLegalMovesFromPointWithNoCheckerGivesEmptyResult()
        {
            bg = new BackgammonGame(initialGameBoard, fd);

            //Ensures that at least one open position is reachable from anywhere on the board
            fd.SetReturnValues(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
                                           13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 });


            //There are no white or black checkers on position 14
            //And
            HashSet <int> legalMovesWhite =
                bg.GetLegalMovesFor(WHITE, 14);

            Assert.IsTrue(legalMovesWhite.Count == 0);

            HashSet <int> legalMovesBlack =
                bg.GetLegalMovesFor(BLACK, 14);

            Assert.IsTrue(legalMovesBlack.Count == 0);

            //There are black, but not white, checkers on position 12
            //Test that it is not possible to move white checkers from here
            legalMovesWhite =
                bg.GetLegalMovesFor(WHITE, 12);
            Assert.IsTrue(legalMovesWhite.Count == 0);

            //There are white, but not black, checkers on position 13
            //Test that it is not possible to move black checkers from here
            legalMovesBlack =
                bg.GetLegalMovesFor(BLACK, 13);
            Assert.IsTrue(legalMovesBlack.Count == 0);
        }
Exemplo n.º 10
0
        public void TestGetPreviousTurnWhenNoLegalMoves()
        {
            //When it becomes black's turn, there will be no legal moves, but the turn should change to white
            //before bg.EndTurn(Black) is called
            int[] board = new int[]
            {
                -15, 2, 2, 2, 2, 2,
                2, 3, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0
            };

            List <int[]> moves = new List <int[]>()
            {
                ar(1, 3), ar(5, 3)
            };

            fd = new FakeDice(moves);

            bg = new BackgammonGame(board, fd);
            bg.Move(White, 8, 5);
            bg.Move(White, 8, 7);

            var turn = bg.GetPreviousTurn();

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

            bg.EndTurn(Black);
            turn = bg.GetPreviousTurn();
            Assert.AreEqual(Black, turn.color);
            Assert.IsTrue(arrayEquals(ar(5, 3), turn.dice.ToArray()));
            Assert.AreEqual(0, turn.moves.Count());
        }
Exemplo n.º 11
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());
        }
Exemplo n.º 12
0
        public void TestThatIfWhiteCheckerIsCapturedAChangeShowsItIsMovedToTheBar()
        {
            int[] mainBoard = new int[] {
                -2, 0, 0, 0, 0, 5,
                0, 3, 0, 0, 0, -5,
                5, 0, 0, 0, -3, 0,
                -5, 0, 0, 1, 0, 1
            };
            fd.SetReturnValues(ar(1, 3));
            bg = new BackgammonGame(mainBoard, fd, 0, 0, 0, 0, Black);
            bg.Move(Black, 19, 22);

            var changes = bg.GetChanges();

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

            var c1 = changes[0];
            var c2 = changes[1];
            var c3 = changes[2];
            var c4 = changes[3];

            Assert.IsTrue(c1.IsDiceState(), "c1 is not dice state");
            Assert.IsTrue(c2.IsMove(), "c2 is not move");
            Assert.IsTrue(c3.IsMove());
            Assert.IsTrue(c4.IsDiceState(), "c3 is not dice state");


            Assert.IsTrue(arrayEqual(ar(1, 3), c1.AsDiceState().GetDiceValues()), "Expected 1,3 but got " + string.Join(",", c1.AsDiceState().GetDiceValues()));
            Assert.AreEqual("b 19 22", c2.AsMove().DebugString());
            Assert.AreEqual("w 22 " + White.GetBar(), c3.AsMove().DebugString());
            Assert.IsTrue(arrayEqual(new int[] { 1 }, c4.AsDiceState().GetDiceValues()));
        }
Exemplo n.º 13
0
 private void Instantiate()
 {
     int[] InitialBoard = BackgammonGame.DefaultGameBoard; // Board.TestBoard3;
     Board         = new Board(InitialBoard);
     Model         = new BackgammonGame(InitialBoard, new RealDice());
     ViewInterface = new ViewInterface(Model);
     Model.ConnectView(this);
     if (WhitePlayer == PlayerType.Online)
     {
         TCPManager.Instance.Instantiate(Model, White);
     }
     if (BlackPlayer == PlayerType.Online)
     {
         TCPManager.Instance.Instantiate(Model, Black);
     }
     if (OptionScreen.ShowPips.SwitchedOn)
     {
         WhitePips = new Image()
         {
             Text = "White: " + Model.GetGameBoardState().pip(White), Position = new Vector2(Board.midX, 700)
         };
         BlackPips = new Image()
         {
             Text = "Black: " + Model.GetGameBoardState().pip(Black), Position = new Vector2(Board.midX, 20)
         };
         WhitePips.LoadContent();
         BlackPips.LoadContent();
     }
 }
Exemplo n.º 14
0
        public void TestIllegalMoveWhiteThrowsException()
        {
            fd.SetReturnValues(new int[] { 5, 1 });
            bg = new BackgammonGame(initialGameBoard, fd);

            bg.Move(WHITE, 6, 1);
        }
Exemplo n.º 15
0
 internal void MakeMove(BackgammonGame model, CheckerColor color)
 {
     if (RemotePlayer == null)
     {
         Instantiate(model, color);
     }
     RemotePlayer.MakeMove();
 }
Exemplo n.º 16
0
        public void TestChangesRegisteredProperlyAfterRolledTwoEqualDiceAndAllMovesConsumed()
        {
            List <int[]> moves = new List <int[]> {
                ar(2, 2), ar(1, 5)
            };

            fd = new FakeDice(moves);
            bg = new BackgammonGame(BackgammonGame.DefaultGameBoard, fd);

            bg.Move(White, 6, 4);
            bg.Move(White, 6, 4);
            bg.Move(White, 13, 11);
            bg.Move(White, 24, 22);

            var changes = bg.GetChanges();

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

            var c1 = changes[0];
            var c2 = changes[1];
            var c3 = changes[2];
            var c4 = changes[3];
            var c5 = changes[4];
            var c6 = changes[5];
            var c7 = changes[6];
            var c8 = changes[7];
            var c9 = changes[8];

            Assert.IsTrue(c1.IsDiceState(), "c1 is not dice state");
            Assert.IsTrue(c2.IsMove(), "c2 is not move");
            Assert.IsTrue(c3.IsDiceState(), "c3 is not dice state");
            Assert.IsTrue(c4.IsMove(), "c4 is not move");
            Assert.IsTrue(c5.IsDiceState(), "c5 is not dice state");
            Assert.IsTrue(c6.IsMove());
            Assert.IsTrue(c7.IsDiceState());
            Assert.IsTrue(c8.IsMove());
            Assert.IsTrue(c9.IsDiceState());



            Assert.IsTrue(arrayEqual(new int[] { 2, 2, 2, 2 }, c1.AsDiceState().GetDiceValues()), "Expected 1,3 but got " + string.Join(",", c1.AsDiceState().GetDiceValues()));

            Assert.AreEqual("w 6 4", c2.AsMove().DebugString());

            Assert.IsTrue(arrayEqual(new int[] { 2, 2, 2 }, c3.AsDiceState().GetDiceValues()));

            Assert.AreEqual("w 6 4", c4.AsMove().DebugString());

            Assert.IsTrue(arrayEqual(ar(2, 2), c5.AsDiceState().GetDiceValues()));

            Assert.AreEqual("w 13 11", c6.AsMove().DebugString());

            Assert.IsTrue(arrayEqual(new int[] { 2 }, c7.AsDiceState().GetDiceValues()));

            Assert.AreEqual("w 24 22", c8.AsMove().DebugString());

            Assert.IsTrue(arrayEqual(ar(1, 5), c9.AsDiceState().GetDiceValues()));
        }
Exemplo n.º 17
0
        public void TestChangesRegisteredProperlyAfterBothWhiteAndBlackMoves()
        {
            List <int[]> moves = new List <int[]> {
                ar(1, 3), ar(4, 5), ar(6, 3)
            };

            fd = new FakeDice(moves);
            bg = new BackgammonGame(BackgammonGame.DefaultGameBoard, fd);

            bg.Move(White, 6, 3);
            bg.Move(White, 6, 5);
            bg.Move(Black, 19, 23);
            bg.Move(Black, 17, 22);

            var changes = bg.GetChanges();

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

            var c1 = changes[0];
            var c2 = changes[1];
            var c3 = changes[2];
            var c4 = changes[3];
            var c5 = changes[4];
            var c6 = changes[5];
            var c7 = changes[6];
            var c8 = changes[7];
            var c9 = changes[8];

            Assert.IsTrue(c1.IsDiceState(), "c1 is not dice state");
            Assert.IsTrue(c2.IsMove(), "c2 is not move");
            Assert.IsTrue(c3.IsDiceState(), "c3 is not dice state");
            Assert.IsTrue(c4.IsMove(), "c4 is not move");
            Assert.IsTrue(c5.IsDiceState(), "c5 is not dice state");
            Assert.IsTrue(c6.IsMove());
            Assert.IsTrue(c7.IsDiceState());
            Assert.IsTrue(c8.IsMove());
            Assert.IsTrue(c9.IsDiceState());



            Assert.IsTrue(arrayEqual(ar(1, 3), c1.AsDiceState().GetDiceValues()), "Expected 1,3 but got " + string.Join(",", c1.AsDiceState().GetDiceValues()));

            Assert.AreEqual("w 6 3", c2.AsMove().DebugString(), "Expected w 6 3, got " + c2.AsMove().DebugString());

            Assert.IsTrue(arrayEqual(new int[] { 1 }, c3.AsDiceState().GetDiceValues()));

            Assert.AreEqual("w 6 5", c4.AsMove().DebugString());

            Assert.IsTrue(arrayEqual(ar(4, 5), c5.AsDiceState().GetDiceValues()));

            Assert.AreEqual("b 19 23", c6.AsMove().DebugString());

            Assert.IsTrue(arrayEqual(new int[] { 5 }, c7.AsDiceState().GetDiceValues()));

            Assert.AreEqual("b 17 22", c8.AsMove().DebugString());

            Assert.IsTrue(arrayEqual(ar(6, 3), c9.AsDiceState().GetDiceValues()));
        }
Exemplo n.º 18
0
        public void TestChangesRegisteredProperlyAfterNotifyViewFlushesChanges()
        {
            List <int[]> moves = new List <int[]>()
            {
                ar(1, 3), ar(4, 4)
            };

            fd = new FakeDice(moves);
            bg = new BackgammonGame(BackgammonGame.DefaultGameBoard, fd);



            bg.Move(White, 6, 3);

            var changes = bg.GetChanges();

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

            var c1 = changes[0];
            var c2 = changes[1];
            var c3 = changes[2];

            Assert.IsTrue(c1.IsDiceState(), "c1 is not dice state");
            Assert.IsTrue(c2.IsMove(), "c2 is not move");
            Assert.IsTrue(c3.IsDiceState(), "c3 is not dice state");



            Assert.IsTrue(arrayEqual(ar(1, 3), c1.AsDiceState().GetDiceValues()), "Expected 1,3 but got " + string.Join(",", c1.AsDiceState().GetDiceValues()));
            Assert.AreEqual("w 6 3", c2.AsMove().DebugString(), "Expected w 6 3, got " + c2.AsMove().DebugString());
            Assert.IsTrue(arrayEqual(new int[] { 1 }, c3.AsDiceState().GetDiceValues()));


            //At least one view has to be present for backgammon game to flush the recent changes
            View view = new DummyView();

            bg.ConnectView(view);
            bg.NotifyAllViews();

            //Disconnecting the view again so that we may read the changes
            bg.DisconnectView(view);

            changes = bg.GetChanges();
            Assert.AreEqual(0, changes.Count());

            bg.Move(White, 6, 5);

            changes = bg.GetChanges();
            Assert.AreEqual(2, changes.Count());
            var c4 = changes[0];
            var c5 = changes[1];

            Assert.IsTrue(c4.IsMove());
            Assert.IsTrue(c5.IsDiceState());
            Assert.AreEqual("w 6 5", c4.AsMove().DebugString());
            Assert.IsTrue(arrayEqual(new int[] { 4, 4, 4, 4 }, c5.AsDiceState().GetDiceValues()));
        }
Exemplo n.º 19
0
 public void initialize()
 {
     moves = new List <int[]>()
     {
         ar(1, 2), ar(4, 3), ar(1, 1), ar(1, 1), ar(6, 5), ar(3, 3)
     };
     fd = new FakeDice(moves);
     bg = new BackgammonGame(BackgammonGame.DefaultGameBoard, fd);
 }
Exemplo n.º 20
0
        public void Initialize()
        {
            List <int[]> moves = new List <int[]>()
            {
                ar(1, 3), ar(5, 3), ar(6, 1), ar(1, 2)
            };

            fd = new FakeDice(moves);
            bg = new BackgammonGame(BackgammonGame.DefaultGameBoard, fd);
        }
Exemplo n.º 21
0
 public BackgammonVM(string playerA, string playerB)
 {
     PlayerA = playerA;
     PlayerB = playerB;
     PropertyChanged?.Invoke(null, new PropertyChangedEventArgs("PlayerA"));
     PropertyChanged?.Invoke(null, new PropertyChangedEventArgs("PlayerB"));
     InitDiceImageList();
     IsWaitingForMove              = false;
     Game                          = new BackgammonGame();
     Game.PropertyChanged         += Game_PropertyChanged;
     ChatResult.MoveRecievedEvent += ChatResult_MoveRecievedEvent;
 }
Exemplo n.º 22
0
        public void TestMoveUpdatesCheckersOnPositionsBlack()
        {
            fd.SetReturnValues(new int[] { 2, 3 });
            bg = new BackgammonGame(initialGameBoard, fd, 0, 0, 0, 0, BLACK);
            bg.Move(BLACK, 19, 22);
            int[] actualResult   = bg.GetGameBoardState().getMainBoard();
            int[] expectedResult = new int[] { -2, 0, 0, 0, 0, 5,
                                               0, 3, 0, 0, 0, -5,
                                               5, 0, 0, 0, -3, 0,
                                               -4, 0, 0, -1, 0, 2 };

            Assert.IsTrue(Enumerable.SequenceEqual(actualResult, expectedResult));
        }
Exemplo n.º 23
0
        public void TestGetWhiteMovesFromBlackBarEmptyAndViceVersa()
        {
            bg = new BackgammonGame(initialGameBoard, fd);
            fd.SetReturnValues(new int[] { 1, 2 });
            HashSet <int> legalMovesWhite =
                bg.GetLegalMovesFor(BLACK, BackgammonGame.WHITE_BAR_ID);

            Assert.AreEqual(0, legalMovesWhite.Count());

            HashSet <int> legalMovesBlack =
                bg.GetLegalMovesFor(WHITE, BackgammonGame.BLACK_BAR_ID);

            Assert.AreEqual(0, legalMovesBlack.Count());
        }
Exemplo n.º 24
0
        public void TestChangesRegisteredProperlyWhenTurnChangesAndThereAreNoLegalMoves()
        {
            int[] board = new int[]
            {
                0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, -15,
                2, 2, 2, 2, 2, 5
            };
            fd.SetReturnValues(ar(1, 3));
            bg = new BackgammonGame(board, fd);

            bg.Move(White, 24, 23);
            bg.Move(White, 24, 21);
        }
Exemplo n.º 25
0
 private void Move(BackgammonGame model, CheckerColor c, Player ai)
 {
     if (ai == null)
     {
         if (naive)
         {
             ai = new NaiveAI(model, c);
         }
         else
         {
             ai = new MachAI(model);
         }
     }
     ai.MakeMove();
 }
Exemplo n.º 26
0
        public void TestGetLegalMovesForBlack()
        {
            fd.SetReturnValues(new int[] { 5, 3 });
            bg = new BackgammonGame(initialGameBoard, fd);


            //Get the legal moves for black's checkers on position 12
            HashSet <int> ActualLegalMoves = bg.GetLegalMovesFor(BLACK, 12);

            //with the initial board configuration and the dice showing 5 and 3,
            //the legal positions to move to are {15, 17, 20}
            HashSet <int> ExpectedLegalMoves = HashSetFromArray(new int[] { 15, 17, 20 });

            Assert.IsTrue(ActualLegalMoves.SetEquals(ExpectedLegalMoves));
        }
Exemplo n.º 27
0
        public void TestGetLegalMovesForWhite()
        {
            fd.SetReturnValues(new int[] { 2, 3 });
            bg = new BackgammonGame(initialGameBoard, fd);


            //Get the legal moves for whites checkers on position 13.
            HashSet <int> ActualLegalMoves = bg.GetLegalMovesFor(WHITE, 13);

            //with the initial board configuration and the dice showing 2 and 3,
            //the legal positions to move to are {11, 10, 8}
            HashSet <int> ExpectedLegalMoves = HashSetFromArray(new int[] { 8, 10, 11 });

            Assert.IsTrue(ActualLegalMoves.SetEquals(ExpectedLegalMoves));
        }
Exemplo n.º 28
0
        public void TestCannotBearOffCheckersWhenNotAllCheckersInHomeBoard()
        {
            bg = new BackgammonGame(initialGameBoard, fd);
            fd.SetReturnValues(new int[] { 6, 1 });
            //With this setup, the black checkers on position 19 and the white checkers on position 6 are able to
            //reach their bear off position. However, all checkers are not in the homeboard, so it should not be available.

            HashSet <int> legalBlackMoves = bg.GetLegalMovesFor(BLACK, 19);

            Assert.IsFalse(legalBlackMoves.Contains(BackgammonGame.BLACK_BEAR_OFF_ID));

            HashSet <int> legalWhiteMoves = bg.GetLegalMovesFor(WHITE, 6);

            Assert.IsFalse(legalWhiteMoves.Contains(BackgammonGame.WHITE_BEAR_OFF_ID));
        }
Exemplo n.º 29
0
        public void TestChangesContainsInitialMovesWhenGameStartesBlack()
        {
            fd.SetReturnValues(ar(1, 2));
            bg = new BackgammonGame(BackgammonGame.DefaultGameBoard, fd, 0, 0, 0, 0, Black);

            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()));
        }
Exemplo n.º 30
0
        public void TestMoveConsistingOfMultipleMovesBlack()
        {
            fd.SetReturnValues(new int[] { 3, 1 });
            bg = new BackgammonGame(initialGameBoard, fd, 0, 0, 0, 0, BLACK);

            bg.Move(BLACK, 19, 23);

            int[] expectedGameBoard = new int[] { -2, 0, 0, 0, 0, 5,
                                                  0, 3, 0, 0, 0, -5,
                                                  5, 0, 0, 0, -3, 0,
                                                  -4, 0, 0, 0, -1, 2 };

            int[] actualGameBoard = bg.GetGameBoardState().getMainBoard();

            Assert.IsTrue(Enumerable.SequenceEqual(expectedGameBoard, actualGameBoard));
        }