Coder Social home page Coder Social logo

chessai's Introduction

ChessAI

"ChessAI" is an intelligent chess player based on searching algorithms specifically alpha-beta-pruning algorithm. It's a kind of brute-force algorithm as at any node(move) on the tree(game space), it calculates the next move by simply trying every possible move and return the move with the heighst score. you can read full explanation of alpha-beta pruning algorithm in this blog: https://www.javatpoint.com/ai-alpha-beta-pruning

Modules:

ChessAI consists of 3 modules:

  1. Main module
  2. ChessEngine module
  3. AIPlayer module

Main module:

The main module reponsible for creating the user-interface of the game board in addition to animation, sounds, and the actual game loop. It uses the ChessEngine module and AIPlayer module.

ChessEngine module:

It's the actual engine of the chess game. It implements all chess' pieces moves like pawn moves, king moves, etc.

GameState class:

The primary class of ChessEngine module is the GameState class which responsible for all functions of the chess game. including all pieces moves function implementations, calculating all valid moves at each gamestate, and making and undoing a move.

Move class:

the secondary class of ChessEngine is the Move class, it's responsible for storing all information about a particular move like the previous square that a piece was at, and the sqaure that a piece is currently at. e.g. if I moved the left-most white pawn from its default sqaure "a2" one step further, it will be on this square "a3". So, we creating an instance of Move class to store all of these information.

AIPlayer module:

The actual magic of thinking is done here!. As I said there is nothing magical of this intgelligent chess player, it just examines all valid moves at each step and choose the best move that returns the lowest score for his opponent aka maximizing its own score. It implements the minimax algorithm which is a brute-force alogithm but without pruning and that's mean that it examines all the nodes of the gamestate tree. In other words, it examines all of the moves it can make without regarding if this move is maximizing or minimizing the score. you can read full explanation of minimax algorithm in this blog: https://www.javatpoint.com/mini-max-algorithm-in-ai

Used packages:

pygame: for implementing the UI and the actual gameloop.

Example usage:

import pygame as p
p.init()

# This is an example usage of making a gameloop with quit mechanism
running = True
while running:
  for event in p.event.get():
    if event.type == p.QUIT:
      running = False

here is the link of its official documentation: https://www.pygame.org/docs/

chessai's People

Contributors

mohammedaly22 avatar

Stargazers

Muhammad Emad Hanafy avatar

Watchers

 avatar  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.