FourtyTwo

GitHub Pages MIT License Python 3.10+

🌐 Landing Page: https://tuckerbrewer12.github.io/FourtyTwo/

A real-time multiplayer implementation of 42, the classic Texas domino trick-and-trump game invented in 1885.

Quick start: pip install flask flask-socketio eventlet && python server/fourty_two_socketio_server.py β†’ open http://localhost:5000

About the Game

42 is a domino game for four players divided into two teams (players 1 & 3 vs. players 2 & 4). It is played with a standard double-six domino set (28 dominoes). Each hand consists of a bidding phase and a trick-taking phase, similar to the card game Spades.

Scoring

Bidding

Trick Play


GitHub Pages

The static landing page in docs/ is automatically deployed to GitHub Pages via the workflow at .github/workflows/pages.yml. Every push to main redeploys the landing page.

To enable GitHub Pages in your fork:

  1. Go to Settings β†’ Pages
  2. Set Source to GitHub Actions
  3. The next push to main will deploy the site

The landing page is 100% static HTML/CSS/JS β€” no build step required.


Project Structure

FourtyTwo/
β”œβ”€β”€ docs/                   # ← Static GitHub Pages landing page
β”‚   └── index.html
β”œβ”€β”€ .github/workflows/
β”‚   └── pages.yml           # ← Auto-deploy docs/ to GitHub Pages
β”‚
β”œβ”€β”€ domino.py               # Domino class: comparison, value, suit logic
β”œβ”€β”€ domino_set.py           # DominoesSet: full 28-domino set, shuffle & deal
β”œβ”€β”€ player.py               # Player class: hand management, move validation
β”œβ”€β”€ fourty_two_game.py      # FourtyTwo game engine: bidding, trick play, scoring
β”œβ”€β”€ console_game.py         # Interactive CLI game runner
β”‚
β”œβ”€β”€ server/
β”‚   β”œβ”€β”€ fourty_two_socketio_server.py  # Flask-SocketIO real-time multiplayer server
β”‚   └── templates/
β”‚       └── index.html                 # Game SPA frontend
β”‚
β”œβ”€β”€ test_domino.py          # Unit tests for Domino
β”œβ”€β”€ test_domino_set.py      # Unit tests for DominoesSet
β”œβ”€β”€ test_player.py          # Unit tests for Player
β”œβ”€β”€ test_fourty_two.py      # Unit tests for FourtyTwo game logic
β”œβ”€β”€ test_fourty_two_server.py  # Integration tests for Flask API
└── test_stress.py          # Stress / concurrency tests

Setup

Prerequisites

Install dependencies

pip install flask flask-socketio

Running the Game

Console (local play)

python console_game.py

REST API Server

cd server
python fourty_two_server.py

The server starts on http://localhost:5000.


REST API Reference

All endpoints accept and return JSON.

Method Endpoint Description
POST /start Start a new game
POST /join Join the game (returns your player number 1–4)
POST /shuffle Deal dominoes (requires all 4 players joined)
POST /bid Submit a bid {player_num, bid, marks}
GET /get_high_bid Get the current highest bid
POST /set_trump Set trump suit {trump: 0–6}
POST /play Play a domino {player_num, move: [a, b]}
POST /get_hand Get a player’s hand {player_num}
POST /get_trick Get the dominoes in the current trick
POST /get_winner Evaluate the completed trick and update scores
GET /health Health check

Example: start a game and join

curl -X POST http://localhost:5000/start
curl -X POST http://localhost:5000/join -H "Content-Type: application/json" -d '{"name": "Alice"}'
# Returns: {"ok": true, "player_num": 1, "name": "Alice", "players": 1}

Running Tests

python -m unittest discover -v

Tests are written with Python’s built-in unittest framework.


Key Classes

Domino

from domino import Domino

d = Domino([5, 3])
d.value()          # 0 (8 is not divisible by 5)
d.contains(5)      # True
d.high_side()      # 5
d.low_side()       # 3
str(d)             # "[5|3]"

FourtyTwo

from fourty_two_game import FourtyTwo

game = FourtyTwo()
game.join()                  # Player 1 joins
game.shuffle()               # Deal dominoes
game.bid(1, 32)              # Player 1 bids 32
game.set_trump(5)            # Trump is 5s
game.play(1, Domino([5,3]))  # Player 1 plays [5|3]
winner = game.get_trick_winner()
game.set_winner(winner)

Teams