Revert "wip"
This reverts commit 17587ad3d4228c120b8437ed0ff939e67289aa20.
This commit is contained in:
parent
2c06b5c327
commit
d62184232c
8
blunderboard-py/.idea/.gitignore
vendored
8
blunderboard-py/.idea/.gitignore
vendored
|
@ -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
|
|
|
@ -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>
|
|
|
@ -1,6 +0,0 @@
|
||||||
<component name="InspectionProjectProfileManager">
|
|
||||||
<settings>
|
|
||||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
|
||||||
<version value="1.0" />
|
|
||||||
</settings>
|
|
||||||
</component>
|
|
|
@ -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>
|
|
|
@ -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>
|
|
|
@ -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>
|
|
|
@ -2,9 +2,6 @@ from stockfish import Stockfish
|
||||||
from playsound import playsound
|
from playsound import playsound
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import random
|
import random
|
||||||
from pgn_parser import parser, pgn
|
|
||||||
|
|
||||||
# import RPi.GPIO as GPIO
|
|
||||||
|
|
||||||
settings = {
|
settings = {
|
||||||
"Debug Log File": "",
|
"Debug Log File": "",
|
||||||
|
@ -49,66 +46,39 @@ class Game:
|
||||||
A class representing the game state
|
A class representing the game state
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, engine_settings: dict):
|
def __init__(self, settings: dict):
|
||||||
self.engine = Stockfish("/usr/bin/stockfish")
|
self.engine = Stockfish("/usr/local/bin/stockfish")
|
||||||
self.settings = engine_settings
|
self.settings = settings
|
||||||
self.engine.update_engine_parameters(self.settings)
|
self.engine.update_engine_parameters(self.settings)
|
||||||
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()
|
||||||
self.evaluations = []
|
self.evaluations = []
|
||||||
self.engine.set_position()
|
self.engine.set_position()
|
||||||
|
|
||||||
def move_was_blunder(self) -> bool:
|
def make_move(move) -> None:
|
||||||
"""
|
"""
|
||||||
Returns true if the last move was a blunder
|
Makes a move on the board and updates the game state
|
||||||
:return: bool
|
:param move:
|
||||||
"""
|
:return: None
|
||||||
if len(self.evaluations) > 1:
|
"""
|
||||||
previous_evaluation = self.evaluations[-1]
|
if self.engine.is_move_correct(move):
|
||||||
return abs(self.current_evaluation["value"] - previous_evaluation["value"]) > 300
|
self.engine.make_moves_from_current_position([move])
|
||||||
# TODO This is not a particularly good way to identify a blunder
|
self.current_evaluation = self.engine.get_evaluation()
|
||||||
else:
|
self.evaluations.append(self.current_evaluation)
|
||||||
return False
|
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:
|
def move_was_blunder() -> bool:
|
||||||
"""
|
"""
|
||||||
Makes a move on the board and updates the game state
|
Returns true if the last move was a blunder
|
||||||
:param move:
|
:return: bool
|
||||||
:return: None
|
"""
|
||||||
"""
|
previous_evaluation = self.evaluations[-1]
|
||||||
if self.engine.is_move_correct(move):
|
return self.current_evaluation["value"] < (previous_evaluation["value"] + 3) # TODO This is not a
|
||||||
self.engine.make_moves_from_current_position([move])
|
# particularly good way to identify a blunder
|
||||||
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 __str__(self):
|
def __str__(self):
|
||||||
return ""
|
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)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,2 @@
|
||||||
stockfish
|
stockfish
|
||||||
playsound
|
playsound
|
||||||
pygobject
|
|
||||||
pgn_parser
|
|
Binary file not shown.
Loading…
Reference in a new issue