blunder.changes

This commit is contained in:
hagi 2022-12-27 19:16:17 +01:00
parent 5d61d69c1a
commit db38497dea

View file

@ -4,17 +4,17 @@ import time
from pathlib import Path from pathlib import Path
import random import random
import os import os
import RPi.GPIO as GPIO #import RPi.GPIO as GPIO
settings = { settings = {
"Debug Log File": "", "Debug Log File": "",
"Contempt": 0, "Contempt": 0,
"Min Split Depth": 0, "Min Split Depth": 0,
"Threads": 1, "Threads": 10,
# More threads will make the engine stronger, but should be kept at less than the number of logical processors on # More threads will make the engine stronger, but should be kept at less than the number of logical processors on
# your computer. # your computer.
"Ponder": "false", "Ponder": "false",
"Hash": 16, "Hash": 8100,
# Default size is 16 MB. It's recommended that you increase this value, but keep it as some power of 2. E.g., # Default size is 16 MB. It's recommended that you increase this value, but keep it as some power of 2. E.g.,
# if you're fine using 2 GB of RAM, set Hash to 2048 (11th power of 2). # if you're fine using 2 GB of RAM, set Hash to 2048 (11th power of 2).
"MultiPV": 1, "MultiPV": 1,
@ -24,7 +24,8 @@ settings = {
"Slow Mover": 100, "Slow Mover": 100,
"UCI_Chess960": "false", "UCI_Chess960": "false",
"UCI_LimitStrength": "false", "UCI_LimitStrength": "false",
"UCI_Elo": 1350 "UCI_Elo": 1350,
"NNUE": "true",
} }
sound_path = Path("sounds") sound_path = Path("sounds")
@ -68,6 +69,8 @@ class Game:
self.matrix = BoardReader() self.matrix = BoardReader()
self.current_evaluation = self.engine.get_evaluation() # This is not necessary, now that I think about it. self.current_evaluation = self.engine.get_evaluation() # This is not necessary, now that I think about it.
self.evaluations = [] self.evaluations = []
self.current_wdl = self.engine.get_wdl_stats()
self.wdls = []
self.engine.set_position() self.engine.set_position()
def move_was_blunder(self) -> bool: def move_was_blunder(self) -> bool:
@ -75,10 +78,12 @@ class Game:
Returns true if the last move was a blunder Returns true if the last move was a blunder
:return: bool :return: bool
""" """
if len(self.evaluations) > 1: # Don't check for blunders on the first move if len(self.wdls) > 1: # Don't check for blunders on the first move
previous_evaluation = self.evaluations[len(self.evaluations) - 2] previous_wdl = self.wdls[len(self.evaluations) - 2]
return abs(self.current_evaluation["value"] - previous_evaluation["value"]) > 100 if abs(previous_wdl[0] - self.current_wdl[0]) > 300:
# TODO This is not a particularly good way to identify a blunder return True
elif abs(previous_wdl[2] - self.current_wdl[2]) > 300:
return True
else: else:
return False return False
@ -92,10 +97,13 @@ class Game:
self.engine.make_moves_from_current_position([move]) self.engine.make_moves_from_current_position([move])
self.current_evaluation = self.engine.get_evaluation() self.current_evaluation = self.engine.get_evaluation()
self.evaluations.append(self.current_evaluation) self.evaluations.append(self.current_evaluation)
print(test_game.current_evaluation) self.current_wdl = self.engine.get_wdl_stats()
self.wdls.append(self.current_wdl)
print(self.current_wdl)
print(self.current_evaluation)
if self.move_was_blunder(): if self.move_was_blunder():
# If the played move was a blunder play a random sound from the sound path # If the played move was a blunder play a random sound from the sound path
play_sound() #play_sound()
print("Blunder!") print("Blunder!")
else: else:
print("Invalid move") print("Invalid move")