예제 #1
0
        public void GameState_Board_Is_Immutable_After_Construction()
        {
            var array = new Piece[64];

            array[0] = Piece.WhiteRook;

            var target = new GameState(array, Piece.White, Castling.KQkq, Cell.None, 0, 1);

            //*** Initial state: a1 should have a WhiteRook
            Assert.AreEqual(Piece.WhiteRook, target.Board[Cell.a1]);

            //*** Outside array is mutated
            array[0] = Piece.BlackRook;

            //*** Expected: board a1 should maintain its inital state
            Assert.AreEqual(Piece.WhiteRook, target.Board[Cell.a1]);

            //*** Also, converting the board back to an array
            var array2 = target.Board.ToArray();

            //*** And mutating the returned array, shouldn't modify the original board
            array2[0] = Piece.BlackRook;

            //*** Expected: board a1 should maintain its inital state
            Assert.AreEqual(Piece.WhiteRook, target.Board[Cell.a1]);
        }
예제 #2
0
        public void addPiece(Piece piece, int x, int y)
        {
            if(selectPiece(x, y) != null) {
                throw new ArgumentException("There is already a piece on that square.");
            }

            Grid[x, y] = piece;
        }
예제 #3
0
        public PgnMove(string pgnString)
        {
            Match m = r.Match(pgnString);

              if (m.Groups["Move"].Value == "")
              {
            ColorToPlay = PieceColor.Black;
              }
              else
              {
            ColorToPlay = PieceColor.White;
              }

              if (m.Groups["Castling"].Value == "")
              {
            PieceToPlay = StringToPiece(m.Groups["Piece"].Value, ColorToPlay);
            FromFile = StringToFile(m.Groups["File"].Value);
            FromRank = StringToRank(m.Groups["Rank"].Value);
            DestinationSquare = StringToSquare(m.Groups["Destination"].Value);
            PromotionPiece = StringToPromotion(m.Groups["Promotion"].Value);
              }
              else if (m.Groups["Castling"].Value == "O-O")
              {
            if (ColorToPlay == PieceColor.White)
            {
              DestinationSquare = Square.G1;
              PieceToPlay = Piece.WhiteKing;
              FromFile = 4;
              FromRank = 0;
            }

            if (ColorToPlay == PieceColor.Black)
            {
              DestinationSquare = Square.G8;
              PieceToPlay = Piece.BlackKing;
              FromFile = 4;
              FromRank = 7;
            }
              }
              else if (m.Groups["Castling"].Value == "O-O-O")
              {
            if (ColorToPlay == PieceColor.White)
            {
              DestinationSquare = Square.C1;
              PieceToPlay = Piece.WhiteKing;
              FromFile = 4;
              FromRank = 0;
            }

            if (ColorToPlay == PieceColor.Black)
            {
              DestinationSquare = Square.C8;
              PieceToPlay = Piece.BlackKing;
              FromFile = 4;
              FromRank = 7;
            }
              }
        }
예제 #4
0
        public GameState(Piece[] board, Piece active, Castling castling, Cell enpassant, int draw, int move)
        {
            if (board.Length != 64)
            {
                throw new ArgumentException("Board must be 64 squares", nameof(board));
            }

            if (active != Piece.White && active != Piece.Black)
            {
                throw new ArgumentException("Must be White or Black", nameof(active));
            }

            Board = new Board((Piece[])board.Clone());
            Active = active;
            Castling = castling;
            Enpassant = enpassant;
            DrawClock = draw;
            Move = move;
        }
예제 #5
0
 public static bool CanMove(Piece piece, Direction dir)
 {
     ISet<Direction> allowableDirections;
     return Piece.TryGetValue(piece, out allowableDirections) && allowableDirections.Contains(dir);
 }
예제 #6
0
        private static Piece[] ParseBoard(string state, ref int i)
        {
            var retval = new Piece[64];

            var cell = 64 - 8;
            char c;
            while ((c = state[i]) != ' ')
            {
                if (c >= '1' && c <= '8')
                {
                    i++;
                    for (var j = c - '0'; j > 0; j--)
                    {
                        retval[cell++] = Piece.None;
                    }
                }
                else if (c == '/')
                {
                    i++;

                    if (cell % 8 != 0)
                    {
                        throw new ArgumentException();
                    }

                    cell -= 16;
                }
                else if (_PieceChar.TryGetFirst(c, out retval[cell]))
                {
                    i++;
                    cell++;
                }
                else
                {
                    throw new ArgumentException();
                }
            }
            i++;

            return retval;
        }
예제 #7
0
 public override Image PieceImage(Piece piece)
 {
     return m_pieces[(int)piece];
 }
예제 #8
0
 private Pawn GetPawn(Piece p, int i, int j)
 {
     return new Pawn(((int)p.ChessColor) + p.GetType().Name, i + 1, j + 1);
 }
예제 #9
0
파일: Board.cs 프로젝트: MerickOWA/Chess
 public Board(Piece[] pieces)
 {
     _pieces = pieces;
 }
예제 #10
0
파일: Move.cs 프로젝트: MerickOWA/Chess
 public Move PromoteTo(Piece promotion)
 {
     return new Move(From, To, promotion);
 }
예제 #11
0
파일: Move.cs 프로젝트: MerickOWA/Chess
 public Move(Cell from, Cell to, Piece promotion = Piece.None)
 {
     From = from;
     To = to;
     Promotion = promotion;
 }
예제 #12
0
        private void SetEditorPiece(Piece piece)
        {
            m_pictureBoxWhiteKing.BorderStyle = BorderStyle.FixedSingle;
              m_pictureBoxWhiteQueen.BorderStyle = BorderStyle.FixedSingle;
              m_pictureBoxWhiteRook.BorderStyle = BorderStyle.FixedSingle;
              m_pictureBoxWhiteBishop.BorderStyle = BorderStyle.FixedSingle;
              m_pictureBoxWhiteKnight.BorderStyle = BorderStyle.FixedSingle;
              m_pictureBoxWhitePawn.BorderStyle = BorderStyle.FixedSingle;
              m_pictureBoxBlackKing.BorderStyle = BorderStyle.FixedSingle;
              m_pictureBoxBlackQueen.BorderStyle = BorderStyle.FixedSingle;
              m_pictureBoxBlackRook.BorderStyle = BorderStyle.FixedSingle;
              m_pictureBoxBlackBishop.BorderStyle = BorderStyle.FixedSingle;
              m_pictureBoxBlackKnight.BorderStyle = BorderStyle.FixedSingle;
              m_pictureBoxBlackPawn.BorderStyle = BorderStyle.FixedSingle;

              m_editorPiece = (m_editorPiece == piece) ? Piece.None : piece;

              switch (m_editorPiece)
              {
            case Piece.WhiteKing:
              m_pictureBoxWhiteKing.BorderStyle = BorderStyle.Fixed3D;
              break;

            case Piece.WhiteQueen:
              m_pictureBoxWhiteQueen.BorderStyle = BorderStyle.Fixed3D;
              break;

            case Piece.WhiteRook:
              m_pictureBoxWhiteRook.BorderStyle = BorderStyle.Fixed3D;
              break;

            case Piece.WhiteBishop:
              m_pictureBoxWhiteBishop.BorderStyle = BorderStyle.Fixed3D;
              break;

            case Piece.WhiteKnight:
              m_pictureBoxWhiteKnight.BorderStyle = BorderStyle.Fixed3D;
              break;

            case Piece.WhitePawn:
              m_pictureBoxWhitePawn.BorderStyle = BorderStyle.Fixed3D;
              break;

            case Piece.BlackKing:
              m_pictureBoxBlackKing.BorderStyle = BorderStyle.Fixed3D;
              break;

            case Piece.BlackQueen:
              m_pictureBoxBlackQueen.BorderStyle = BorderStyle.Fixed3D;
              break;

            case Piece.BlackRook:
              m_pictureBoxBlackRook.BorderStyle = BorderStyle.Fixed3D;
              break;

            case Piece.BlackBishop:
              m_pictureBoxBlackBishop.BorderStyle = BorderStyle.Fixed3D;
              break;

            case Piece.BlackKnight:
              m_pictureBoxBlackKnight.BorderStyle = BorderStyle.Fixed3D;
              break;

            case Piece.BlackPawn:
              m_pictureBoxBlackPawn.BorderStyle = BorderStyle.Fixed3D;
              break;
              }
        }
예제 #13
0
 public abstract Image PieceImage(Piece piece);
예제 #14
0
        public void DrawPiece(Square square, Piece piece)
        {
            if (square != Square.None && piece != Piece.None)
              {
            Image image = PieceImage(piece);

            switch (m_viewFromBlack)
            {
              case true:
            m_picturePainter.DrawImage(image, ((7 - ChessFacade.File(square)) * SquareSize) + EdgeSize, (ChessFacade.Rank(square) * SquareSize) + EdgeSize, SquareSize, SquareSize);
            break;

              case false:
            m_picturePainter.DrawImage(image, (ChessFacade.File(square) * SquareSize) + EdgeSize, ((7 - ChessFacade.Rank(square)) * SquareSize) + EdgeSize, SquareSize, SquareSize);
            break;
            }
              }
        }