Skip to content

alazaro/vibe-checkers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

5 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Checkers Game

A fully functional, web-based checkers game built with Next.js, TypeScript, and Tailwind CSS. Play against a friend locally or challenge an AI opponent with three distinct difficulty levels.

Checkers Game TypeScript Tailwind CSS

Features

Core Game Mechanics

  • โœ… Standard American Checkers Rules: Full implementation including mandatory captures
  • โœ… King Promotion: Pieces become kings when reaching the opposite end
  • โœ… Multi-Jump Captures: Support for consecutive jumps in a single turn
  • โœ… Move Validation: Real-time validation ensuring legal moves only
  • โœ… Win Detection: Automatic detection when a player runs out of pieces or valid moves

Gameplay Modes

  • ๐ŸŽฎ Player vs Player: Local multiplayer on the same device
  • ๐Ÿค– Player vs AI: Three difficulty levels
    • Easy: Random move selection
    • Medium: Prioritizes captures and multi-jumps
    • Hard: Minimax algorithm with alpha-beta pruning (looks 4 moves ahead)

User Interface

  • ๐ŸŽจ Beautiful Design: Clean, modern interface with smooth animations
  • ๐Ÿ–ฑ๏ธ Drag & Drop: Native HTML5 drag-and-drop for intuitive piece movement
  • ๐Ÿ‘† Click to Move: Alternative click-based controls
  • ๐Ÿ‘€ Visual Hints: Toggle to show/hide valid moves
  • โ†ฉ๏ธ Undo Function: Revert moves (undoes both player and AI moves in AI mode)
  • ๐Ÿ“ฑ Responsive: Works on desktop, tablet, and mobile devices

Technology Stack

  • Framework: Next.js 16 with App Router
  • Language: TypeScript
  • Styling: Tailwind CSS
  • State Management: React hooks (useReducer, useState, useCallback)
  • Drag & Drop: Native HTML5 Drag and Drop API

Getting Started

Prerequisites

  • Node.js 18.0 or later
  • npm, yarn, or pnpm

Installation

  1. Clone the repository:
git clone <repository-url>
cd checkers
  1. Install dependencies:
npm install
# or
yarn install
# or
pnpm install
  1. Run the development server:

  2. Run the development server:

npm run dev
# or
yarn dev
# or
pnpm dev
  1. Open http://localhost:3000 in your browser

Building for Production

npm run build
npm start

How to Play

Basic Rules

  1. Board Setup: 8x8 board with 12 pieces per player on dark squares
  2. Movement:
    • Regular pieces (men) move diagonally forward one square
    • Kings can move diagonally forward or backward one square
  3. Capturing:
    • Jump over opponent's piece to capture it
    • Multiple jumps are allowed in one turn
    • Mandatory captures: If you can capture, you must
  4. Winning: Eliminate all opponent pieces or block them so they have no legal moves

Controls

  • Drag & Drop: Click and drag your piece to a valid square
  • Click Mode: Click a piece to select it, then click the destination square
  • Valid Moves: Enable "Show Valid Moves" to highlight available moves
  • Undo: Click "Undo Move" to revert the last move
  • New Game: Start a fresh game with Player vs Player or Player vs AI

Project Structure

checkers/
โ”œโ”€โ”€ app/
โ”‚   โ”œโ”€โ”€ layout.tsx          # Root layout with metadata
โ”‚   โ”œโ”€โ”€ page.tsx            # Main game page with state management
โ”‚   โ””โ”€โ”€ globals.css         # Global styles
โ”œโ”€โ”€ components/
โ”‚   โ”œโ”€โ”€ GameBoard.tsx       # 8x8 board grid component
โ”‚   โ”œโ”€โ”€ Square.tsx          # Individual square component
โ”‚   โ”œโ”€โ”€ Piece.tsx           # Draggable piece component
โ”‚   โ”œโ”€โ”€ GameControls.tsx    # Game controls panel
โ”‚   โ””โ”€โ”€ NotificationPanel.tsx # Game status display
โ”œโ”€โ”€ types/
โ”‚   โ””โ”€โ”€ game.ts             # TypeScript type definitions
โ”œโ”€โ”€ utils/
โ”‚   โ”œโ”€โ”€ gameLogic.ts        # Core game rules and validation
โ”‚   โ””โ”€โ”€ ai.ts               # AI opponent logic
โ””โ”€โ”€ public/                 # Static assets

Architecture

State Management

The game uses React's useReducer hook for centralized state management with the following structure:

type GameState = {
  boardState: BoardState;           // 8x8 array of pieces
  currentPlayer: 'red' | 'black';   // Current turn
  winner: 'red' | 'black' | null;   // Game result
  history: GameState[];             // For undo functionality
  showValidMoves: boolean;          // Toggle for hints
  gameMode: 'pvp' | 'pve';          // Game mode
  aiDifficulty: AIDifficulty;       // AI level
  selectedPiece: Position | null;   // Currently selected piece
  validMoves: Position[];           // Available destinations
  message: string;                  // Status message
}

Game Logic

  • initializeBoard(): Sets up the starting position
  • getValidMovesForPiece(): Calculates legal moves (respects mandatory capture rule)
  • validateAndExecuteMove(): Validates and executes a move
  • getMultiJumpCaptures(): Recursively finds all multi-jump sequences
  • checkWinner(): Determines if the game has ended

AI Implementation

Easy Difficulty

  • Selects random valid moves

Medium Difficulty

  • Prioritizes captures over regular moves
  • Chooses the capture with the most pieces if multiple captures available
  • Falls back to random moves when no captures exist

Hard Difficulty

  • Implements Minimax algorithm with alpha-beta pruning
  • Looks ahead 4 moves
  • Evaluation function: (AI pieces - opponent pieces) + (AI kings ร— 1.5 - opponent kings ร— 1.5)
  • Provides challenging gameplay for experienced players

Customization

Styling

The game uses Tailwind CSS for styling. Key colors can be modified in the components:

  • Red pieces: bg-red-600
  • Black pieces: bg-gray-800
  • Board colors: bg-amber-800 (dark) and bg-amber-100 (light)
  • Valid moves: bg-green-400

AI Difficulty

Adjust AI lookahead depth in utils/ai.ts:

const depth = 4; // Increase for harder AI (warning: slower)

Board Size

The game currently supports standard 8x8 boards. Modifying board size would require changes to:

  • initializeBoard() in utils/gameLogic.ts
  • Board dimensions in components/GameBoard.tsx

Future Enhancements

Potential features for future versions:

  • Online multiplayer
  • Game statistics and history
  • Custom themes
  • Sound effects
  • Animation for piece movements
  • Timer for turns
  • International Checkers rules variant
  • Save/load game state
  • Move history notation

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is open source and available under the MIT License.

Deployment

Deploy on Vercel

The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.

Check out the Next.js deployment documentation for more details.

Acknowledgments


Enjoy playing Checkers! ๐ŸŽฎ

About

Vibe coded checkers game

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages