Пример #1
0
        public static void undo()
        {
            Piece last = board.at(lastMove.to);

            if (last.getType() == "pawn" && (lastMove.from.y == 1 && last.getColor() == "black" || lastMove.from.y == 6 && last.getColor() == "white"))
            {
                last.numberOfMoves = 0;
            }
            else
            {
                last.numberOfMoves--;
            }
            last.setPosition(lastMove.from);
            board.set(lastMove.from, last);
            board.set(lastMove.to, pieceRemoved);
        }
Пример #2
0
        private static void move(Position from, Position to, bool realMove)
        {
            lastMove = new ChessMove(from, to);
            Piece p1 = board.at(from);
            Piece p2 = board.at(to);

            pieceRemoved = p2;

            int xDiff = to.x - from.x;

            if (p1.getType() == "king" && Math.Abs(xDiff) > 1 && realMove)
            {
                int      xDir = xDiff < 0 ? -2 : 1;
                Position rook = new Position(to.x + xDir, to.y);
                xDir = xDiff < 0 ? 1 : -1;
                board.at(rook).debug();
                move(rook, new Position(to.x + xDir, to.y));
            }

            board.set(from, new Piece("blank", "none", from));

            p1.numberOfMoves++;
            if (p1.getType() == "pawn" && Math.Abs(to.y - from.y) == 2)
            {
                p1.numberOfMoves++;
            }

            p1.setPosition(to);

            if (p1.getType() == "pawn" && (to.y == 0 || to.y == 7))
            {
                p1 = new Piece("queen", p1.getColor(), p1.getPosition(), p1.getNumberOfMoves());
            }

            board.set(to, p1);
        }