PyChess
- 3 Devlogs
- 3 Total hours
A chess engine built in python
A chess engine built in python
Added actual pygame rendering, piece images on their tiles, and basic clicking events on tiles. I am currently having one issue with my pieces not being centered on their tiles hopefully an easy fix. But overall I’m making solid progress. It definitely gets hard to code every day while coming home from school tired every day but I will push through.
The picture below shows my progress with this so far. I’ve addded from last devlog to this one:
Did not do much for this devlog. I mainly did refactor work and cleaning up my code. But I discovered a new thing about python.
These are actually really cool and they add some additional functionality to your classes that you make. For example in my use I use the:
__str__()
dunder (double underscore) method which allows me to call print() on my class and print whatever I want to print for my class. Here is how I’m using it:
# inside of the board class
def __str__(self):
board_str = ""
for y in range(8):
for x in range(8):
piece = self.grid[x][y]
if piece:
board_str += f"{piece.type[0].upper() if piece.team == 'white' else piece.type[0].lower()} "
else:
board_str += ". "
board_str += "\n"
return board_str
# How you call it assuming you've already declared a board object called board.
print(board)
This allows for easier and cleaner code for debugging. This code snippet prints what is shown in the photo.
I got a little busy with school and my social life so I have not worked much on this project yet. Definitely a little step down from my grand project that I just finished. (You should check it out, it’s called Tetr.AI). But I want something a little more relaxed to work on. So I opted to make my own Chess engine built in python. And making this project could lead to some other future projects maybe a cool chess bot or an AI that learns to play chess.
|
So I just got finished with the basic board initialization and piece initialization. Nothing too much.