Week 9 – Python Chess

Hour 1 – Square Labels

When I decided to redraw the board with each move so that the current player’s pieces would be at the bottom of the window, it necessitated fixing the labels.  At first I just drew the labels at the beginning of the game when I drew the board and forgot about them.  The first idea was to put the labels in a list and move them each turn, but that was actually more complicated and problematic than necessary.  The solution was to create two lists for the labels, then undraw the old labels and draw the correct labels with each turn.  The labels, being objects in a list, are retained and can be turned on and off as needed.

Hour 2 – OOP House Keeping

So what Laurie was saying about the configuation of the Game is starting to click.  Instead of just letting pieces exist within the game matrix, they need to belong to their player.  So instead of individually placing pieces, I append each piece to the players pieces list, then iterate through the list to place the pieces.  The code is cleaner and makes more sense that way.  In turn the players need to belong to the game.  So instead of doing wierd purmutations with variables at the beginning of each turn, I just reverse the games player list so that the current player is player[0].

Now that I have the turns configured like this making sure that a pawn can only be captured enpassant for the first move after the double jump is simple.  Just iterate through the current players pawns at the start of the turn and turn off the EP flag.

Hour 3 – Revamping Legal

So this is the fun part of programming ( insert heavy sarcasm ). I spent about 30 minutes rewriting the obstructed function so that it would be streamlined, and callable from outside of the Legal module.  Then I spent two hours bashing my head against the desk because now ghost pieces are showing up.  Sometimes the new obstructed function is returning a None type which it shouldn’t be doing.  This causes captured pieces to stay in the matrix, and sometimes pieces don’t recognize that they are on the same side.  Oh well, I’ll sort this out later.

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*