Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement undo method to revert last move in game #143

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

amjadjibon
Copy link

Issue #142

  • Revert Last Move: Reverts the most recent move in the game.
  • Restore Previous State: Updates the position history to reflect the game state before the last move.
  • Return Undone Move: Returns the last move that was undone.
  • Error Handling: Provides an error if there are no moves to undo.

@silkrow
Copy link

silkrow commented Sep 3, 2024

Consider the following test case, it fails since the method and outcome of the game are not changed by the updatePosition function properly. I've added some changes to settle this issue. Please check this PR.

        g = NewGame()
	moves = []string{
		"f4", "e6", "g4", "Qh4",
	}

	for _, m := range moves {
		if err = g.MoveStr(m); err != nil {
			t.Fatal(err)
		}
	}

	lastMove, err = g.Undo()
	if err != nil {
		t.Fatal(err)
	}

	if err = g.MoveStr("h6"); err != nil {
		t.Fatal(err)
	}
	if g.Outcome() != NoOutcome {
		t.Fatal("unexpected game outcome")
	}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants