From 7c8b703cbc02456ea39043b7df6cd8b9539c05b2 Mon Sep 17 00:00:00 2001 From: Thomas Lindner Date: Wed, 28 Dec 2022 15:50:26 +0100 Subject: [PATCH] cleanup --- .gitignore | 18 ---- blunderboard-py/.idea/workspace.xml | 69 -------------- blunderboard-py/requirements.txt | 17 ---- blunderboard.go | 91 ------------------- go.mod | 3 - go.sum | 3 - pyproject.toml | 6 ++ pyvenv.cfg | 3 - setup.cfg | 58 ++++++++++++ src/blunderboard/__init__.py | 2 + .../blunderboard}/blunderboard.py | 73 +++++++++++---- 11 files changed, 119 insertions(+), 224 deletions(-) delete mode 100644 .gitignore delete mode 100644 blunderboard-py/.idea/workspace.xml delete mode 100644 blunderboard-py/requirements.txt delete mode 100644 blunderboard.go delete mode 100644 go.mod delete mode 100644 go.sum create mode 100644 pyproject.toml delete mode 100644 pyvenv.cfg create mode 100644 setup.cfg create mode 100644 src/blunderboard/__init__.py rename {blunderboard-py => src/blunderboard}/blunderboard.py (75%) diff --git a/.gitignore b/.gitignore deleted file mode 100644 index d3f3408..0000000 --- a/.gitignore +++ /dev/null @@ -1,18 +0,0 @@ -.*.swp - -# Binaries for programs and plugins -*.exe -*.exe~ -*.dll -*.so -*.dylib -blunderboard - -# Test binary, built with `go test -c` -*.test - -# Output of the go coverage tool, specifically when used with LiteIDE -*.out - -# Dependency directories (remove the comment below to include it) -# vendor/ diff --git a/blunderboard-py/.idea/workspace.xml b/blunderboard-py/.idea/workspace.xml deleted file mode 100644 index bc54ea6..0000000 --- a/blunderboard-py/.idea/workspace.xml +++ /dev/null @@ -1,69 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - 1671724416846 - - - - - - - - - - - - - - \ No newline at end of file diff --git a/blunderboard-py/requirements.txt b/blunderboard-py/requirements.txt deleted file mode 100644 index be4684f..0000000 --- a/blunderboard-py/requirements.txt +++ /dev/null @@ -1,17 +0,0 @@ -stockfish -<<<<<<< Updated upstream -playsound -======= -<<<<<<< Updated upstream -playsound -pygobject -pgn_parser -======= -<<<<<<< Updated upstream -playsound -======= -pygame -pgn_parser ->>>>>>> Stashed changes ->>>>>>> Stashed changes ->>>>>>> Stashed changes diff --git a/blunderboard.go b/blunderboard.go deleted file mode 100644 index 77ace0a..0000000 --- a/blunderboard.go +++ /dev/null @@ -1,91 +0,0 @@ -package main - -import ( - "fmt" - "github.com/notnil/chess" - "github.com/notnil/chess/uci" - "math" - "os" -) - -// stolen^H^H inspired from lichess https://github.com/ornicar/lila/blob/master/modules/analyse/src/main/Advice.scala#L79 -func WinningChance(cp int) float64 { - winning_chance := 2 / (1 + math.Exp(-0.004 * float64(cp))) - 1 - return winning_chance -} - -func main() { - reader, err := os.Open("spongeboyahoy_vs_tomlx.pgn") - if err != nil { - panic(err) - } - pgn, err := chess.PGN(reader) - if err != nil { - panic(err) - } - spongeboyahoy_vs_tomlx := chess.NewGame(pgn) - fmt.Println(spongeboyahoy_vs_tomlx) - - engine, err := uci.New("stockfish") - if err != nil { - panic(err) - } - defer engine.Close() - - if err := engine.Run(uci.CmdUCI, uci.CmdIsReady, uci.CmdUCINewGame); err != nil { - panic(err) - } - - game := chess.NewGame() -// prevprev_winning_chance := 0.0 - prev_winning_chance := 0.0 - for game.Outcome() == chess.NoOutcome { - num_of_moves := len(game.Moves()) - if err := engine.Run(uci.CmdPosition{Position: game.Position()}, uci.CmdGo{Depth: 12}); err != nil { - panic(err) - } - search_results := engine.SearchResults() - cp := search_results.Info.Score.CP - if (num_of_moves % 2 == 1) { - cp *= -1 - } - winning_chance := WinningChance(cp) - if (num_of_moves > 0) { - delta := prev_winning_chance - winning_chance - if (num_of_moves % 2 == 0) { - delta *= -1; - } - if delta > 0.3 { - fmt.Print("B-b-b-blunder!!") - } else if delta > 0.2 { - fmt.Print("That was a mistake.") - } else if delta > 0.1 { - fmt.Print("Meh...") - } else { - fmt.Print("Ok") - } - fmt.Printf(" (%0.2f, %0.2f, %0.2f)\n", float64(cp) / 100, winning_chance, -delta) - } -// prevprev_winning_chance = prev_winning_chance - prev_winning_chance = winning_chance -// fmt.Println(game.Position().Board().Draw()) -// fmt.Println("Score (centipawns):", cp, "Winning chance:", winning_chance, "Best Move: ", search_results.BestMove) -// fmt.Println("Move: ", search_results.BestMove) - move := spongeboyahoy_vs_tomlx.Moves()[num_of_moves] - fmt.Print(num_of_moves / 2 + 1, move, "\t") - if err := game.Move(move); err != nil { - panic(err) - } -// for { -// var move string -// fmt.Print("Move: ") -// fmt.Scanln(&move) -// if err := game.MoveStr(move); err == nil { -// break -// } -// fmt.Println("Illegal move!") -// } - } - fmt.Println(game.Outcome()) - fmt.Println(game.Position().Board().Draw()) -} diff --git a/go.mod b/go.mod deleted file mode 100644 index fb4d781..0000000 --- a/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module git.0x90.space/0x90/blunderboard - -require github.com/notnil/chess v1.5.0 diff --git a/go.sum b/go.sum deleted file mode 100644 index 3256ec6..0000000 --- a/go.sum +++ /dev/null @@ -1,3 +0,0 @@ -github.com/ajstarks/svgo v0.0.0-20200320125537-f189e35d30ca/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw= -github.com/notnil/chess v1.5.0 h1:BcdmSGqZYhoqHsAqNpVTtPwRMOA4Sj8iZY1ZuPW4Umg= -github.com/notnil/chess v1.5.0/go.mod h1:cRuJUIBFq9Xki05TWHJxHYkC+fFpq45IWwk94DdlCrA= diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..374b58c --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,6 @@ +[build-system] +requires = [ + "setuptools>=42", + "wheel" +] +build-backend = "setuptools.build_meta" diff --git a/pyvenv.cfg b/pyvenv.cfg deleted file mode 100644 index 8810f2d..0000000 --- a/pyvenv.cfg +++ /dev/null @@ -1,3 +0,0 @@ -home = /usr/bin -include-system-site-packages = false -version = 3.10.8 diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..340c9f4 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,58 @@ +[metadata] +name = blunderboard +version = 0.0.1 +author = 0x90.space +author_email = people@schleuder.0x90.space +description = Blunderboard +url = https://git.0x90.space/0x90/blunderboard +project_urls = + Bug Tracker = https://git.0x90.space/0x90/blunderboard/issues +classifiers = + Programming Language :: Python :: 3 :: Only + License :: OSI Approved :: ISC License (ISCL) + Operating System :: POSIX :: Linux + Topic :: Games/Entertainment :: Board Games + +[options] +package_dir = + = src +packages = find: +python_requires = >=3.9 +install_requires = + pygame + RPi.GPIO + stockfish + +[options.packages.find] +where = src + +[options.entry_points] +console_scripts = + blunderboard = blunderboard:main + +[tox:tox] +envlist = lint +isolated_build = True + +[testenv:lint] +skip_install = True +deps = + black + flake8 + mypy +commands = + black --check --diff src + flake8 src + mypy src + +#[testenv] +#deps = +# pytest +#commands = +# pytest tests + +[flake8] +max_line_length = 88 + +[mypy] +ignore_missing_imports = True diff --git a/src/blunderboard/__init__.py b/src/blunderboard/__init__.py new file mode 100644 index 0000000..336e825 --- /dev/null +++ b/src/blunderboard/__init__.py @@ -0,0 +1,2 @@ +def main(): + pass diff --git a/blunderboard-py/blunderboard.py b/src/blunderboard/blunderboard.py similarity index 75% rename from blunderboard-py/blunderboard.py rename to src/blunderboard/blunderboard.py index b232565..07aaca7 100644 --- a/blunderboard-py/blunderboard.py +++ b/src/blunderboard/blunderboard.py @@ -1,22 +1,22 @@ -from stockfish import Stockfish -from pygame import mixer -import time -from pathlib import Path -import random import os -#import RPi.GPIO as GPIO +from pathlib import Path +from pygame import mixer +import random +from stockfish import Stockfish +import time settings = { "Debug Log File": "", "Contempt": 0, "Min Split Depth": 0, - "Threads": 10, - # More threads will make the engine stronger, but should be kept at less than the number of logical processors on - # your computer. + "Threads": 1, + # More threads will make the engine stronger, but should be kept at less than the + # number of logical processors on your computer. "Ponder": "false", - "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., - # if you're fine using 2 GB of RAM, set Hash to 2048 (11th power of 2). + "Hash": 16, + # 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). "MultiPV": 1, "Skill Level": 20, "Move Overhead": 10, @@ -67,10 +67,12 @@ class Game: self.settings = engine_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.evaluations = [] + self.current_evaluation = ( + self.engine.get_evaluation() + ) # This is not necessary, now that I think about it. + self.evaluations: list[dict] = [] self.current_wdl = self.engine.get_wdl_stats() - self.wdls = [] + self.wdls: list[tuple[int, int, int]] = [] self.engine.set_position() def move_was_blunder(self) -> bool: @@ -86,6 +88,7 @@ class Game: return True else: return False + return False def make_move(self, move) -> None: """ @@ -102,8 +105,9 @@ class Game: print(self.current_wdl) print(self.current_evaluation) if self.move_was_blunder(): - # If the played move was a blunder play a random sound from the sound path - #play_sound() + # If the played move was a blunder play a random sound from the sound + # path + # play_sound() print("Blunder!") else: print("Invalid move") @@ -114,9 +118,38 @@ class Game: test_game = Game(settings) -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"] +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)