/Chess

A Chinese chess program based on tkintertools and written in pure Python.

Primary LanguagePythonMIT LicenseMIT

Chess ๐Ÿš€

A Chinese chess program based on tkintertools and written in Python 3.12 and C++ 20.

This program is implemented using a mix of tkinter and tkintertools modules, tkintertools is a third-party Python module that I developed on my own to beautify tkinter and provide some advanced features! ๐ŸŽ‰

Note

Since the original program was written by me one year ago, the tkintertools module uses the test version, and the AI of the program was added later, and the previous code quality is relatively poor, please understand. ๐Ÿ˜…

Star History

Star History Chart

How to use

Before use

Important

Make sure your Python version is 3.12 or greater and C++ version is 20 or greater.

Choose the mode

run the main.py and choose a game mode you want.

I've provided 4 modes, Three of them can be selected in "ๆ–ฐๆธธๆˆ"๏ผŒand "ๆฎ‹ๅฑ€ๆŒ‘ๆˆ˜" needs to be selected in the "ๆฃ‹ๅฑ€ๅบ“".

One last step

have fun! ๐Ÿ˜

Brief introduction

Base Features

  1. Two-player match
  2. Man-machine battles
  3. Endgame Challenge
  4. LAN connection

About the AI

I've provided 2 AI algorithms, one of which also provides an implementation of C++20:

  1. Minimum-Max search algorithm
    • Python: min_max_search.py
  2. Alpha-beta pruning algorithm
    • Python: alpha_beta_search.py
    • C++ (default):
      • src: ./cpp/HelloWorld.cpp
      • dll: ./PyDLL.dll

You can change them in the settings. By the way, default value of the search depth is 4.

Tip

Due to the smaller number of pieces in endgame mode, the search space is smaller, and you can increase the AI's search depth a little more, and the results could be even better!

Caution

You can also modify the pieces of the individual AI algorithms to evaluate the scores if you want, but be careful not to set the score to a limit value (like math.inf), which will cause the algorithm to not come up with the correct result!

Some really great features

When you're playing chess, the terminal actually has an output! For example:

SCORE: 2
STEP: 5
ใ€‡ใ€‡่ฑกๅฃซๅฐ†ๅฃซ่ฑก้ฉฌ่ฝฆ
่ฝฆใ€‡ใ€‡ใ€‡ใ€‡ใ€‡ใ€‡ใ€‡ใ€‡
ใ€‡็‚ฎ้ฉฌใ€‡ใ€‡ใ€‡ใ€‡็‚ฎใ€‡
ๅ’ใ€‡ๅ’ใ€‡ๅ’ใ€‡ๅ’ใ€‡ๅ’
ใ€‡ใ€‡ใ€‡ใ€‡ใ€‡ใ€‡ใ€‡ใ€‡ใ€‡
ใ€‡ใ€‡ใ€‡ใ€‡ใ€‡ใ€‡ใ€‡ใ€‡ใ€‡
ๅ…ตใ€‡ๅ…ตใ€‡ๅ…ตใ€‡ๅ…ตใ€‡ๅ…ต
ใ€‡ใ€‡้ฆฌใ€‡็ ฒใ€‡ใ€‡็ ฒใ€‡
ใ€‡ใ€‡ใ€‡ใ€‡ใ€‡ใ€‡ใ€‡ใ€‡ใ€‡
ใ€‡่ปŠ็›ธไป•ๅธฅไป•็›ธ้ฆฌ่ปŠ

It provides a very clear picture of the game state and the current AI score.

Warning

Some of the pictures and other resources involved in the project come from the Internet and are not used for commercial purposes.
Please contact me for infringement: 2951256653@qq.com

Known Bugs

  • When the AI algorithm can't find anything that can get rid of the dead chess ending, it will report an error and cause the thread to crash, which in turn will cause the computer to be in a state of "thinking" without proceeding to the next step.
  • When starting a new game, threads from previous games will not be killed, causing the game to become unusually stuttering.
  • When connected to a local area network, when one party disconnects, the other party may crash or freeze.
  • Some of the code on statistics is broken.

If you want to know more about this program, see: https://xiaokang2022.blog.csdn.net/article/details/128852029