// Restore cached current game situation (figure constellation, king positions,
//	castlings, active player and turn number):
public int undo()
	{
		if (turn == 1)
		{
			return 0;
		}
		// Restore game history (pop current moves frame and reset selected move):
		moves_frame = moves[moves_frame + 1];
		final var move = moves[moves_frame + 2];// TODO: fix when moves_selected contains index not move
		moves[moves_frame + 2] = 0;
		// Restore cached current game situation (figure constellation, king positions,
		//	castlings, active player and turn number):
		final var x = Move.x(move);
		final var y = Move.y(move);
		final var X = Move.X(move);
		final var Y = Move.Y(move);
		final var figure_moved = Move.figure_moved(move);
		final var figure_destination = Move.figure_destination(move);
		board[x][y] = figure_moved;
		board[X][Y] = figure_destination;
		if (figure_moved.is_king())
		{
			if (player)
			{
				king_x_b = x;
				king_y_b = y;
			}
			else
			{
				king_x_w = x;
				king_y_w = y;
			}
			if (X == x - 2)
			{ // Castling left:
				board[0][Y] = board[3][Y];
				board[3][Y] = null;
				if (figure_moved.owner)
				{
					castling_done_w = false;
				}
				else
				{
					castling_done_b = false;
				}
			}
			else if (X == x + 2)
			{ // Castling right:
				board[7][Y] = board[5][Y];
				board[5][Y] = null;
				if (figure_moved.owner)
				{
					castling_done_w = false;
				}
				else
				{
					castling_done_b = false;
				}
			}
		}
		else if (figure_moved.is_pawn() && X != x && figure_destination == null)
		{ // Undo en passant capture:
			board[X][y] = Figure.pawn(!figure_moved.owner);
		}
		castlings_allowed ^= Move.castling_changes(move);
		player = !player;
		turn--;
		return move;
	}
final var move = moves[moves_frame + 2];// TODO: fix when moves_selected contains index not move
moves[moves_frame + 2] = 0;
// Restore cached current game situation (figure constellation, king positions,
// castlings, active player and turn number):
final var x = Move.x(move);
final var y = Move.y(move);
public int undo()
{
if (turn == 1)
{
return 0;
}
// Restore game history (pop current moves frame and reset selected move):
moves_frame = moves[moves_frame + 1];
final var move = moves[moves_frame + 2];// TODO: fix when moves_selected contains index not move
moves[moves_frame + 2] = 0;
// Restore cached current game situation (figure constellation, king positions,
// castlings, active player and turn number):
final var x = Move.x(move);
final var y = Move.y(move);
final var X = Move.X(move);
final var Y = Move.Y(move);
final var figure_moved = Move.figure_moved(move);
final var figure_destination = Move.figure_destination(move);
board[x][y] = figure_moved;
board[X][Y] = figure_destination;
if (figure_moved.is_king())
{
public int undo()
{
if (turn == 1)
{
return 0;
}
// Restore game history (pop current moves frame and reset selected move):
moves_frame = moves[moves_frame + 1];
final var move = moves[moves_frame + 2];// TODO: fix when moves_selected contains index not move
moves[moves_frame + 2] = 0;
// Restore cached current game situation (figure constellation, king positions,
// castlings, active player and turn number):
final var x = Move.x(move);
final var y = Move.y(move);
final var X = Move.X(move);
final var Y = Move.Y(move);
final var figure_moved = Move.figure_moved(move);
final var figure_destination = Move.figure_destination(move);
board[x][y] = figure_moved;
board[X][Y] = figure_destination;
if (figure_moved.is_king())
{
if (player)
{
king_x_b = x;
king_y_b = y;
}
else
{
king_x_w = x;
king_y_w = y;
}