Git Product home page Git Product logo

python-easy-chess-gui's Introduction

Python Easy Chess GUI

A Chess GUI based from Python using PySimpleGUI and Python-Chess modules. Users can also load a chess engine and play with it. This program is based on a demo chess against ai from PySimpleGUI.

Command line to compile the source to exe using pyinstaller.

pyinstaller python_easy_chess_gui.py -F -w

Then add the folders for the exe to work.

A. Requirements

If you want to run from the python source the following are required or see the installation section below.

  • Python 3.7 and up
  • Python-chess v0.28.0 and up
  • PySimpleGUI 4.4.1 and up
  • Pyperclip
  • Download this repo

Or you can just download the executable file along with other files such as book and images.

B. Features

1. Save games to repertoire pgn files

2. Install uci engine of your choice

2.1 It is recommended to configure the engine setting after installation

Configure engine via Engine->Manage->Edit, select engine and press modify.

3. Need book assistance? Right-click on BOOK 2 and press show

4. Need what engine adviser will think about the position? Right-click on Adviser and press start

C. Installation

  1. If you want to run from the source code
  1. If you want to run from the exe
  • Download the exe file from the release link

Note

If you are on linux be sure to give permission to uci engine with:
chmod +x uci_engine_fn.

D. How to

To start the gui

  • Execute python_easy_chess_gui.py
    Typical command line:
    python python_easy_chess_gui.py
  • Execute the exe when using exe file

To play as white

  • Mode->Play
  • Move the piece you want to move
  • Press the square you want the piece to move to

To play as black

  • If current mode is Neutral, Board->Flip, flip such that black pieces are at the bottom
  • If current mode is Play, Mode->Neutral, then Board->Flip
  • Mode->Play
  • Engine->Go

To paste a FEN

  • You should be in Play mode. If not, then Mode->Play
  • FEN->Paste
  • If you play as white, you can make your move
  • If you play as black, Engine->Go

To flip board

  • If current mode is Neutral, Board->Flip
  • If current mode is Play, Mode->Neutral, then Board->Flip

To set opponent engine book options

  • Book->Set Book, only available in Neutral mode. This book is used by your opponent engine. This book is named pecg_book.bin and is located in Book folder. You can build a polyglot book name it pecg_book.bin and replace the default.

To Hide/Unhide engine search info

  • Right-click on Opponent Search Info label an press Show. This would only work on Play mode.

To Hide/Unhide Book info

  • Right-click on BOOK 1 or BOOK 2 labels and press Show. This would only work on Play mode.

To request Adviser search info

  • Right-click on Adviser and press start. This would only work on Play mode.

To select opponent engine

  • Engine->Set Engine Opponent, available only in Neutral mode.

To set time control of engine

  • Time->Engine

To set time control of user

  • Time->User

To install engine

  • Engine->Manage->Install
    This is only accessible in Neutral mode. After the uci engine is installed, you have to Edit it to modify its options, etc. Only uci engines are supported so far.
  • Engine->Manage->Edit

To Edit engine

  • Engine->Manage->Edit

To delete engine from config file

  • Engine->Manage->Delete

E. Credits

python-easy-chess-gui's People

Contributors

buzzcraft avatar fsmosca avatar tommikurki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-easy-chess-gui's Issues

Implement engine search interruption

While engine is thinking:

  • Forced it to play its best move seen so far
    • Add Move Now sub-menu in Engine menu
  • Allow user to change mode from Play to Neutral
  • Allow user to start a new game
  • Allow user to resign
  • Allow user to adjudicate the game

Bad attribute error on Ubuntu when trying to select any menu item

Using ubuntu 20.04.5 and python 3.8 I was able to install this code and start it, and I see the GUI. But when I select any menu item, no matter what, the code crashes with the following error message:

Traceback (most recent call last):
  File "python_easy_chess_gui.py", line 3578, in <module>
    main()
  File "python_easy_chess_gui.py", line 3574, in main
    pecg.main_loop()
  File "python_easy_chess_gui.py", line 3443, in main_loop
    window.Disable()
  File "/home/user/Chess/venv_Python-Easy-Chess-GUI/lib/python3.8/site-packages/PySimpleGUI/PySimpleGUI.py", line 10999, in disable
    self.TKroot.attributes('-disabled', 1)
  File "/usr/lib/python3.8/tkinter/__init__.py", line 1976, in wm_attributes
    return self.tk.call(args)
_tkinter.TclError: bad attribute "-disabled": must be -alpha, -topmost, -zoomed, -fullscreen, or -type

Add Settings menu

General gui options will be saved here.

  • Add option to save time left of the game in the pgn.

Create polyglot book from pgn file

  • Create Polyglot dir
  • Create PGN dir
  • Save polyglot.exe and manual in polyglot dir
  • Add Tools menu
  • Add "Create Book" sub-menu under Tools menu
  • Create a new window for Create Book
  • Add class BuildBook()
    • Add init with pgn file located at PGN dir
    • Add create_book() method

Add engine adviser

  • Create adviser button, can be a text element
  • Add 1 Text element to show the adviser short pv
  • Show short pv, once button is pressed, adviser engine will search for bestmove of the position
  • Create a Set Adviser Engine sub-menu under Engine menu. User can select engine name and other basic setting
  • Modify Engine menu, rename Set Engine sub-menu to Set Opponent Engine

Best Move display when I use stockfish

First, I love that you have put this out to the public for people to use.
I am trying to make a robot that uses the stockfish engine to play along with the game in real-time with a board.
Would there be a way I can gather the stockfish best move data and then send that to the robot for it to move?
Any help would be great, even if you send me on my way with only a little help.
The robot I am using is Niryo One.

Missing Icon file?

On the screenshot in the readme, I noticed that the icon is the tkinter default 'leaf' style icon. PySimpleGUI has its own built-in icon that is normally shown.

image

Support for MacOS/Linux?

Since .exes are used, this doesnt seem to work on UNIX based systems. What is involved in making that possible? I can submit a PR.

Pathing problems

When trying to test the program I am consistenly having pathing issues from running commands in MacOS. I have tried from both with VSCode and directly from terminal. Both in VENV and not. I was finally able to move past the file itself being inaccessible by using the absolute path but then ran into pathing issues for the assets themselves. This:

(base) thisaintyocompgetoff@nonyas-MacBook-Air pkmn_chs % python "/Users/thisaintyocompgetoff/Desktop/Coding/pkmn_chs/chess_env/lib/python3.9/site-packages/Python-Easy-Chess-GUI/python_easy_chess_gui.py" 

Returned this:

Traceback (most recent call last):
  File "/Users/thisaintyocompgetoff/Desktop/Coding/pkmn_chs/chess_env/lib/python3.9/site-packages/Python-Easy-Chess-GUI/python_easy_chess_gui.py", line 3578, in <module>
    main()
  File "/Users/thisaintyocompgetoff/Desktop/Coding/pkmn_chs/chess_env/lib/python3.9/site-packages/Python-Easy-Chess-GUI/python_easy_chess_gui.py", line 3574, in main
    pecg.main_loop()
  File "/Users/thisaintyocompgetoff/Desktop/Coding/pkmn_chs/chess_env/lib/python3.9/site-packages/Python-Easy-Chess-GUI/python_easy_chess_gui.py", line 2579, in main_loop
    self.check_engine_config_file()
  File "/Users/thisaintyocompgetoff/Desktop/Coding/pkmn_chs/chess_env/lib/python3.9/site-packages/Python-Easy-Chess-GUI/python_easy_chess_gui.py", line 1163, in check_engine_config_file
    self.engine_file_list = self.get_engines()
  File "/Users/thisaintyocompgetoff/Desktop/Coding/pkmn_chs/chess_env/lib/python3.9/site-packages/Python-Easy-Chess-GUI/python_easy_chess_gui.py", line 2412, in get_engines
    files = os.listdir(engine_path)
FileNotFoundError: [Errno 2] No such file or directory: 'Engines'

I have gotten similar errors for the images for the pieces on the board.

Is there a way to fix this without manually changing every path to its absolute path? I want to build on top of this so that seems like it would stop the project before it starts.

I am on MacOS Monterrey 12.6.2

Add feature to allow user to install an engine

  • Add sub menu "Manage" under engine menu.
    • Add submenu "Install" under Manage
    • Add submenu "Edit" under Manage
    • Add submenu "Delete" under Manageoption values.
  • Add code for Install
  • Add code for Edit
  • Add code for delete
  • Load the engine if it would work.
    • Set Engine Opponent
    • Set Engine Adviser

[Enhancement] Right click menu

Do you know about the right click menu that is available to all elements?

I don't now exactly what action you would add to say a piece on the board, but it could be super useful. Maybe "Remove Piece" or "Quit" or ???

Anyway, just a reminder that it's a tool in your arsenal.

Same with ToolTips.

These kinds of tools have turned out to be super useful at times.

The debugger

FINALLY, it's not documented well, but if you're running plain PySimpleGUI, then you can press the BREAK key or CONTROL+BREAK key to bring up the debugger. This feature is so amazing because it allows you to debug your code while it continued to run.... and it's after you started running the program, perhaps without an IDE.

So, you're running your program by double clicking on it but after a while there's a bug that starts showing up intermittently. With this debugger you can do almost anything because there's a REPL built in. With that you can literally execute code.

The reason I thought of it is the right click menu. On the popup window that shows up in the corner after pressing BREAK, you can right click any text and you'll get a right click menu to - Run main debugger (open the other debug window) or Exit.

Add time control and clock boxes

  • Add TimeControl menu
    • Add Engine submenu
      • Fischer type, example TC 300+10
    • Add User submenu
      • Fischer type, example TC 300+10
      • Delay type, example TC 300-10
  • Add clock box for engine
    • Remaining time box, hh:mm:ss
    • Elapsed counter box, mm:ss:ms
  • Add clock box for user
    • Remaining time box, hh:mm:ss
    • Elapsed counter box, mm:ss:ms

Thank you for writing this!

Really appreciate you taking the time to make this game (and using PySimpleGUI in the process). I use it a lot as a successful example. The screenshots in your readme are awesome. Thanks for your hard work!

install new engine causes a crash

System information

Macbook Air with M1 16GB
OS: OSX 11.0.1 Big Sur
Python: Python 3.9.1
packages:
  python-chess:  1.999
  pysimplegui: 4.32.1
  pyperclip: 1.8.1

i clicked
menu>engine>manage>install

Traceback (most recent call last):
  File "/Users/nic/chess/Python-Easy-Chess-GUI/python_easy_chess_gui.py", line 3575, in <module>
    main()
  File "/Users/nic/chess/Python-Easy-Chess-GUI/python_easy_chess_gui.py", line 3571, in main
    pecg.main_loop()
  File "/Users/nic/chess/Python-Easy-Chess-GUI/python_easy_chess_gui.py", line 2859, in main_loop
    window.Disable()
  File "/Users/nic/miniforge3/envs/python39/lib/python3.9/site-packages/PySimpleGUI/PySimpleGUI.py", line 8537, in Disable
    self.TKroot.attributes('-disabled', 1)
  File "/Users/nic/miniforge3/envs/python39/lib/python3.9/tkinter/__init__.py", line 1968, in wm_attributes
    return self.tk.call(args)
_tkinter.TclError: bad attribute "-disabled": must be -alpha, -fullscreen, -modified, -notify, -titlepath, -topmost, -transparent, or -type

Add GUI book

The book is a polyglot book named pecg_book.bin. When enabled, the gui will probe the polyglot book and if there is a move, it will use that move for the engine.

Book file and location is at book/pecg_book.bin

  • Use Class
  • Add "Use Book" option
  • Add "Best move" option
  • Add "Random move" option

[Marketing] YouTube

There are some pretty darned popular YouTube channels devoted to chess and some with chess and AI. It seems like if you could get just one of those guys / gals (one chick in particular I found quite, hum, entertaining).

I wonder if any of them would jump at having custom software just for them. You can easily add their logo or YouTube name to the Window somewhere to make it extra exclusive just for them. Heck, maybe the fact they have input into something like that may be enough to get their attention.

I dunno, just throwing random stuff out there. May or not not be helpful in any way. As usual, the price of this advice should tell you a little about its potential value ;-)

Test v0.27 thoroughly

  • Neutral mode
  • Play mode
    • Promote
      • Queen
      • Rook
      • Bishop
      • Knight
    • EP capture
    • Castle
  • New Game
  • Flipping board
  • Pasting FEN
  • Saving games

Trying to castle by clicking on King then on rook crashes program

Trying to castle by clicking on King then on rook crashes program.
Stack trace:
Traceback (most recent call last):
File "\python_easy_chess_gui.py", line 3578, in
main()
File "
\python_easy_chess_gui.py", line 3574, in main
pecg.main_loop()
File "\python_easy_chess_gui.py", line 3535, in main_loop
start_new_game = self.play_game(window, engine_id_name, board)
File "
\python_easy_chess_gui.py", line 2055, in play_game
self.update_rook(window, str(user_move))
File "*\python_easy_chess_gui.py", line 1543, in update_rook
self.psg_board[self.get_row(fr)][self.get_col(fr)] = BLANK
UnboundLocalError: local variable 'fr' referenced before assignment

Design a movelist box for game navigation

When certain move is selected in the movelist box, the board will also update.
When move navigation button is pressed, move is highlighted in the movelist box.

It is ideal to have more than one move in the horizontal in the move list box.

  • Study PySimpleGUI Table element
  • Study PySimpleGUI Tree element

Create engine config file

  • Read the current dir where pecg.exe is located and look for pecg_engines.json file.
  • If there is no pecg_engines.json file, then read the engines dir and create pecg_engines.json file.
    • The json format will be the same to that of cutechess
    • Run uci engine and determine its options and id name
      • Save all options and write it to json file. Hash is set to 64, and threads is set to 1, all other options will use default values.
      • Write engine id name to json file.
  • Read the json file at startup and show the engine id name in engine list box when user presses Set Engine Opponent.
  • When user selects an engine from the engine list, and presses OK button
    • Read the json file and save the engine file and path with file
  • Tested uci engines
    • Alaric
    • Amoeba
    • Anmon
    • Andscacs
    • Arasan
    • Arminius
    • Atlas
    • Bobcat
    • Booot
    • Cheng
    • Critter
    • Demolito
    • Deuterium
    • Ethereal
    • Floyd
    • Fire
    • Fizbo
    • Gaviota (Does not work, Python-Chess 0.28.0 does not run it)
    • Greko
    • Gogobello
    • Hannibal
    • Ice
    • Laser
    • Lc0
    • Marvin
    • Maverick
    • Monolith
    • Nemorino
    • Pedone
    • Rhetoric
    • Pirarucu
    • Rodent
    • RofChade
    • RubiChess
    • Schooner
    • Senpai
    • Shield
    • Skiull
    • SmarThink
    • Spark (Does not work, Python-Chess 0.28.0 does not run it)
    • Spike (Does not work, Python-Chess 0.28.0 does not run it)
    • Stockfish
    • Texel
    • The Baron
    • Toga
    • Topple
    • Vajolet2
    • Wasp
    • Winter
    • Xiphos
    • Zurichess

error : bad attribute "-disabled"

i think i encounter a serious bug : bad attribute "-disabled" .. the following error lines occur after starting the application (which seems OK) at all menu actions, eg. at "User / Set name" and "Engine / Manage / Install" :

$ python3 python_easy_chess_gui.py
Traceback (most recent call last):
  File "python_easy_chess_gui.py", line 3578, in <module>
    main()
  File "python_easy_chess_gui.py", line 3574, in main
    pecg.main_loop()
  File "python_easy_chess_gui.py", line 2829, in main_loop
    window.Disable()
  File "/home/roelof/.local/lib/python3.8/site-packages/PySimpleGUI/PySimpleGUI.py", line 9239, in disable
    self.TKroot.attributes('-disabled', 1)
  File "/usr/lib/python3.8/tkinter/__init__.py", line 1976, in wm_attributes
    return self.tk.call(args)
_tkinter.TclError: bad attribute "-disabled": must be -alpha, -topmost, -zoomed, -fullscreen, or -type

maybe i can provide more info to solve this issue .. I use Xubuntu 20.04 and i'm not a beginner at Linux .. do i miss some module on my OS ? Can i supply some log ?

Name change....

I would think about a sexier name down the road, or ASAP.

You've got what may very well be the premier chess program written in Python, certainly the best that has a GUI.

Chess Master
Chess Multi-AI
Multi-AI Chess

I'm TERRIBLE at naming stuff, or am on short notice. I renamed PySimpleGUI several times. Had several icons made too. I went with the best of them. The point is that marketing counts.

If you can write at all, I would consider writing some articles on it. Get listed in Chess blogs, etc. I'm serious. This thing is likely to take off pretty well considering the stuff that it does and that it's such a nice GUI.

Here are a few things I thought of that may make a positive difference in your program's reach / use. I really would like to see it get a lot of use. It looks awesome and you've put time into it. These things may or may not have an impact. They're things I've learned from the past year of PySimpleGUI.

  1. EASILY packaged - has to work every time out of the box. I was going to update my version when I discovered yours and didn't. I was going to put all the graphics in the 1 source file.
  2. Has an easy recognizable name / memorable
  3. Doesn't hurt to have a logo. They're under $40 on Fiverr.
  4. Write an article. Within a few weeks of releasing PySimpleGUI 1.0 I wrote an article that was published on OpenSource. It went nuts and was picked up and re-distributed all over. I'm learning that other people rarely (never) write articles for your software, it's kinda up to you.
  5. Reddit has been a good place to get the word out. I'm sure there are tons of chess forums, et
  6. Get onto the list of "Python Applications" - I'll look at this one. I found a list of Python applications that look like windows programs. That's what the list is meant to be "Application Software". It's a rare thing in the Python world.
  7. Open yourself up to the AI community.

That last one could be super interesting. I'm wondering if it's possible to be the bolt-on display package or some other aspect of chess oriented AI work. I dunno, just thinking out loud.

I would like to see your software used. There is too little examples of Python GUI programs, especially good ones :-)

Anyway.... just my opinions. They're free, meaning they're pretty much worthless ๐Ÿ˜

ModuleNotFoundError: No module named 'chess.uci'

I have done the "py -m pip install chess", and been told that it went fine, but still get the message

ModuleNotFoundError: No module named 'chess.uci'

Anyone have the same problem? Or am I doing something wrong?

Released?

Are you officially released? Or, do you have a feature set that you're shooting for?

The reason I ask is that if you're "done" and like how it works, then you should get some publicity. I can help make some of that happen.

It looks really sharp! You've done a great job on this.

Let me know when you're ready to be promoted.

Delete player in a PGN file

  • Create "Delete Player" submenu under Tools menu on Neutral mode.
  • Create new window when Delete Player is pressed.
  • Create Text, Input, and FolderBrowse elements for pgn loading.
  • Create Listbox element to display player names from the PGN file.
  • Create OK button.
  • Read pgn file and extract player names and show it in Listbox.
  • If user selects a player from Listbox delete that player when user pressed OK button.

Create White and Black Repertoire.pgn

  • Add a sub-menu called Save to WhiteRepertoire under Game menu
    Save the game to WhiteRepertoire.pgn whenever user likes the opening of white.
  • Add a sub-menu called Save to BlackRepertoire under Game menu

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.