Skip to content
This repository has been archived by the owner on Jan 25, 2025. It is now read-only.

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.

@erkaii
Copy link

erkaii 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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants