Compare commits

...

2 Commits

Author SHA1 Message Date
hagi 5d61d69c1a wip 2022-12-23 21:49:58 +01:00
hagi d62184232c Revert "wip"
This reverts commit 17587ad3d4228c120b8437ed0ff939e67289aa20.
2022-12-23 21:47:20 +01:00
10 changed files with 117 additions and 77 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

@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="3e262a23-1a63-4818-97cf-591091cd1e52" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/blunderboard.py" beforeDir="false" afterPath="$PROJECT_DIR$/blunderboard.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/requirements.txt" beforeDir="false" afterPath="$PROJECT_DIR$/requirements.txt" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
<component name="ProjectId" id="2JHA16UVCORl9oGXtkokQL85N3r" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"WebServerToolWindowFactoryState": "false",
"last_opened_file_path": "/home/hagenest/Repos/blunderboard/blunderboard-py",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"vue.rearranger.settings.migration": "true"
}
}]]></component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="3e262a23-1a63-4818-97cf-591091cd1e52" name="Changes" comment="" />
<created>1671724416846</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1671724416846</updated>
<workItem from="1671724417946" duration="16204000" />
</task>
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
<component name="UnknownFeatures">
<option featureType="com.intellij.fileTypeFactory" implementationName="requirements.txt" />
</component>
<component name="Vcs.Log.Tabs.Properties">
<option name="TAB_STATES">
<map>
<entry key="MAIN">
<value>
<State />
</value>
</entry>
</map>
</option>
</component>
<component name="com.intellij.coverage.CoverageDataManagerImpl">
<SUITE FILE_PATH="coverage/blunderboard_py$blunderboard.coverage" NAME="blunderboard Coverage Results" MODIFIED="1671828227830" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
</component>
</project>

View File

@ -1,10 +1,10 @@
from stockfish import Stockfish
from playsound import playsound
from pygame import mixer
import time
from pathlib import Path
import random
from pgn_parser import parser, pgn
# import RPi.GPIO as GPIO
import os
import RPi.GPIO as GPIO
settings = {
"Debug Log File": "",
@ -27,7 +27,7 @@ settings = {
"UCI_Elo": 1350
}
sound_path = [Path("sounds/")]
sound_path = Path("sounds")
class BoardReader:
@ -44,6 +44,18 @@ class BoardReader:
return ""
def play_sound() -> None:
"""
Plays a random sound from the sound path
:return: None
"""
mixer.init()
mixer.music.load("sounds/" + random.choice(os.listdir(sound_path)))
mixer.music.play()
while mixer.music.get_busy():
time.sleep(0.1)
class Game:
"""
A class representing the game state
@ -63,9 +75,9 @@ class Game:
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
if len(self.evaluations) > 1: # Don't check for blunders on the first move
previous_evaluation = self.evaluations[len(self.evaluations) - 2]
return abs(self.current_evaluation["value"] - previous_evaluation["value"]) > 100
# TODO This is not a particularly good way to identify a blunder
else:
return False
@ -73,42 +85,30 @@ class Game:
def make_move(self, move) -> None:
"""
Makes a move on the board and updates the game state
:param move:
:param move: str
: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!")
print(test_game.current_evaluation)
if self.move_was_blunder():
# If the played move was a blunder play a random sound from the sound path
play_sound()
print("Blunder!")
else:
print("Invalid move")
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)
moves_manual = ["e2e4", "e7e6", "e4e5", "d7d5", "e5d6", "c7d6", "b1c3", "b8c6", "f1b5", "a7a6", "b5a4", "b7b5", "a4b3",
"d6d5", "a2a4", "c8b7", "a4b5", "a6b5", "a1a8", "d8a8", "c3b5", "a8a5", "c2c4", "b7a6", "b5c3", "a6c4",
"b3c4", "d5c4", "d1g4", "a5a1"]
for move in moves_manual:
print(move)
test_game.make_move(move)

View File

@ -1,4 +1,17 @@
stockfish
<<<<<<< Updated upstream
playsound
=======
<<<<<<< Updated upstream
playsound
pygobject
pgn_parser
pgn_parser
=======
<<<<<<< Updated upstream
playsound
=======
pygame
pgn_parser
>>>>>>> Stashed changes
>>>>>>> Stashed changes
>>>>>>> Stashed changes