Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"= ["**/*"]


File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions src/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import sunfish
from . import tools

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
91 changes: 47 additions & 44 deletions sunfish.py → src/sunfish.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)')

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.