This repository contains the game server and bot examples for the Bridge arena in CodeClash.
Bridge is a 4-player trick-taking card game played in teams:
- North/South (positions 0/2) vs East/West (positions 1/3)
Bridge/
├── game_server/ # Core game logic
│ ├── __init__.py # Module exports
│ ├── game.py # BridgeGame class - main game state manager
│ ├── deck.py # Card deck management and comparison
│ └── scoring.py # Bridge scoring rules
├── bridge_agent.py # Starter bot implementation (edit this!)
├── run_game.py # Game runner script for local testing
├── CODECLASH.md # CodeClash arena information
└── README.md
- Edit
bridge_agent.pyto implement your bot logic - Test locally:
python run_game.py bridge_agent.py bridge_agent.py bridge_agent.py bridge_agent.py
- Submit to CodeClash!
Your bot must implement two functions in bridge_agent.py:
Make bidding decisions during the auction phase.
game_state contains:
position: Your position (0=North, 1=East, 2=South, 3=West)hand: List of cards in your hand (e.g.,["AS", "KH", "7D"])bids: List of previous bidslegal_bids: List of legal bids you can makedealer: Position of the dealervulnerability: Which teams are vulnerable
Returns: A bid string like "PASS", "1H", "2NT", "3S"
Play a card during the playing phase.
game_state contains:
position: Your position (0=North, 1=East, 2=South, 3=West)hand: List of cards currently in your handcurrent_trick: Cards played so far in current tricklegal_cards: List of legal cards you can playcontract: The current contract (level, suit, declarer)tricks_won: Tricks won by each team so far
Returns: A card string like "AS", "7H", "KD"
- Cards are represented as 2 characters:
<rank><suit> - Ranks: A, K, Q, J, T (10), 9, 8, 7, 6, 5, 4, 3, 2
- Suits: S (Spades), H (Hearts), D (Diamonds), C (Clubs)
- Examples:
"AS"= Ace of Spades,"7H"= 7 of Hearts,"TD"= 10 of Diamonds
- Pass:
"PASS" - Suit bids: Level (1-7) + Suit (C, D, H, S, NT)
- Examples:
"1H","2NT","4S","7NT"
- Examples:
Games are scored using standard Bridge scoring rules, then normalized to Victory Points (VP) on a 0-1 scale.
Use run_game.py to test your bot:
# Run with 4 copies of your agent
python run_game.py agent1.py agent2.py agent3.py agent4.py
# With options
python run_game.py agent.py agent.py agent.py agent.py --seed 42 --dealer 1 -o result.jsonOptions:
--seed: Random seed for reproducible games--dealer: Dealer position (0-3, default: 0)-o, --output: Output file for results (default: stdout)
The included bridge_agent.py is a simple random bot:
def get_bid(game_state):
legal_bids = game_state.get("legal_bids", ["PASS"])
# Your bidding logic here
return "PASS"
def play_card(game_state):
legal_cards = game_state.get("legal_cards", [])
# Your card playing logic here
return legal_cards[0]MIT License - See CodeClash repository for details.