Example #1
0
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            _game = Game.Load(TestGame.PGN);
            Board.SetPieces(_game);
        }
Example #2
0
 public void SetPieces(Game game)
 {
     if (game == null) throw new ArgumentNullException("game");
     for (int rank = 1; rank <= 8; rank++)
     {
         for (char file = 'a'; file <= 'h'; file++)
         {
             Piece piece = game.GetPiece(new Location(file, rank));
             _boardSpaces[file - 'a', rank - 1].Text = piece != null ? AsciiPiece.GetCharForPiece(piece).ToString() : "";
         }
     }
 }
Example #3
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.board);

            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(TestGame.PGN)))
            {
                _game = Game.Load(stream);
            }

            SetPieces();

            //Wire up button click handles
            var nextMove = FindViewById<Button>(Resource.Id.btnNextMove);
            nextMove.Click += NextMoveOnClick;

            var previousMove = FindViewById<Button>(Resource.Id.btnPreviousMove);
            previousMove.Click += PreviousMoveOnClick;

            var resetBoard = FindViewById<Button>(Resource.Id.btnResetBoard);
            resetBoard.Click += ResetBoardOnClick;
        }
Example #4
0
        public static Game Load(string pgn)
        {
            var rv = new Game();

            foreach (Match match in _tagPairsRegex.Matches(pgn))
            {
                string name = match.Groups["Name"].Value;
                string value = match.Groups["Value"].Value;

                rv._tagPairs[name] = value;
            }

            var moveRegex = new Regex(string.Format(MoveRegexPattern, rv.TagPairs["Result"]));

            foreach (Match match in moveRegex.Matches(pgn))
            {
                //This is also available
                //string moveNumber = match.Groups["MoveNumber"].Value;

                Piece whitePiece = GetPieceFromLetter(match.Groups["WhitePiece"].Value, PieceColor.White);
                rv.AddMove(match.Groups["WhiteMove"].Value, whitePiece, match.Groups["WhiteFrom"].Value, match.Groups["WhiteTo"].Value);

                Piece blackPiece = GetPieceFromLetter(match.Groups["BlackPiece"].Value, PieceColor.Black);
                rv.AddMove(match.Groups["BlackMove"].Value, blackPiece, match.Groups["BlackFrom"].Value, match.Groups["BlackTo"].Value);
            }

            //Put the pieces back to the beginning.
            rv._board.ResetMoves();

            return rv;
        }