← All projects

Games

War (card game)

Rewrite of a game from my studies: War, the card game, in Ada.

Done Sprint S21 · 3 points
In short, no jargon for non-developersRead the summaryClose
What it is
The card game of war, simulated 100,000 times to answer one question: does a game always end? No, 42 % never do.
What it is for
A game from my studies, rewritten from scratch with the methods of a professional project: automatic tests, versions for several systems.
What it shows
The Ada language, known for its safety, and the art of answering a question by simulation.
Source code

How the pieces fit together

Diagram: Cards → Game (played) ; Game → Terminal (tells) ; Game → Statistics ; Statistics → stats.json (written as JSON) ; stats.json → Project page ; Tests → Game (check). played tells written as JSON check Cards Ada types, contracts Game shuffle, tricks, wars Terminal trick by trick Statistics 100,000 games stats.json read at site build Project page charts Tests AUnit

What 100,000 games say

The Ada program played the 100,000 games of seeds 1 to 100,000, up to 10,000 plies each; the figures come from its output file, recomputed by CI.

of the games never end (42,346 games)
42.4 %
plies on average when the game ends
1,689
wars per game, on average
39.2
of the finished games won by the first player
52.9 %
plies from the shortest to the longest
20 – 9,994

Why so many endless games? Here the winner of a trick always picks the cards up in the same order: the game becomes deterministic and can cycle. Between real players the order changes from trick to trick and the game nearly always ends.

Tech stack

  • Ada
  • Alire
  • AUnit

Who does what

Ada
The game: types that rule out impossible cards, packs with contracts, an xorshift64 shuffle; 100,000 simulated games for the project page's statistics.
Alire
The same GNAT toolchain and AUnit locally and in CI, on the three systems.
AUnit
Tests of the rules, the contracts and the shuffle.

Definition of Done

  • Code reviewed, diff by diff
  • Unit and integration tests green
  • Green CI on Linux, Windows and macOS when compiled
  • README, REVIEW.md and DECISIONS.md up to date
  • Texts in French and English
  • Demo deployed and tested on mobile