Chess

Description

The purpose of the project was to create a chess game with a dedicated logic engine, with the possibility to play by mouse and keyboard (chess algebraic notation in a separate translation module). Moreover, according to assumptions, the game should contain mechanisms of:

  • Possibility to play with a bot controlled by a dedicated convolutional neural network model;
  • Multiplayer mode with communication by IPv6;
  • Game saving in SQLite database and XML file;
  • Millisecond analog clocks for each player;
  • Saving game status in JSON file;
  • Animated history playback gave from the file (controlled by the engine);
  • Marking possible moves while holding a piece.

The application was written in Python 3.10.9, using the Qt Framework, in the PyCharm 2023.1.1 (Professional Edition) environment.

User interfece

Interface is splitted to two main parts:

  • Input user interface with:

    • Text box with adequate mask for IPv6 (multiplayer mode);
    • Port Text box (multiplayer mode);
    • Grid layout to choose game mode;
    • Combo boxes to choice game to load or game settings;
    • Button to apply all of the configurations.

    2023-05-19_18h59_43 2023-05-19_19h10_58

    Fig. 1. Inup user interface clear and with example data

  • The game user interface contains:

    • Board section with pieces, labels, and the possibility to change color style;
    • Check / Mate buttons to inform about game status;
    • A text box for inserting moves in chess algebraic notation. Move confirmation could be preceded by “Submit text move button” or pressing Enter in the text box;
    • Light and dark clocks for each player;
    • Continue button to submit proceed move and change clock;
    • Start, Reset and Save Buttons to control the game
    • Additional window to choose pawn promotion.

    2023-05-19_19h06_43

    Fig. 2. The game user interface with pawn promotion window in the center

    2023-05-19_19h07_00

    Fig. 3. The game user interface with second color style

Code

The structure of the project files is as follows:

  • main.py - simple UI with a selection of game mode;
  • server.py - example of IPv6 server for multiplayer connection;
  • configs folder - holding JSON files with saved games configurations;
  • saves folder - holding DB and XML files with games histories;
  • core folder - all main elements of the the chess game;
    • chessBoard.py - a class that creates all pieces objects due to current board set configuration;
    • chessClock.py - a module that creates and updates analog clocks for each player;
    • chessEngine.py - chess logic engine. It takes as input the current board set and games status and gives new ones as output. All chess rules were implemented among others:
      • en passant;
      • promotion;
      • castling;
    • chessPiece.py - this class creates a single chess piece and proceeds with its movement on board. Calculations for holding and releasing a piece are included;
    • gameStaus.py - a class which contains all useful information for all game modes like single, multi, playback etc.;
  • gameModes folder - other useful classes specified in chosen game mode;
    • controllerAI.py - a class which translates current board set to inputs for neural network and proceeds its movement;
    • playBackGame.py - module which retraces all moves from gives DB or XML file;
    • saveGame.py - a class which creates files mentioned in configs and saves;
    • stockEngine.py - implementation of communication wich stockfish engine due to teaching AI model;
  • interaction folder - all modules somehow connected with UI;
    • boardCommunication.py - set of functions which proceed user communication windows;
    • chessGraphics.py - binary file created from .qrc which contains all used graphics;
    • loadGame.py - a main class which proceeds:
      • communication with the player by load.ui interface;
      • history playback triggering;
      • communication by IPv6 protocol;
      • data transfer of text messages;
      • and more minor functionalities;
    • loadui.ui, start.ui - user interfaces;
    • textEngine.py - a translator from chess algebraic notation to chess board coordinates;
  • modelsAI folder - files that are necessary for AI game mode creation not for the game as such;
    • convolutional.py - convolutional neural network teaching model;
    • dataCreation.py - creation of dataset with inputs and outputs for teaching;
    • evolutionary.py - skeleton for future usage of evolutionary algorithm supported bot;

Discussion

To sum up the implementation of the above project, the application implements all the initial assumptions. The undoubted advantages of our solution include:

  • Intuitive interface, the application is legible and does not contain any redundant elements which could confuse the user;
  • A significant amount of game modes single, multi and AI enforced;
  • Changeable graphic layout for board and pieces;
  • Immersive analog clocks;
  • Saving and playback of game status which makes it less binding and more flexible for daily usage;
  • Chess algebraic notation for those who want to learn serious chess tournaments slang;

On the other hand, there are also flaws in the application and eliminating them would be the first step in the further development of the project. Future upgrades that have not yet been undertaken may include:

  • Interface improvements to enhance its aesthetics;
  • Adding a dark background for the entire application, it's standard in today's software to make the background of the UI have at least a light and dark version;
  • Implementation of difficulty levels by the usage of different AI models like for example evolutionary algorithm mentioned in evolutionary.py. Usage of different models should cause the creation of bots with different playstyles not only various skill levels

Thus, the product already has a number of useful functionalities and is fully usable, but there is still a lot of room for future development.