Skip to content

Xiaokang2022/Chess

Repository files navigation

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