From b23d50d74a70284e85e2f850bc9ccbfdec1d2280 Mon Sep 17 00:00:00 2001 From: "LAPTOP-G43MA5MO\\ekarni" Date: Fri, 4 Oct 2024 23:42:51 +0300 Subject: [PATCH] make it project --- pyproject.toml | 30 ++++++ .../.github}/workflows/python-app.yml | 0 .gitignore => src/.gitignore | 0 LICENSE.md => src/LICENSE.md | 0 README.md => src/README.md | 0 src/__init__.py | 3 + {build => src/build}/clean.sh | 0 {build => src/build}/pack.sh | 0 {build => src/build}/pack_nnue.sh | 0 {docs => src/docs}/logo/sunfish_large.png | Bin {docs => src/docs}/logo/sunfish_small.bmp | Bin {docs => src/docs}/sunfish.6 | 0 {nnue => src/nnue}/models/color.pickle | Bin {nnue => src/nnue}/models/color2.pickle | Bin {nnue => src/nnue}/models/color2_v2.pickle | Bin {nnue => src/nnue}/models/color2_v3.pickle | Bin {nnue => src/nnue}/models/model.pickle | Bin {nnue => src/nnue}/models/model_19.pickle | Bin {nnue => src/nnue}/models/model_39.pickle | Bin {nnue => src/nnue}/models/model_59.pickle | Bin {nnue => src/nnue}/models/model_79.pickle | Bin {nnue => src/nnue}/models/model_99.pickle | Bin {nnue => src/nnue}/models/nnue1.pickle | Bin {nnue => src/nnue}/models/tanh.pickle | Bin {nnue => src/nnue}/models/tanh2.pickle | Bin {nnue => src/nnue}/models/tanh_139.pickle | Bin {nnue => src/nnue}/models/tanh_199.pickle | Bin {nnue => src/nnue}/models/tanh_79.pickle | Bin {nnue => src/nnue}/nnue_bug_fens | 0 {nnue => src/nnue}/speed_tests.py | 0 {nnue => src/nnue}/sunfish2.py | 0 {nnue => src/nnue}/sunfish_king.py | 0 requirements.txt => src/requirements.txt | 0 sunfish.py => src/sunfish.py | 91 +++++++++--------- sunfish_nnue.py => src/sunfish_nnue.py | 0 {tools => src/tools}/clean_draws.py | 0 {tools => src/tools}/fancy.py | 0 {tools => src/tools}/quick_tests.sh | 0 {tools => src/tools}/test.sh | 0 {tools => src/tools}/test_files/3fold.epd | 0 {tools => src/tools}/test_files/3fold.pgn | 0 {tools => src/tools}/test_files/3fold_do.pgn | 0 .../tools}/test_files/3fold_dont.pgn | 0 .../tools}/test_files/avoid_mate.epd | 0 .../tools}/test_files/bratko_kopec_test.epd | 0 .../tools}/test_files/ccr_one_hour_test.epd | 0 .../test_files/chessathome_openings.fen | 0 .../tools}/test_files/gaviota-starters.pgn | 0 {tools => src/tools}/test_files/mate1.fen | 0 {tools => src/tools}/test_files/mate2.fen | 0 {tools => src/tools}/test_files/mate3.fen | 0 {tools => src/tools}/test_files/mate4.fen | 0 .../tools}/test_files/nullmove_mates.fen | 0 {tools => src/tools}/test_files/perft.epd | 0 {tools => src/tools}/test_files/pgns.pgn | 0 {tools => src/tools}/test_files/queen.fen | 0 .../tools}/test_files/stalemate0.fen | 0 .../tools}/test_files/stalemate1.fen | 0 .../tools}/test_files/stalemate2.fen | 0 {tools => src/tools}/test_files/unstable1 | 0 .../tools}/test_files/unstable_positions | 0 .../tools}/test_files/unstable_positions2 | 0 .../tools}/test_files/win_at_chess_test.epd | 0 {tools => src/tools}/tester.py | 0 {tools => src/tools}/uci.py | 0 65 files changed, 80 insertions(+), 44 deletions(-) create mode 100644 pyproject.toml rename {.github => src/.github}/workflows/python-app.yml (100%) rename .gitignore => src/.gitignore (100%) rename LICENSE.md => src/LICENSE.md (100%) rename README.md => src/README.md (100%) create mode 100644 src/__init__.py rename {build => src/build}/clean.sh (100%) rename {build => src/build}/pack.sh (100%) rename {build => src/build}/pack_nnue.sh (100%) rename {docs => src/docs}/logo/sunfish_large.png (100%) rename {docs => src/docs}/logo/sunfish_small.bmp (100%) rename {docs => src/docs}/sunfish.6 (100%) rename {nnue => src/nnue}/models/color.pickle (100%) rename {nnue => src/nnue}/models/color2.pickle (100%) rename {nnue => src/nnue}/models/color2_v2.pickle (100%) rename {nnue => src/nnue}/models/color2_v3.pickle (100%) rename {nnue => src/nnue}/models/model.pickle (100%) rename {nnue => src/nnue}/models/model_19.pickle (100%) rename {nnue => src/nnue}/models/model_39.pickle (100%) rename {nnue => src/nnue}/models/model_59.pickle (100%) rename {nnue => src/nnue}/models/model_79.pickle (100%) rename {nnue => src/nnue}/models/model_99.pickle (100%) rename {nnue => src/nnue}/models/nnue1.pickle (100%) rename {nnue => src/nnue}/models/tanh.pickle (100%) rename {nnue => src/nnue}/models/tanh2.pickle (100%) rename {nnue => src/nnue}/models/tanh_139.pickle (100%) rename {nnue => src/nnue}/models/tanh_199.pickle (100%) rename {nnue => src/nnue}/models/tanh_79.pickle (100%) rename {nnue => src/nnue}/nnue_bug_fens (100%) rename {nnue => src/nnue}/speed_tests.py (100%) rename {nnue => src/nnue}/sunfish2.py (100%) rename {nnue => src/nnue}/sunfish_king.py (100%) rename requirements.txt => src/requirements.txt (100%) rename sunfish.py => src/sunfish.py (92%) rename sunfish_nnue.py => src/sunfish_nnue.py (100%) rename {tools => src/tools}/clean_draws.py (100%) rename {tools => src/tools}/fancy.py (100%) rename {tools => src/tools}/quick_tests.sh (100%) rename {tools => src/tools}/test.sh (100%) rename {tools => src/tools}/test_files/3fold.epd (100%) rename {tools => src/tools}/test_files/3fold.pgn (100%) rename {tools => src/tools}/test_files/3fold_do.pgn (100%) rename {tools => src/tools}/test_files/3fold_dont.pgn (100%) rename {tools => src/tools}/test_files/avoid_mate.epd (100%) rename {tools => src/tools}/test_files/bratko_kopec_test.epd (100%) rename {tools => src/tools}/test_files/ccr_one_hour_test.epd (100%) rename {tools => src/tools}/test_files/chessathome_openings.fen (100%) rename {tools => src/tools}/test_files/gaviota-starters.pgn (100%) rename {tools => src/tools}/test_files/mate1.fen (100%) rename {tools => src/tools}/test_files/mate2.fen (100%) rename {tools => src/tools}/test_files/mate3.fen (100%) rename {tools => src/tools}/test_files/mate4.fen (100%) rename {tools => src/tools}/test_files/nullmove_mates.fen (100%) rename {tools => src/tools}/test_files/perft.epd (100%) rename {tools => src/tools}/test_files/pgns.pgn (100%) rename {tools => src/tools}/test_files/queen.fen (100%) rename {tools => src/tools}/test_files/stalemate0.fen (100%) rename {tools => src/tools}/test_files/stalemate1.fen (100%) rename {tools => src/tools}/test_files/stalemate2.fen (100%) rename {tools => src/tools}/test_files/unstable1 (100%) rename {tools => src/tools}/test_files/unstable_positions (100%) rename {tools => src/tools}/test_files/unstable_positions2 (100%) rename {tools => src/tools}/test_files/win_at_chess_test.epd (100%) rename {tools => src/tools}/tester.py (100%) rename {tools => src/tools}/uci.py (100%) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..24dcec7 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,30 @@ +[build-system] +requires = ["setuptools", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "sunfish" +version = "1.0.0" +description = "Sunfish: a Python Chess Engine in 111 lines of code" +authors = [ + { name = "Thomas Ahle", email = "thomasahle@example.com" } +] +readme = "README.md" +license = { text = "GNU GPL v3" } +requires-python = ">=3.6" +classifiers = [ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", + "Operating System :: OS Independent", +] + +[tool.setuptools] +packages = ["sunfish"] + +[tool.setuptools.package-dir] +"sunfish" = "src" + +[tool.setuptools.package-data] +"sunfish"= ["**/*"] + + diff --git a/.github/workflows/python-app.yml b/src/.github/workflows/python-app.yml similarity index 100% rename from .github/workflows/python-app.yml rename to src/.github/workflows/python-app.yml diff --git a/.gitignore b/src/.gitignore similarity index 100% rename from .gitignore rename to src/.gitignore diff --git a/LICENSE.md b/src/LICENSE.md similarity index 100% rename from LICENSE.md rename to src/LICENSE.md diff --git a/README.md b/src/README.md similarity index 100% rename from README.md rename to src/README.md diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..caeb4d3 --- /dev/null +++ b/src/__init__.py @@ -0,0 +1,3 @@ +from . import sunfish +from . import tools + diff --git a/build/clean.sh b/src/build/clean.sh similarity index 100% rename from build/clean.sh rename to src/build/clean.sh diff --git a/build/pack.sh b/src/build/pack.sh similarity index 100% rename from build/pack.sh rename to src/build/pack.sh diff --git a/build/pack_nnue.sh b/src/build/pack_nnue.sh similarity index 100% rename from build/pack_nnue.sh rename to src/build/pack_nnue.sh diff --git a/docs/logo/sunfish_large.png b/src/docs/logo/sunfish_large.png similarity index 100% rename from docs/logo/sunfish_large.png rename to src/docs/logo/sunfish_large.png diff --git a/docs/logo/sunfish_small.bmp b/src/docs/logo/sunfish_small.bmp similarity index 100% rename from docs/logo/sunfish_small.bmp rename to src/docs/logo/sunfish_small.bmp diff --git a/docs/sunfish.6 b/src/docs/sunfish.6 similarity index 100% rename from docs/sunfish.6 rename to src/docs/sunfish.6 diff --git a/nnue/models/color.pickle b/src/nnue/models/color.pickle similarity index 100% rename from nnue/models/color.pickle rename to src/nnue/models/color.pickle diff --git a/nnue/models/color2.pickle b/src/nnue/models/color2.pickle similarity index 100% rename from nnue/models/color2.pickle rename to src/nnue/models/color2.pickle diff --git a/nnue/models/color2_v2.pickle b/src/nnue/models/color2_v2.pickle similarity index 100% rename from nnue/models/color2_v2.pickle rename to src/nnue/models/color2_v2.pickle diff --git a/nnue/models/color2_v3.pickle b/src/nnue/models/color2_v3.pickle similarity index 100% rename from nnue/models/color2_v3.pickle rename to src/nnue/models/color2_v3.pickle diff --git a/nnue/models/model.pickle b/src/nnue/models/model.pickle similarity index 100% rename from nnue/models/model.pickle rename to src/nnue/models/model.pickle diff --git a/nnue/models/model_19.pickle b/src/nnue/models/model_19.pickle similarity index 100% rename from nnue/models/model_19.pickle rename to src/nnue/models/model_19.pickle diff --git a/nnue/models/model_39.pickle b/src/nnue/models/model_39.pickle similarity index 100% rename from nnue/models/model_39.pickle rename to src/nnue/models/model_39.pickle diff --git a/nnue/models/model_59.pickle b/src/nnue/models/model_59.pickle similarity index 100% rename from nnue/models/model_59.pickle rename to src/nnue/models/model_59.pickle diff --git a/nnue/models/model_79.pickle b/src/nnue/models/model_79.pickle similarity index 100% rename from nnue/models/model_79.pickle rename to src/nnue/models/model_79.pickle diff --git a/nnue/models/model_99.pickle b/src/nnue/models/model_99.pickle similarity index 100% rename from nnue/models/model_99.pickle rename to src/nnue/models/model_99.pickle diff --git a/nnue/models/nnue1.pickle b/src/nnue/models/nnue1.pickle similarity index 100% rename from nnue/models/nnue1.pickle rename to src/nnue/models/nnue1.pickle diff --git a/nnue/models/tanh.pickle b/src/nnue/models/tanh.pickle similarity index 100% rename from nnue/models/tanh.pickle rename to src/nnue/models/tanh.pickle diff --git a/nnue/models/tanh2.pickle b/src/nnue/models/tanh2.pickle similarity index 100% rename from nnue/models/tanh2.pickle rename to src/nnue/models/tanh2.pickle diff --git a/nnue/models/tanh_139.pickle b/src/nnue/models/tanh_139.pickle similarity index 100% rename from nnue/models/tanh_139.pickle rename to src/nnue/models/tanh_139.pickle diff --git a/nnue/models/tanh_199.pickle b/src/nnue/models/tanh_199.pickle similarity index 100% rename from nnue/models/tanh_199.pickle rename to src/nnue/models/tanh_199.pickle diff --git a/nnue/models/tanh_79.pickle b/src/nnue/models/tanh_79.pickle similarity index 100% rename from nnue/models/tanh_79.pickle rename to src/nnue/models/tanh_79.pickle diff --git a/nnue/nnue_bug_fens b/src/nnue/nnue_bug_fens similarity index 100% rename from nnue/nnue_bug_fens rename to src/nnue/nnue_bug_fens diff --git a/nnue/speed_tests.py b/src/nnue/speed_tests.py similarity index 100% rename from nnue/speed_tests.py rename to src/nnue/speed_tests.py diff --git a/nnue/sunfish2.py b/src/nnue/sunfish2.py similarity index 100% rename from nnue/sunfish2.py rename to src/nnue/sunfish2.py diff --git a/nnue/sunfish_king.py b/src/nnue/sunfish_king.py similarity index 100% rename from nnue/sunfish_king.py rename to src/nnue/sunfish_king.py diff --git a/requirements.txt b/src/requirements.txt similarity index 100% rename from requirements.txt rename to src/requirements.txt diff --git a/sunfish.py b/src/sunfish.py similarity index 92% rename from sunfish.py rename to src/sunfish.py index 0c43388..6fb712c 100755 --- a/sunfish.py +++ b/src/sunfish.py @@ -450,51 +450,54 @@ def render(i): #input = raw_input # minifier-hide start -import sys, tools.uci -tools.uci.run(sys.modules[__name__], hist[-1]) -sys.exit() -# minifier-hide end +if __name__ == "__main__": + print('aaa') + import sys, tools.uci + tools.uci.run(sys.modules[__name__], hist[-1]) + sys.exit() -searcher = Searcher() -while True: - args = input().split() - if args[0] == "uci": - print("id name", version) - print("uciok") - - elif args[0] == "isready": - print("readyok") - - elif args[0] == "quit": - break - - elif args[:2] == ["position", "startpos"]: - del hist[1:] - for ply, move in enumerate(args[3:]): - i, j, prom = parse(move[:2]), parse(move[2:4]), move[4:].upper() - if ply % 2 == 1: - i, j = 119 - i, 119 - j - hist.append(hist[-1].move(Move(i, j, prom))) - - elif args[0] == "go": - wtime, btime, winc, binc = [int(a) / 1000 for a in args[2::2]] - if len(hist) % 2 == 0: - wtime, winc = btime, binc - think = min(wtime / 40 + winc, wtime / 2 - 1) - - start = time.time() - move_str = None - for depth, gamma, score, move in Searcher().search(hist): - # The only way we can be sure to have the real move in tp_move, - # is if we have just failed high. - if score >= gamma: - i, j = move.i, move.j - if len(hist) % 2 == 0: +# minifier-hide end +if 0: + searcher = Searcher() + while True: + args = input().split() + if args[0] == "uci": + print("id name", version) + print("uciok") + + elif args[0] == "isready": + print("readyok") + + elif args[0] == "quit": + break + + elif args[:2] == ["position", "startpos"]: + del hist[1:] + for ply, move in enumerate(args[3:]): + i, j, prom = parse(move[:2]), parse(move[2:4]), move[4:].upper() + if ply % 2 == 1: i, j = 119 - i, 119 - j - move_str = render(i) + render(j) + move.prom.lower() - print("info depth", depth, "score cp", score, "pv", move_str) - if move_str and time.time() - start > think * 0.8: - break + hist.append(hist[-1].move(Move(i, j, prom))) + + elif args[0] == "go": + wtime, btime, winc, binc = [int(a) / 1000 for a in args[2::2]] + if len(hist) % 2 == 0: + wtime, winc = btime, binc + think = min(wtime / 40 + winc, wtime / 2 - 1) + + start = time.time() + move_str = None + for depth, gamma, score, move in Searcher().search(hist): + # The only way we can be sure to have the real move in tp_move, + # is if we have just failed high. + if score >= gamma: + i, j = move.i, move.j + if len(hist) % 2 == 0: + i, j = 119 - i, 119 - j + move_str = render(i) + render(j) + move.prom.lower() + print("info depth", depth, "score cp", score, "pv", move_str) + if move_str and time.time() - start > think * 0.8: + break - print("bestmove", move_str or '(none)') + print("bestmove", move_str or '(none)') diff --git a/sunfish_nnue.py b/src/sunfish_nnue.py similarity index 100% rename from sunfish_nnue.py rename to src/sunfish_nnue.py diff --git a/tools/clean_draws.py b/src/tools/clean_draws.py similarity index 100% rename from tools/clean_draws.py rename to src/tools/clean_draws.py diff --git a/tools/fancy.py b/src/tools/fancy.py similarity index 100% rename from tools/fancy.py rename to src/tools/fancy.py diff --git a/tools/quick_tests.sh b/src/tools/quick_tests.sh similarity index 100% rename from tools/quick_tests.sh rename to src/tools/quick_tests.sh diff --git a/tools/test.sh b/src/tools/test.sh similarity index 100% rename from tools/test.sh rename to src/tools/test.sh diff --git a/tools/test_files/3fold.epd b/src/tools/test_files/3fold.epd similarity index 100% rename from tools/test_files/3fold.epd rename to src/tools/test_files/3fold.epd diff --git a/tools/test_files/3fold.pgn b/src/tools/test_files/3fold.pgn similarity index 100% rename from tools/test_files/3fold.pgn rename to src/tools/test_files/3fold.pgn diff --git a/tools/test_files/3fold_do.pgn b/src/tools/test_files/3fold_do.pgn similarity index 100% rename from tools/test_files/3fold_do.pgn rename to src/tools/test_files/3fold_do.pgn diff --git a/tools/test_files/3fold_dont.pgn b/src/tools/test_files/3fold_dont.pgn similarity index 100% rename from tools/test_files/3fold_dont.pgn rename to src/tools/test_files/3fold_dont.pgn diff --git a/tools/test_files/avoid_mate.epd b/src/tools/test_files/avoid_mate.epd similarity index 100% rename from tools/test_files/avoid_mate.epd rename to src/tools/test_files/avoid_mate.epd diff --git a/tools/test_files/bratko_kopec_test.epd b/src/tools/test_files/bratko_kopec_test.epd similarity index 100% rename from tools/test_files/bratko_kopec_test.epd rename to src/tools/test_files/bratko_kopec_test.epd diff --git a/tools/test_files/ccr_one_hour_test.epd b/src/tools/test_files/ccr_one_hour_test.epd similarity index 100% rename from tools/test_files/ccr_one_hour_test.epd rename to src/tools/test_files/ccr_one_hour_test.epd diff --git a/tools/test_files/chessathome_openings.fen b/src/tools/test_files/chessathome_openings.fen similarity index 100% rename from tools/test_files/chessathome_openings.fen rename to src/tools/test_files/chessathome_openings.fen diff --git a/tools/test_files/gaviota-starters.pgn b/src/tools/test_files/gaviota-starters.pgn similarity index 100% rename from tools/test_files/gaviota-starters.pgn rename to src/tools/test_files/gaviota-starters.pgn diff --git a/tools/test_files/mate1.fen b/src/tools/test_files/mate1.fen similarity index 100% rename from tools/test_files/mate1.fen rename to src/tools/test_files/mate1.fen diff --git a/tools/test_files/mate2.fen b/src/tools/test_files/mate2.fen similarity index 100% rename from tools/test_files/mate2.fen rename to src/tools/test_files/mate2.fen diff --git a/tools/test_files/mate3.fen b/src/tools/test_files/mate3.fen similarity index 100% rename from tools/test_files/mate3.fen rename to src/tools/test_files/mate3.fen diff --git a/tools/test_files/mate4.fen b/src/tools/test_files/mate4.fen similarity index 100% rename from tools/test_files/mate4.fen rename to src/tools/test_files/mate4.fen diff --git a/tools/test_files/nullmove_mates.fen b/src/tools/test_files/nullmove_mates.fen similarity index 100% rename from tools/test_files/nullmove_mates.fen rename to src/tools/test_files/nullmove_mates.fen diff --git a/tools/test_files/perft.epd b/src/tools/test_files/perft.epd similarity index 100% rename from tools/test_files/perft.epd rename to src/tools/test_files/perft.epd diff --git a/tools/test_files/pgns.pgn b/src/tools/test_files/pgns.pgn similarity index 100% rename from tools/test_files/pgns.pgn rename to src/tools/test_files/pgns.pgn diff --git a/tools/test_files/queen.fen b/src/tools/test_files/queen.fen similarity index 100% rename from tools/test_files/queen.fen rename to src/tools/test_files/queen.fen diff --git a/tools/test_files/stalemate0.fen b/src/tools/test_files/stalemate0.fen similarity index 100% rename from tools/test_files/stalemate0.fen rename to src/tools/test_files/stalemate0.fen diff --git a/tools/test_files/stalemate1.fen b/src/tools/test_files/stalemate1.fen similarity index 100% rename from tools/test_files/stalemate1.fen rename to src/tools/test_files/stalemate1.fen diff --git a/tools/test_files/stalemate2.fen b/src/tools/test_files/stalemate2.fen similarity index 100% rename from tools/test_files/stalemate2.fen rename to src/tools/test_files/stalemate2.fen diff --git a/tools/test_files/unstable1 b/src/tools/test_files/unstable1 similarity index 100% rename from tools/test_files/unstable1 rename to src/tools/test_files/unstable1 diff --git a/tools/test_files/unstable_positions b/src/tools/test_files/unstable_positions similarity index 100% rename from tools/test_files/unstable_positions rename to src/tools/test_files/unstable_positions diff --git a/tools/test_files/unstable_positions2 b/src/tools/test_files/unstable_positions2 similarity index 100% rename from tools/test_files/unstable_positions2 rename to src/tools/test_files/unstable_positions2 diff --git a/tools/test_files/win_at_chess_test.epd b/src/tools/test_files/win_at_chess_test.epd similarity index 100% rename from tools/test_files/win_at_chess_test.epd rename to src/tools/test_files/win_at_chess_test.epd diff --git a/tools/tester.py b/src/tools/tester.py similarity index 100% rename from tools/tester.py rename to src/tools/tester.py diff --git a/tools/uci.py b/src/tools/uci.py similarity index 100% rename from tools/uci.py rename to src/tools/uci.py