Revert "wip"

This reverts commit 17587ad3d4228c120b8437ed0ff939e67289aa20.
This commit is contained in:
hagi 2022-12-23 19:45:44 +01:00
parent 2c06b5c327
commit d62184232c
9 changed files with 26 additions and 100 deletions

View file

@ -1,8 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View file

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View file

@ -1,6 +0,0 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

View file

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (blunderboard-py)" project-jdk-type="Python SDK" />
</project>

View file

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/blunderboard-py.iml" filepath="$PROJECT_DIR$/.idea/blunderboard-py.iml" />
</modules>
</component>
</project>

View file

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

View file

@ -2,9 +2,6 @@ from stockfish import Stockfish
from playsound import playsound
from pathlib import Path
import random
from pgn_parser import parser, pgn
# import RPi.GPIO as GPIO
settings = {
"Debug Log File": "",
@ -49,66 +46,39 @@ class Game:
A class representing the game state
"""
def __init__(self, engine_settings: dict):
self.engine = Stockfish("/usr/bin/stockfish")
self.settings = engine_settings
def __init__(self, settings: dict):
self.engine = Stockfish("/usr/local/bin/stockfish")
self.settings = settings
self.engine.update_engine_parameters(self.settings)
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()
self.evaluations = []
self.engine.set_position()
def move_was_blunder(self) -> bool:
"""
Returns true if the last move was a blunder
:return: bool
"""
if len(self.evaluations) > 1:
previous_evaluation = self.evaluations[-1]
return abs(self.current_evaluation["value"] - previous_evaluation["value"]) > 300
# TODO This is not a particularly good way to identify a blunder
else:
return False
def make_move(move) -> None:
"""
Makes a move on the board and updates the game state
:param move:
:return: None
"""
if self.engine.is_move_correct(move):
self.engine.make_moves_from_current_position([move])
self.current_evaluation = self.engine.get_evaluation()
self.evaluations.append(self.current_evaluation)
if move_was_blunder():
# If the played move was a blunder play a random sound from the sound path
playsound(random.choice(sound_path))
def make_move(self, move) -> None:
"""
Makes a move on the board and updates the game state
:param move:
:return: None
"""
if self.engine.is_move_correct(move):
self.engine.make_moves_from_current_position([move])
self.current_evaluation = self.engine.get_evaluation()
self.evaluations.append(self.current_evaluation)
if self.move_was_blunder():
# If the played move was a blunder play a random sound from the sound path
# playsound(random.choice(sound_path))
print("Blunder!")
def move_was_blunder() -> bool:
"""
Returns true if the last move was a blunder
:return: bool
"""
previous_evaluation = self.evaluations[-1]
return self.current_evaluation["value"] < (previous_evaluation["value"] + 3) # TODO This is not a
# particularly good way to identify a blunder
def __str__(self):
return ""
def get_moves_from_pgn(pgn_file: Path):
"""
Returns a list of moves from a PGN file
:param pgn_file: str
:return: list
"""
with open(pgn_file, "r") as f:
pgn_file = f.read()
return parser.parse(pgn_file, actions=pgn.Actions())
test_game = Game(settings)
pgn_path = Path("../spongeboyahoy_vs_tomlx.pgn")
moves = get_moves_from_pgn(pgn_path)
for i in range(1, 250):
print(str(moves.move(i)).split(". ")[1].split(" ")[0])
test_game.make_move(str(moves.move(i)).split(". ")[1].split(" ")[0])
print(test_game.current_evaluation)
test_game.make_move(str(moves.move(i)).split(". ")[1].split(" ")[1])
print(test_game.current_evaluation)

View file

@ -1,4 +1,2 @@
stockfish
playsound
pygobject
pgn_parser