I’ve added a bot! The main point of this was to link the new file I made (bot.py) to main.py. The bot currently just chooses moves based off of what would result in the best material difference between white (player) and black (bot). It calculates these moves with a depth of 4. Since the main point wasn’t to actually make a bot in one go the bot isn’t very good currently. However I still added alpha beta pruning. Alpha beta pruning works by storing the best guaranteed outcome for you (alpha) and the best guaranteed outcome for the opponent (beta). Whenever it finds a path where the opponent can force a move that is worse than the alpha, it immediately stops going down that path. The same happens for beta. I also removed some duplicated code in main.py and fixed the undo and redo move logic as I forgot to check if it still worked properly after switching from tkinter to pygame. Currently you can only tap the buttons and but can’t hold to go back multiple moves. Undoing and redoing moves with a bot was a bit confusing for me and so I decided to make it so that when undoing and redoing there is 3 seconds before the bot moves. During these 3 seconds you can go forwards or backwards to reset the timer. I used threading so that the bot starts to calculate what move it would make at the same time as the 3 seconds are passing. This means that if you decide to stay on the turn you don’t need to wait as long. I also blurred the background of the the promotion GUI so that it is grabs the players attention. Next I am going to try and add a better bot by assigning each possible move a score that is based off of the squares it controls, offensive and defensive opportunities and potentials for forks (when 2 pieces are being attacked by 1 piece so only one piece can move out of danger).
Comments 4
the reason for the strange first move from the bot is because since the only thing the bot cares about right now is material difference and openings don’t have many captures, all the moves have an equal score. I have a variable bestScore which is used
if score >= bestScore:
bestScore = score
This means that since all of the paths have the same score it just always uses the last path. Moving the right most pawn forward twice is the last path that is checked and so this is always its opening. This will change when I determine score based off of other things as well as material difference.
Dang This is cool, You even have the planning attacks feature. maybe you can add like an elo slider maybe? or aggresive ness and defensive slider? Great Job
@Shreyansh thanks so much. An elo slider is a great idea! I could probably adjust my piece values and depth depending on where the slide is. Currently my piece values are
Pawn: 10
Bishop: 40
Knight: 45
Rook: 70
Queen: 130
King: 99999
looking good!!
Sign in to join the conversation.