Play chess against the computer — 5 difficulty levels from Novice to Master
Chess is one of the oldest and most celebrated strategy games in human history, with roots stretching back over 1,500 years to 6th-century India where it was known as Chaturanga. From there it spread to Persia, the Islamic world, and eventually medieval Europe, evolving into the game we recognize today. Few activities exercise the human mind as thoroughly as chess — it demands calculation, pattern recognition, strategic planning, tactical creativity, and psychological resilience all at once. Whether you are a complete beginner learning how the pieces move or an experienced club player looking to sharpen your skills, this free online chess game provides a complete, full-featured environment to play, learn, and improve. This chess implementation is built entirely in your browser using a pure JavaScript chess engine — no downloads, no plugins, no server connections required. The engine handles every rule of standard chess: legal move generation for all six piece types, castling (both kingside and queenside) with all qualifying conditions, en passant pawn captures, pawn promotion to queen, rook, bishop, or knight, check detection, checkmate and stalemate detection, the 50-move draw rule, threefold repetition detection, and insufficient material draws. Every move you make is immediately validated against the complete ruleset, so illegal moves are simply not available to click. The AI opponent uses a minimax algorithm with alpha-beta pruning, a classical computer science approach to game tree search. At every position, the engine looks ahead multiple moves, evaluating resulting positions using a combination of material balance (standard centipawn values: Pawn=100, Knight=320, Bishop=330, Rook=500, Queen=900) and piece-square tables that reward good piece placement — knights in the center, bishops on long diagonals, rooks on open files, and kings safely tucked behind pawns. Alpha-beta pruning dramatically reduces the number of positions the engine must examine, allowing deeper searches without sacrificing response time. Five distinct difficulty levels are available. At Novice level, the AI plays entirely random legal moves, making it suitable for complete beginners and children learning the game for the first time. Beginner adds a slight preference for captures but still plays largely randomly — an ideal partner for someone who knows the rules but has not yet developed strategic thinking. Apprentice uses a 2-ply search (looking one full move ahead for each side), making material captures consistently while still missing tactical sequences. Club Player searches 3 plies deep with full piece-square table evaluation, playing at roughly the level of a casual over-the-board player who understands basic strategy. Master level searches 4 plies with move ordering optimizations that significantly improve pruning efficiency, presenting a genuine challenge that will test players rated below ~1500 ELO. The board interface features click-to-move interaction: click any of your pieces to select it (legal destination squares are highlighted with dots), then click the destination square to complete the move. The last move is always highlighted so you can clearly see what the AI just played. When your king is in check, a red glow appears on the king's square as a visual warning. Pawn promotion triggers a dialog where you choose which piece to promote to, or you can enable Auto-Queen in the settings to always promote to a queen automatically without interruption. Five board color themes are available — Classic (the familiar brown wooden look), Tournament (green competition style), Blue, Ocean, and Purple — each with tastefully chosen light and dark square colors. Coordinate labels showing files (a-h) and ranks (1-8) can be toggled on or off. The board can be flipped to view from either player's perspective, and when you choose to play as Black, the board automatically flips so your pieces are at the bottom. The move history panel displays every move in standard algebraic notation (SAN), the universal language of chess: piece moves like Nf3 or Bxc6, pawn moves like e4 or exd5, check annotations with + and checkmate with #, and castling as O-O or O-O-O. You can export the complete game as a PGN (Portable Game Notation) file, which can be loaded into any chess analysis software including Lichess and Chess.com for post-game review. Captured pieces are displayed beside each player's name along with the material advantage score, so you can track who is ahead in material at a glance. The Hint button uses the AI engine to suggest a good move for you — useful when you are stuck or learning. Undo backs up two half-moves (your move and the AI's response) so you can explore alternative lines freely. Statistics tracking records your wins, losses, and draws across sessions using browser local storage, so your record persists between visits.
Understanding Chess
What Is Chess?
Chess is a two-player abstract strategy board game played on an 8×8 grid of 64 squares. Each player begins with 16 pieces: one king, one queen, two rooks, two bishops, two knights, and eight pawns. Players alternate moves, with White always going first. The objective is to checkmate the opponent's king — placing it under attack (check) with no legal escape. If the player to move has no legal moves but is not in check, the game is a draw by stalemate. Chess has a virtually infinite strategic depth despite its simple rules, which is why it has captivated players for over fifteen centuries and continues to be studied, played, and appreciated worldwide by an estimated 600 million people.
How Does the Chess Engine Work?
The AI uses minimax search with alpha-beta pruning. Starting from the current position, it builds a game tree by considering every legal move available to the current player, then every response by the opponent, alternating to the chosen search depth. At the leaf nodes (the end of the search), a static evaluation function assigns a numerical score based on material balance (sum of piece values) and positional factors captured in piece-square tables. Alpha-beta pruning eliminates branches that cannot possibly affect the final choice — if the AI finds a move that's already better than anything the opponent would allow, it stops exploring that branch. This typically reduces the search space by 50–70%, enabling deeper searches in the same time budget. Move ordering (trying captures first) further improves pruning effectiveness.
Key Chess Strategies
Chess strategy operates on several levels simultaneously. In the opening, principles guide development: bring knights before bishops, control the center with pawns and pieces, castle early to tuck the king away safely, and connect your rooks. In the middlegame, tactical motifs — forks, pins, skewers, discovered attacks, and combinations — create decisive advantages through forcing sequences. Strategic thinking focuses on pawn structure (passed pawns are powerful, isolated or doubled pawns are weak), piece activity (a bishop controlling a long diagonal or a rook on an open file is far stronger than the same piece hemmed in by its own pawns), and king safety. The endgame requires precise technique: king activation (the king becomes a powerful piece in the endgame), pawn promotion races, and understanding drawn vs. won positions with reduced material.
Chess Rules: Special Moves and Draws
Three special moves distinguish chess from simpler games. Castling allows the king to move two squares toward a rook while the rook jumps over to the other side — kingside (O-O) or queenside (O-O-O) — provided neither piece has moved, no pieces stand between them, and the king is not in check, does not pass through check, and does not land in check. En passant allows a pawn that has just advanced two squares from its starting position to be captured by an opposing pawn as if it had only moved one square — but only on the very next move. Pawn promotion occurs when a pawn reaches the last rank; it must be promoted to a queen, rook, bishop, or knight. Draws occur by stalemate (no legal moves, not in check), the 50-move rule (50 consecutive moves with no pawn move or capture), threefold repetition (same position with same rights occurring three times), or insufficient mating material.
How to Use
اختر إعداداتك
Select whether to play against the computer (vs Computer) or pass-and-play with a friend (2 Players). If playing against the AI, choose your color (White moves first) and pick a difficulty level from 1 (Novice — random moves) to 5 (Master — deep search). Click New Game to start.
Make Your Moves
Click any of your pieces to select it — small dots appear on all legal destination squares. Click a highlighted square to move there. For captures, the dots appear as corner brackets on occupied squares. The last move is always highlighted in yellow-green so you can track what the AI played.
Use the Game Controls
Click Hint to get an AI-suggested best move highlighted on the board. Click Undo to take back your last move and the AI's response simultaneously. Click Flip to rotate the board 180°. When a pawn reaches the last rank, a promotion dialog appears — choose Queen, Rook, Bishop, or Knight. Enable Auto-Queen in Theme settings to skip the dialog.
Review and Export
Every move is recorded in the Move History panel in standard algebraic notation. After the game ends (checkmate, stalemate, draw, or resign), click Export PGN to download the complete game record as a .pgn file you can load into Lichess, Chess.com, or any chess analysis software for detailed review. Your win/loss/draw statistics are saved automatically.
Frequently Asked Questions
How strong is the AI at the Master difficulty level?
At Master difficulty (level 5), the AI searches 4 moves ahead (4 plies) using minimax with alpha-beta pruning and piece-square table positional evaluation. This makes it roughly equivalent to a casual-to-intermediate club player, around 1200–1600 ELO depending on the position. It will consistently punish obvious blunders, execute basic tactics like forks and pins, and maintain reasonable piece activity. However, it won't find deeply hidden combinations or demonstrate advanced endgame technique, so strong players above 1600 ELO will generally beat it with careful play. Higher depths are computationally expensive in the browser without Web Workers, which is why we cap at 4-ply for responsiveness.
Why did my castling move get rejected?
Castling has six strict preconditions that must all be met: (1) Your king must not have moved previously in the game. (2) The rook on that side must not have moved. (3) There must be no pieces between the king and the rook. (4) Your king must not currently be in check. (5) The square the king passes through must not be attacked by any opponent piece. (6) The square the king lands on must not be attacked. If any condition is violated, castling is not a legal move. The most commonly missed condition is #5 — you cannot castle 'through' an attacked square even if the king's destination is safe.
What is en passant and when can I use it?
En passant is a special pawn capture that can only occur immediately after an opponent pawn makes a double-step advance from its starting rank. If one of your pawns is on the 5th rank (rank 5 for White, rank 4 for Black) and an opponent pawn on an adjacent file advances two squares to land beside your pawn, you may capture it 'in passing' — moving your pawn diagonally forward to the square the opponent pawn skipped over, and removing the opponent pawn from the board. This capture is only legal on the very next move. If you play a different move first, the en passant opportunity is gone. The game shows en passant as a legal move (small dot) when available.
How does the 50-move draw rule work?
The 50-move rule states that if 50 consecutive moves have been played by each side (100 half-moves total) without any pawn move and without any capture, the game is declared a draw. The counter resets to zero every time a pawn is moved or a piece is captured. This rule prevents games from continuing indefinitely in positions where neither side can make progress. In practice it rarely activates in normal games, but it can occur in certain endgame positions — for example, when a king tries to chase down a lone bishop or knight with only a king defending. The engine detects this automatically and announces the draw.
What does PGN export do?
PGN (Portable Game Notation) is the universal standard format for recording chess games. Clicking Export PGN downloads your complete game as a .pgn text file containing the game header information (date, players, result) and every move in standard algebraic notation. You can open this file in Lichess's game import tool, Chess.com's analysis board, ChessBase, or any other chess software to replay the game move by move, run engine analysis to find mistakes, or share the game with others. The PGN file preserves the complete move history with check and checkmate annotations, allowing full post-game review.
Can I play as Black against the computer?
Yes — click the 'Black' button in the color selector at the top of the game. When you play as Black, the board automatically flips so your pieces appear at the bottom (the standard orientation for the player). The computer (playing White) will make the first move immediately after the game starts. You can also click the Flip button at any time to toggle the board orientation without changing which side you are playing. In 2-player local mode, the Flip button is useful for rotating the board between turns so each player always sees their pieces from the bottom.