예제 #1
0
 private bool CapturesChecker(CheckerColor color, int to)
 {
     if (color == White)
     {
         return(state.GetCheckersOnPosition(to) == -1);
     }
     else
     {
         return(state.GetCheckersOnPosition(to) == 1);
     }
 }
예제 #2
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));
            }
        }