Code Monkey home page Code Monkey logo

dichess's Introduction

Chess Application

Introduction

This application allows users to play chess against each other over a network.

Usage

  1. First Version

    1. Starting the Server and Connecting Clients and Playing the game:
  2. Second version

    1. Starting the Server and Connecting Clients and Playing the game:

Current Status

  • Implemented features:
    • Client-server communication
    • Client vs bot
    • Basic chess gameplay functionality
  • Known issues:
    • The Player against Human button does not work as it doesn't create the correct game mode as the server does not understand it correctly.
    • The Client vs Client game functionality does not work right now, but I am going to continue working on it even after submission.
    • Occasionally, the server disconnects unexpectedly.

Decomposition

Chess Game with Client-Server Architecture

This is a simple implementation of a chess game with a client-server architecture. The server uses the Stockfish chess engine to play against the client. The client is a graphical user interface (GUI) built with Tkinter, allowing the user to play against the server.

Overview

  • client.py: Contains the implementation of the client GUI and logic for handling user input and communicating with the server.
  • server.py: Contains the implementation of the server logic, including handling client connections, managing the game state, and using the Stockfish engine to generate moves.
  • protocol.py: Contains helper functions for encoding and decoding chess moves.

How to Run

  1. Make sure you have Python and Tkinter installed on your system.
  2. Run the server.py file to start the server.
  3. Run the client.py file to start the client GUI.
  4. In the client GUI, choose your opponent (bot or human).
  5. In the client GUI, choose your color (white or black) and click the "Submit" button.
  6. The game will start, and you can make moves by clicking on the squares on the board.

Method Decomposition

client.py

  1. ChessGUI class:

    • __init__(self, root, server_socket, client_color): Initializes the GUI, loads piece images, draws the board, and sets up event handlers.
    • load_images(self): Loads the piece images from the corresponding directories.
    • draw_board(self): Clears the canvas and draws the board with pieces.
    • on_square_click(self, event): Handles the square click event, allowing the user to make moves.
    • receive_moves(self): Receives moves from the server and updates the board.
    • resign(self): Handles the resign button click event, sending a "resign" message to the server.
  2. main() function:

    • Creates a window for the user to choose their color.
    • Establishes a connection with the server.
    • Sends the user's color choice to the server.
    • Creates an instance of the ChessGUI class with the server socket and user's color.
    • Starts the main event loop for the GUI.

server.py

  1. ChessServer class:
    • __init__(self, host, port): Initializes the server with the specified host and port, and creates a Stockfish engine instance.
    • handle_client(self, client_socket, client_color): Handles the game logic for a client connection, including receiving moves, making engine moves, and checking for checkmate.
    • start(self): Starts the server, listens for incoming client connections, and creates a new thread for each client.

protocol.py

  1. encode_move(move): Encodes a chess move as a string.
  2. decode_move(encoded_move): Decodes an encoded move string (not used in the current implementation).
  • Note: I was originally going to make the protocol encode the move into binary, and decode from binary, but I was too stuck with GUI implementation so that idea is for future.

Test Cases Output

  • Screenshots of various test cases showing the application in action are in here.

Requirements and Design Documents

Future Enhancements

  • Implement time controls for games to choose different options to play a 3min/5min/10min games.
  • Add support for player ratings and rankings (leaderboard).
  • Make the leaderboard synchronized through synchronized methods.
  • Improve the user interface for a better gaming experience and make it like an actual desktop application.
  • Fix any known issues above.

dichess's People

Contributors

toji-ut avatar

Watchers

 avatar

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.