Skip to content
DoubleAmperSandPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

Checkers

English draughts in the browser, with an opponent that actually plays. Four levels, streak scoring, statistics kept per level, and a wooden board that works in light or dark.

No build step, no dependencies, no assets to download. The board and the pieces are drawn in CSS, the sound is synthesised with the Web Audio API, and the opponent searches in a Web Worker so nothing stutters while it thinks.

Running it

git clone https://github.com/DoubleAmperSand/Checkers.git
cd Checkers
npx http-server . -p 8080
# then visit http://127.0.0.1:8080

Opening index.html directly works too, minus offline caching. Because everything is static, GitHub Pages will host it as-is: enable Pages on the repository root — no workflow required.

Playing

You are red, at the bottom, and you move first.

  • Tap a piece to pick it up, then tap where it should go. Drag works too.
  • The pieces that can move are ringed, and their destinations are dotted. When a capture is available the obliged pieces pulse instead — turn this off under Show moves in settings if you would rather work it out yourself.
  • A multi-jump is taken one hop at a time. When only one continuation is left it plays itself, because there was never a choice to make.
  • Keyboard: u or ⌘/Ctrl-Z undoes, h asks for a hint, n starts a new game, Esc closes a dialog.
  • Undo takes back the whole exchange — your move and the reply — so it is your turn again on the position you were actually looking at.

The rules

Standard English draughts, including the parts that are easy to get wrong:

  • Men move one square diagonally forward, and capture by jumping an adjacent enemy piece to the empty square beyond.
  • Captures are compulsory. If any jump exists anywhere on the board the quiet moves are not offered at all.
  • A jump that can continue must continue, and the whole chain counts as a single move.
  • A man reaching the far row is crowned, and the move ends there — it does not carry on jumping as a king. This is the English rule, not the international one.
  • Kings move and capture in all four diagonal directions.
  • You win by taking every enemy piece or by leaving your opponent with no legal move — a player who is completely blocked has lost, pieces or not.
  • Drawn after forty moves each with no capture and no man moved, or when the same position occurs three times.

Move generation is verified against the published perft counts for English draughts from the starting position: 7, 49, 302, 1469, 7361, 36768, 179740 and 845931 at depths one to eight.

The opponent

Negamax with alpha/beta, iterative deepening under a time budget, and two extensions that matter more in draughts than in chess: a forced move costs no depth, and the search never stops in the middle of an exchange — because captures are compulsory, a position with a jump available has no quiet alternative to compare against, and stopping there would score half a trade as though the rest never happened.

Level Depth Budget Character
Novice 3 220 ms Chooses from among the near-best moves, so it misses things
Casual 5 420 ms Sees the obvious traps
Sharp 9 900 ms Counts the exchange out before starting one
Ruthless 15 1800 ms Plays the endgame

The easier levels are not simply shallower. They search properly and then pick from the moves that are close to best, so they play like someone who missed something rather than like a broken engine.

Positions are hashed incrementally (Zobrist), so playing and unplaying a move during the search costs a few integer operations rather than rebuilding a key from all thirty-two squares.

Scoring

Event Points
Enemy man taken 40
Enemy king taken 85
Each extra piece in a multi-jump 60
One of yours crowned 120
One of yours taken −15
Undo / hint −60 / −80

Each capturing move in a row raises your streak, which multiplies everything up to ×3. Losing a piece breaks it, so an exchange that comes out even still costs you the run. Winning pays 1,200 plus bonuses for finishing quickly, for the pieces you have left, and for needing no help. Every award is multiplied by the level, from ×1 up to ×4 for Ruthless.

Statistics

Games played, won, drawn and lost, win rate, current and best win streak, fastest win and most pieces left are counted per level and overall, and shown from Statistics on the home screen. A game counts when it ends — including one walked away from part-way through, which counts as a loss. Starting a game and changing your mind before moving anything is not a game and counts nothing.

URL parameters

  • ?level=novice|casual|sharp|ruthless
  • ?pos=<position> — the compact position string, one character per dark square, then the side to move and the quiet-ply count

For example ?level=sharp&pos=00000000000000000000100000000000r0.

Layout

index.html            markup and dialogs
css/style.css         the token-based design system, light and dark
js/rules.js           board, move generation, compulsory captures, draws
js/ai.js              negamax search and evaluation
js/worker.js          the search, off the main thread
js/view.js            squares, pieces, animation, tap and drag input
js/score.js           scoring, streaks, high scores and statistics
js/fx.js              particles and the winning shower
js/sound.js           synthesised sound effects
js/app.js             screens, turn order, settings
sw.js                 precaches everything for offline play

Only the thirty-two dark squares are ever used, so the board is a thirty-two-cell array rather than sixty-four and every neighbour is a table lookup. The view lays everything out in percentages of the board, so resizing and rotating cost nothing and there is no measurement code to get wrong.

Offline

The service worker precaches every shipped file and serves cache-first, so once loaded the game runs with no network at all — including the search worker, so the opponent still plays. Bump CACHE in sw.js on any change or users keep the old cached version.

Licence

MIT — see LICENSE.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages