public void Undo() { if (history.Count > 0) { ChessHistory newState = history.Pop(); state = newState.state; movesWithoutKill = newState.movesWithoutKill; gameOver = false; ChangeTeam(); } }
public void MakeMove(Vector2Int start, Vector2Int end) { Piece startPiece = GetPiece(start); Piece[, ] oldState = CloneState(state); ChessHistory newHistory = new ChessHistory(); newHistory.state = oldState; newHistory.movesWithoutKill = 0; history.Push(newHistory); Piece destinationPiece = GetPiece(end); if (destinationPiece != null) { Kill(destinationPiece); } else { movesWithoutKill++; } SetPiece(startPiece, end); SetPiece(null, start); // pawn promotion if (startPiece is Pawn) { if (end.y == 0 || end.y == 7) { SetPiece(new Queen(startPiece.chess, startPiece.team), end); } } if (movesWithoutKill >= 50) { GameOver(); return; } ChangeTeam(); }