Skip to content

alaharilakshyan/AI_vs_Chess

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chess Game with AI

A chess game implementation with a built-in AI opponent.

Features

  • Play chess against a built-in AI opponent
  • Choose to play as white or black pieces
  • Undo moves
  • Restart game at any time
  • Move history tracking
  • Visual move highlighting
  • Modern and clean UI
  • Proper chess piece movement rules
  • Turn-based gameplay

Setup and Play

  1. Open index.html in your web browser
  2. Choose your color:
    • Click "Play as White" to move first
    • Click "Play as Black" to let AI move first
  3. On your turn:
    • Click on one of your pieces to select it
    • Valid moves will be highlighted in green
    • Click on a highlighted square to make your move
  4. The AI will automatically make its move after you
  5. Use the controls:
    • "Undo Move" to take back your last move
    • "Restart Game" to start a new game

Game Rules

  • Standard chess piece movements:
    • Pawns: Forward one square (or two on first move), capture diagonally
    • Rooks: Any number of squares horizontally or vertically
    • Knights: L-shaped movement (two squares in one direction, one square perpendicular)
    • Bishops: Any number of squares diagonally
    • Queens: Any number of squares in any direction
    • Kings: One square in any direction
  • White always moves first
  • Players take turns moving one piece at a time
  • Pieces capture by moving to an opponent's square

AI Behavior

The AI makes decisions based on:

  • Material value (pawns=1, knights/bishops=3, rooks=5, queens=9)
  • Position evaluation:
    • Capturing opponent pieces
    • Controlling the center
    • Advancing pawns
    • Strategic positioning
  • Includes some randomness for varied gameplay

Technical Details

  • Built with vanilla JavaScript
  • No external dependencies or API keys required
  • Responsive design
  • Unicode chess pieces
  • Lightweight and fast

Future Improvements

  • Check and checkmate detection
  • Special moves (castling, en passant)
  • Pawn promotion
  • More sophisticated AI strategy
  • Game end conditions
  • Save/load game state

License

MIT License

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published