Question

I'm working on creating a chess game in MIT Sceheme. I want to create a procedure that keeps track of the moves made by all the pieces.

Here is an example. I make the rook move up 5 spaces. My next turn I want it to move back 5 spaces. The problem is, I don't know how to keep track of the piece i moves forward in the preceding turn - therefore i don't know how to move it back. when I can do currently is take the entire state of the board. I assume i need to use some type of mutation?

Was it helpful?

Solution

Try keeping track of all previous moves in a list -- just cons on your most recent move (and symbol that tells you which piece performed the move) onto the move-log list and pass that along with your procedures. If for some reason you need to find a recent move, it will be simple to search the list a few steps backward, and this would give you some added functionality if you wanted to track games.

If you would like to share some of your code, I will edit this answer with more specific details on implementation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top