Finally, promotions! This was the last major part of chess that I didn’t have. I added it by finding the row of the piece when I move something. I hardcoded it so that it knows when the pawn is at the last row. When at the last row, it runs a choosePromotion() function. That function then creates a frame inside of my window. I then loop for each of the choices of the pieces I can choose. For each of these pieces I create a button with the piece (in the correct colour) in the centre. The frame waits until I pick a choice before adding a 1 on that piece’s bitboard at the correct location and removes the 1 on the pawn bitboard. Thats all I need to do to register a promotion! The rest of the time I spent optimising my code and realising that I didn’t have to use just a bitboard or an array, I could use both. Knowing that, I removed my getPiece() function and instead used an array to find the piece at a row and column. This is more efficient as arrays have a lookup time of O(1) whereas the getPiece() function has a lookup time of O(n) in the worst case. This is because my getPiece() function worked by cycling through each bitboard to find what piece was at a certain coordinate. This meant that I could also remove my totalPieces bitboard since this was only used in the getPiece() function to avoid cycling through all 12 bitboards if there was nothing there. Overall I’m really happy with how everything is going as I have all I really need for a proper game of 2 player chess. Next I am going to try and add the small things I am still missing such as En passant and the 50 move rule.
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.