Skip to content

Commit

Permalink
Spaghetti alla pescatora
Browse files Browse the repository at this point in the history
  • Loading branch information
akuroiwa committed Jan 22, 2022
1 parent f4d0a89 commit d949a51
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
7 changes: 4 additions & 3 deletions chess_classification/genPgn.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
import argparse
import os

async def main(path="train-pgn", loop=1, time=20) -> None:
async def main(path="train-pgn", loop=1, time=20, fen=None) -> None:
transport, engine = await chess.engine.popen_uci(r"/usr/games/stockfish")

os.makedirs(path, exist_ok=True)

for i in range(loop):
board = chess.Board()
board = chess.Board(fen)
game = chess.pgn.Game()
game.headers["Event"]
game.setup(board)
Expand All @@ -44,10 +44,11 @@ def console_script():
parser.add_argument("-p", "--path", dest='path', default="train-pgn", type=str, help="Directory where you want to save. Default is train-pgn.")
parser.add_argument("-l", "--loop", dest='loop', default=1, type=int, help="How many PGN files you want. Default is 1.")
parser.add_argument("-t", "--time", dest='time', default=20, type=float, help="Minimum thinking time. Default is 20.")
parser.add_argument("-f", "--fen", dest='fen', default=None, type=str, help="Initial FEN.")
args = parser.parse_args()

asyncio.set_event_loop_policy(chess.engine.EventLoopPolicy())
asyncio.run(main(args.path, args.loop, args.time))
asyncio.run(main(args.path, args.loop, args.time, args.fen))

if __name__ == "__main__":
console_script()
7 changes: 5 additions & 2 deletions chess_classification/importPgn.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ def importPgn(pgn_file):
pgn = open(pgn_file)
train_df = pd.DataFrame(columns=["text", "labels"])

while game := chess.pgn.read_game(pgn):
# Python>=3.8
# while game := chess.pgn.read_game(pgn):
while True:
try:
game = chess.pgn.read_game(pgn)
result = game.headers["Result"]
if result == "1-0":
result_label = 2
Expand All @@ -34,7 +37,7 @@ def importPgn(pgn_file):
board.push(move)
train_df = train_df.append({"text": board.fen(), "labels": result_label}, ignore_index=True)
except:
continue
break
return train_df

def create_json_for_train_and_eval(self, train_pgn="train-pgn", eval_pgn="eval-pgn"):
Expand Down
8 changes: 5 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='chess_classification',
version='0.0.1',
version='0.0.2',
url='https://github.com/akuroiwa/chess-classification',
# # PyPI url
# download_url='',
Expand All @@ -17,7 +17,8 @@
long_description=open("README.md", "r").read(),
long_description_content_type='text/markdown',
zip_safe=False,
python_requires=">=3.8",
# python_requires=">=3.8",
python_requires=">=3.7",
classifiers=[
'Development Status :: 3 - Alpha',
'Environment :: Console',
Expand All @@ -28,7 +29,8 @@
"Operating System :: OS Independent",
'License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.8',
# 'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.7',
'Topic :: Scientific/Engineering',
'Topic :: Software Development',
"Topic :: Games/Entertainment :: Board Games",
Expand Down

0 comments on commit d949a51

Please sign in to comment.