bridge

package
v0.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package bridge is minimal contract bridge (docs/PLAN.md §3, decision 14): WOPR bids all four hands by point count, the player's side always declares (the table turns when East and West hold the cards), and the player plays both declarer's hand and dummy's while WOPR defends. One deal is one game: making the contract wins it.

Index

Constants

View Source
const Opening = 12

Opening is the fewest points that open the bidding.

Variables

View Source
var Lines = []script.Ls{
	lineRules, linePassedOut, lineTurned, lineAuction, lineContract, promptHand, promptDummy, lineNotHeld, lineFollow,
	linePlayHelp, lineFinish, lineLeads, linePlays, lineTrick, lineMade, lineDown, callPass, strainNames, seatNames, panelTitle, panelContract,
	panelTricks, panelDummy, panelLast, panelTaken, panelToPlay, panelVoid, artTitle,
}

Lines is every script block, for the provenance test.

View Source
var Pass = Bid{}

Pass is the call that bids nothing.

Functions

func Auction

func Auction(hands [cards.Seats][]cards.Card, dealer int) (calls []Bid, c Contract, ok bool)

Auction runs WOPR's bidding for all four seats, starting with dealer. The partnership that holds more points (dealer's side on a tie) declares, if one of its players can open: that player bids one of the target strain, partner raises to the target, and everyone else passes. With no opening hand at the table, the deal is passed out. It returns the calls in order and the contract (ok is false when passed out).

func HCP

func HCP(hand []cards.Card) int

HCP counts high-card points: ace 4, king 3, queen 2, jack 1.

func New

func New() games.Game

New returns a game.

func Score

func Score(c Contract, tricks int) int

Score is the declaring side's score, not vulnerable and undoubled: trick points, the part-score or game bonus, slam bonuses and overtricks when made; 50 a trick when down.

Types

type Bid

type Bid struct {
	Level  int
	Strain Strain
}

Bid is a call in the auction. Level 0 is a pass.

func (Bid) Above

func (b Bid) Above(o Bid) bool

Above reports whether b outranks o: a higher level, or the same level in a higher strain.

func (Bid) String

func (b Bid) String() string

String is the call as the auction shows it: 1S, 3NT, PASS.

type Contract

type Contract struct {
	Bid
	Declarer int
}

Contract is the auction's result.

func (Contract) String

func (c Contract) String() string

Contract text: 4S, 3NT.

type Game

type Game struct {
	// contains filtered or unexported fields
}

Game is bridge as a proto.Program.

func (*Game) Handle

func (g *Game) Handle(ev proto.Event) []proto.Output

Handle implements proto.Program.

func (*Game) Start

func (g *Game) Start(env proto.Env) []proto.Output

Start implements proto.Program: deal until someone can open, turn the table if East and West hold more, bid, and lead.

func (*Game) View

func (g *Game) View(c *proto.Canvas)

View implements proto.Program.

type Strain

type Strain uint8

Strain is a bid's denomination: a suit, or no trumps (above spades).

const NT Strain = 4

NT is no trumps. The suits are cards.Clubs to cards.Spades.

func (Strain) Trump

func (s Strain) Trump() cards.Suit

Trump is the trump suit for the play, or cards.NoTrump.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL