示例#1
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()));
        }
示例#2
0
 internal int GetAmountOfCheckersAtPoint(int i)
 {
     if (i == CheckerColor.Black.GetBar())
     {
         return(BlackBar.GetAmount());
     }
     else if (i == White.GetBar())
     {
         return(WhiteBar.GetAmount());
     }
     else if (i == White.BearOffPositionID())
     {
         return(WhiteBearOff.GetAmount());
     }
     else if (i == Black.BearOffPositionID())
     {
         return(BlackBearOff.GetAmount());
     }
     else
     {
         int value = Points[i].GetAmount();
         if (value != 0 && Points[i].GetTopChecker().Color == Black)
         {
             return(-value);
         }
         return(value);
     }
 }
示例#3
0
 internal int GetClickedPoint()
 {
     foreach (Point p in Points)
     {
         if (InputManager.Instance.WasClicked(p.GetBounds()))
         {
             if (p.Equals(WhiteBar))
             {
                 return(White.GetBar());
             }
             else if (p.Equals(WhiteBearOff))
             {
                 return(White.BearOffPositionID());
             }
             else if (p.Equals(BlackBar))
             {
                 return(Black.GetBar());
             }
             else if (p.Equals(BlackBearOff))
             {
                 return(Black.BearOffPositionID());
             }
             else
             {
                 return(Points.IndexOf(p));
             }
         }
     }
     return(-1);
 }
示例#4
0
        public void XmlifyMoveAndParseBackFromString()
        {
            Move   move1       = new Move(White, 6, 3);
            string move1Xml    = UpdateCreatorParser.CreateXmlForMove(move1);
            Move   parsedMove1 = UpdateCreatorParser.ParseMove(move1Xml);

            Assert.AreEqual("<move>w 6 3</move>", move1Xml);
            Assert.AreEqual(move1, parsedMove1);

            Move   move2       = new Move(White, 6, White.GetBar());
            string move2Xml    = UpdateCreatorParser.CreateXmlForMove(move2);
            Move   parsedMove2 = UpdateCreatorParser.ParseMove(move2Xml);

            Assert.AreEqual("<move>w 6 25</move>", move2Xml);
            Assert.AreEqual(move2, parsedMove2, "this one failing");

            Move   move3       = new Move(White, 6, White.BearOffPositionID());
            string move3Xml    = UpdateCreatorParser.CreateXmlForMove(move3);
            Move   parsedMove3 = UpdateCreatorParser.ParseMove(move3Xml);

            Assert.AreEqual("<move>w 6 28</move>", move3Xml);
            Assert.AreEqual(move3, parsedMove3);


            Move   move4       = new Move(Black, 20, 24);
            string move4Xml    = UpdateCreatorParser.CreateXmlForMove(move4);
            Move   parsedMove4 = UpdateCreatorParser.ParseMove(move4Xml);

            Assert.AreEqual("<move>b 20 24</move>", move4Xml);
            Assert.AreEqual(move4, parsedMove4);

            Move   move5       = new Move(Black, 24, Black.BearOffPositionID());
            string move5Xml    = UpdateCreatorParser.CreateXmlForMove(move5);
            Move   parsedMove5 = UpdateCreatorParser.ParseMove(move5Xml);

            Assert.AreEqual("<move>b 24 27</move>", move5Xml);
            Assert.AreEqual(move5, parsedMove5);


            Move   move6       = new Move(Black, 20, Black.GetBar());
            string move6Xml    = UpdateCreatorParser.CreateXmlForMove(move6);
            Move   parsedMove6 = UpdateCreatorParser.ParseMove(move6Xml);

            Assert.AreEqual("<move>b 20 26</move>", move6Xml);
            Assert.AreEqual(move6, parsedMove6);
        }
示例#5
0
        internal static string CreateXmlForGameBoardState(GameBoardState state, string rootTag)
        {
            if (state == null)
            {
                throw new ArgumentNullException("state");
            }
            if (rootTag == null)
            {
                throw new ArgumentNullException("rootTag");
            }

            //Separating each element of the array with a space, and removes trailing spaces
            var board = state.getMainBoard().Select(i => i + " ").Aggregate((a, b) => a + b).Trim();

            //Wrap the board with tags
            board = "<board>" + board + "</board>";


            int whiteGoal = state.GetCheckersOnPosition(White.BearOffPositionID());
            int whiteBar  = state.GetCheckersOnPosition(White.GetBar());

            //The agreed format is that black checkers on bar and target should be represented as negative
            int blackGoal = state.GetCheckersOnPosition(Black.BearOffPositionID());

            blackGoal = Math.Min(blackGoal, blackGoal * -1);

            int blackBar = state.GetCheckersOnPosition(Black.GetBar());

            blackBar = Math.Min(blackBar, blackBar * -1);

            //Wrap each of the above four values in their own tags
            var rest = String.Format("<whiteGoal>{0}</whiteGoal><whiteBar>{1}</whiteBar><blackGoal>{2}</blackGoal><blackBar>{3}</blackBar>",
                                     whiteBar, whiteGoal, blackBar, blackGoal);

            //Wrapping the entire message in the supplied root tags
            if (rootTag == "")
            {
                return(board + rest);
            }
            else
            {
                return(String.Format("<{0}>" + board + rest + "</{0}>", rootTag));
            }
        }
示例#6
0
 private static int AdaptPositionFromOutputFormat(int pos)
 {
     if (pos == WHITE_BAR_POSITION_IN_UPDATE_MESSAGE)
     {
         return(White.GetBar());
     }
     if (pos == WHITE_TARGET_POSITION_IN_UPDATE_MESSAGE)
     {
         return(White.BearOffPositionID());
     }
     if (pos == BLACK_BAR_POSITION_IN_UPDATE_MESSAGE)
     {
         return(Black.GetBar());
     }
     if (pos == BLACK_TARGET_POSITION_IN_UPDATE_MESSAGE)
     {
         return(Black.BearOffPositionID());
     }
     return(pos);
 }