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
Changes from 1 commit
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
Prev Previous commit
Formatting
gaganchandan committed Apr 29, 2023
commit 91376fc1d6aeb7a7d089c19254c5f384ce654c38
10 changes: 5 additions & 5 deletions jarviscli/plugins/chess.py
Original file line number Diff line number Diff line change
@@ -4,25 +4,25 @@
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):
while (True):
jarvis.say("Choose your option:")
jarvis.say("1. Moves")
jarvis.say("2. FEN")
option = jarvis.input("Choice: ")
if(option == '1'):
if (option == '1'):
moves = jarvis.input("Moves: ")
print(moves.split())
fish.set_position(moves.split())
jarvis.say(fish.get_best_move())
elif(option == '2'):
elif (option == '2'):
fen = jarvis.input("FEN: ")
if(fish.is_fen_valid(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")