Skip to content

CodeClash-ai/Bridge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bridge Arena Game Server

This repository contains the game server and bot examples for the Bridge arena in CodeClash.

Overview

Bridge is a 4-player trick-taking card game played in teams:

  • North/South (positions 0/2) vs East/West (positions 1/3)

Repository Structure

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

Quick Start

  1. Edit bridge_agent.py to implement your bot logic
  2. Test locally:
    python run_game.py bridge_agent.py bridge_agent.py bridge_agent.py bridge_agent.py
  3. Submit to CodeClash!

Bot Interface

Your bot must implement two functions in bridge_agent.py:

get_bid(game_state) -> str

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 bids
  • legal_bids: List of legal bids you can make
  • dealer: Position of the dealer
  • vulnerability: Which teams are vulnerable

Returns: A bid string like "PASS", "1H", "2NT", "3S"

play_card(game_state) -> str

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 hand
  • current_trick: Cards played so far in current trick
  • legal_cards: List of legal cards you can play
  • contract: The current contract (level, suit, declarer)
  • tricks_won: Tricks won by each team so far

Returns: A card string like "AS", "7H", "KD"

Card Notation

  • 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

Bidding

  • Pass: "PASS"
  • Suit bids: Level (1-7) + Suit (C, D, H, S, NT)
    • Examples: "1H", "2NT", "4S", "7NT"

Scoring

Games are scored using standard Bridge scoring rules, then normalized to Victory Points (VP) on a 0-1 scale.

Running Games Locally

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.json

Options:

  • --seed: Random seed for reproducible games
  • --dealer: Dealer position (0-3, default: 0)
  • -o, --output: Output file for results (default: stdout)

Example Bot

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]

License

MIT License - See CodeClash repository for details.

About

Bridge card game server for CodeClash arena

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages