예제 #1
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);
     }
 }
예제 #2
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);
 }
예제 #3
0
 internal int GetClickedPoint(int i)
 {
     if (GamePadPointOrdering[i] == WhiteBearOff)
     {
         return(White.BearOffPositionID());
     }
     else if (GamePadPointOrdering[i] == BlackBearOff)
     {
         return(Black.BearOffPositionID());
     }
     return(Points.IndexOf(GamePadPointOrdering[i]));
 }
예제 #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);
 }