示例#1
0
文件: game_test.go 项目: notnil/joker
func BenchmarkOmahaHiLoShowdown(b *testing.B) {
	p := newPot(4)
	p.contribute(0, 100)
	p.contribute(1, 110)
	p.contribute(2, 120)
	p.contribute(3, 130)

	for i := 0; i < b.N; i++ {
		deck := hand.NewDealer().Deck()
		board := deck.PopMulti(5)
		holeCards := map[int][]*HoleCard{}
		for i := 0; i < 4; i++ {
			holeCards[i] = []*HoleCard{
				newHoleCard(deck.Pop(), Concealed),
				newHoleCard(deck.Pop(), Concealed),
				newHoleCard(deck.Pop(), Concealed),
				newHoleCard(deck.Pop(), Concealed),
			}
		}
		hCards := cardsFromHoleCardMap(holeCards)
		highHands := newHands(hCards, board, OmahaHiLo.get().FormHighHand)
		lowHands := newHands(hCards, board, OmahaHiLo.get().FormLowHand)
		p.payout(highHands, lowHands, hand.SortingHigh, 0)
	}
}
示例#2
0
文件: table.go 项目: notnil/joker
// UnmarshalJSON implements the json.Unmarshaler interface.
func (t *Table) UnmarshalJSON(b []byte) error {
	tJSON := &tableJSON{}
	if err := json.Unmarshal(b, tJSON); err != nil {
		return err
	}

	players := map[int]*PlayerState{}
	for seat, player := range tJSON.Players {
		i, err := strconv.ParseInt(seat, 10, 64)
		if err != nil {
			return err
		}
		players[int(i)] = player
	}

	t.opts = tJSON.Options
	t.dealer = hand.NewDealer()
	t.deck = tJSON.Deck
	t.button = tJSON.Button
	t.action = tJSON.Action
	t.round = tJSON.Round
	t.minRaise = tJSON.MinRaise
	t.board = tJSON.Board
	t.players = players
	t.pot = tJSON.Pot
	t.startedHand = tJSON.StartedHand

	return nil
}
示例#3
0
func TestToAndFronJSON(t *testing.T) {
	t.Parallel()
	register()

	// create table
	opts := table.Config{
		Game: table.Holdem,
		Stakes: table.Stakes{
			SmallBet: 1,
			BigBet:   2,
			Ante:     0,
		},
		NumOfSeats: 6,
		Limit:      table.NoLimit,
	}
	p1 := Player("1", []PlayerAction{})
	tbl := table.New(opts, hand.NewDealer())
	if err := tbl.Sit(p1, 0, 100); err != nil {
		t.Fatal(err)
	}

	// marshal into json
	b, err := json.Marshal(tbl)
	if err != nil {
		t.Fatal(err)
	}
	// unmarshal from json
	tblCopy := &table.Table{}
	if err := json.Unmarshal(b, tblCopy); err != nil {
		t.Fatal(err)
	}

	// marshal back to view
	b, err = json.Marshal(tblCopy)
	if err != nil {
		t.Fatal(err)
	}

	if len(tblCopy.Players()) != 1 {
		t.Fatal("players didn't deserialize correctly")
	}

}
示例#4
0
文件: main.go 项目: notnil/joker
func main() {
	p1 := playerFromInput("Player 1")
	p2 := playerFromInput("Player 2")

	opts := table.Config{
		Game:       table.Holdem,
		Limit:      table.NoLimit,
		Stakes:     table.Stakes{SmallBet: 1, BigBet: 2, Ante: 0},
		NumOfSeats: 2,
	}
	tbl = table.New(opts, hand.NewDealer())
	if err := tbl.Sit(p1, 0, 100); err != nil {
		panic(err)
	}
	if err := tbl.Sit(p2, 1, 100); err != nil {
		panic(err)
	}

	runTable(tbl)
	fmt.Println("DONE")
}
示例#5
0
func TestSeating(t *testing.T) {
	t.Parallel()

	opts := table.Config{
		Game: table.Holdem,
		Stakes: table.Stakes{
			SmallBet: 1,
			BigBet:   2,
			Ante:     0,
		},
		NumOfSeats: 6,
	}

	p1 := Player("1", []PlayerAction{})
	p1Dup := Player("1", []PlayerAction{})
	p2 := Player("2", []PlayerAction{})

	tbl := table.New(opts, hand.NewDealer())

	// sit player 1
	if err := tbl.Sit(p1, 0, 100); err != nil {
		t.Fatal(err)
	}

	// can't sit dup player 1

	if err := tbl.Sit(p1Dup, 1, 100); err != table.ErrAlreadySeated {
		t.Fatal("should already be seated")
	}

	// can't sit player 2 in invalid seat
	if err := tbl.Sit(p2, 6, 100); err != table.ErrInvalidSeat {
		t.Fatal("can't sit in invalid seat")
	}

	// can't sit player 2 in occupied seat
	if err := tbl.Sit(p2, 0, 100); err != table.ErrSeatOccupied {
		t.Fatal("can't sit in occupied seat")
	}
}
示例#6
0
func TestRaises(t *testing.T) {
	t.Parallel()

	opts := table.Config{
		Game: table.Holdem,
		Stakes: table.Stakes{
			SmallBet: 1,
			BigBet:   2,
			Ante:     0,
		},
		NumOfSeats: 6,
	}

	p1 := Player("1", []PlayerAction{})
	p2 := Player("2", []PlayerAction{})
	p3 := Player("3", []PlayerAction{})
	p4 := Player("4", []PlayerAction{})

	tbl := table.New(opts, hand.NewDealer())

	if err := tbl.Sit(p1, 0, 50); err != nil {
		t.Fatal(err)
	}
	if err := tbl.Sit(p2, 1, 100); err != nil {
		t.Fatal(err)
	}
	if err := tbl.Sit(p3, 2, 52); err != nil {
		t.Fatal(err)
	}
	if err := tbl.Sit(p4, 3, 60); err != nil {
		t.Fatal(err)
	}

	// preflop
	p1.Call()
	p2.Call()
	p3.Call()
	p4.Check()

	// flop
	p3.Check()
	p4.Check()
	p1.Bet(48)
	p2.Call()
	p3.Raise(2)
	p4.Raise(8)

	for i := 0; i < 12; i++ {
		if _, _, err := tbl.Next(); err != nil {
			t.Fatal(err)
		}
	}

	if tbl.Action() != 1 {
		t.Fatal("action should be on player 2")
	}

	players := tbl.Players()
	if players[1].CanRaise() {
		t.Fatal("player 2 shouldn't be able to raise")
	}

	p2.Call()
	_, _, err := tbl.Next()
	_, _, err = tbl.Next()
	if err != nil {
		t.Fatal(err)
	}
}