Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the chess plugin which leverages stockfish #1095

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion installer/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ pdf2image
python-nmap
yeelight
haversine
FlightRadarAPI
FlightRadarAPI
stockfish==3.28.0
28 changes: 28 additions & 0 deletions jarviscli/plugins/chess.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# There needs to be a binary named 'stockfish' in the PATH for this to work.

import os
from plugin import plugin
from stockfish import Stockfish


@plugin('chess')
Copy link
Collaborator

@pnhofmann pnhofmann May 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@plugin('chess')
@require(native="stockfish")
@plugin('chess')

You can even declare in the plugin, that stockfish binary is required ;)

class Chess():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add an example of usage in the documentation.
Like:
"""
Docu
"""

def __call__(self, jarvis, s):
fish = Stockfish()
while (True):
jarvis.say("Choose your option:")
jarvis.say("1. Moves")
jarvis.say("2. FEN")
option = jarvis.input("Choice: ")
if (option == '1'):
moves = jarvis.input("Moves: ")
print(moves.split())
fish.set_position(moves.split())
jarvis.say(fish.get_best_move())
elif (option == '2'):
fen = jarvis.input("FEN: ")
if (fish.is_fen_valid(fen)):
fish.set_fen_position(fen)
jarvis.say(fish.get_best_move())
Copy link
Collaborator

@pnhofmann pnhofmann May 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should catch ValueError at this line

Moves: a2
['a2']
Some error occurred, please open an issue on github!
Here is error:

Traceback (most recent call last):
  File "/data/git/Jarvis/jarviscli/CmdInterpreter.py", line 286, in try_do
    do(self, s)
  File "/data/git/Jarvis/jarviscli/plugin.py", line 208, in run
    self._backend[0](jarvis.get_api(), s)
  File "/data/git/Jarvis/jarviscli/plugins/chess.py", line 20, in __call__
    fish.set_position(moves.split())
  File "/home/phil/git/Jarvis/env/lib/python3.8/site-packages/stockfish/models.py", line 222, in set_position
    self.make_moves_from_current_position(moves)
  File "/home/phil/git/Jarvis/env/lib/python3.8/site-packages/stockfish/models.py", line 238, in make_moves_from_current_position
    raise ValueError(f"Cannot make move: {move}")
ValueError: Cannot make move: a2

else:
jarvis.say("Invalid option\n")