Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

z10_tournament_filetest.gno

3.62 Kb · 84 lines
 1// PKGPATH: gno.land/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/z10
 2
 3// A round-robin tournament with a bot that crashes: the crash is handled by
 4// step mode and a forfeit, and the tournament still finishes.
 5package z10
 6
 7import (
 8	"testing"
 9
10	"gno.land/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/arena/v2"
11	"gno.land/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/testbots/crasher"
12)
13
14func main(cur realm) {
15	try := func(name string, f func()) { println(name+":", revive(f)) }
16	// act as a wallet: calls from this test now arrive as calls from its owner
17	testing.SetOriginCaller(cur.Address())
18	crasher.RegisterHunter(cross(cur), "t-hunter")
19	crasher.RegisterTrickster(cross(cur), "t-trickster")
20	crasher.Register(cross(cur), "t-crasher")
21
22	id := arena.CreateTournament(cross(cur), "Friday Night <Brawl>", 4)
23	for _, b := range []string{"t-hunter", "t-trickster", "t-crasher"} {
24		arena.JoinTournament(cross(cur), id, b)
25	}
26	try("join twice", func() { arena.JoinTournament(cross(cur), id, "t-hunter") })
27	try("play before start", func() { arena.PlayTournament(cross(cur), id) })
28	arena.StartTournament(cross(cur), id)
29	try("join after start", func() { arena.JoinTournament(cross(cur), id, "t-hunter") })
30
31	for i := 0; i < 6; i++ {
32		a, b, ok := arena.TournamentNext(id)
33		if !ok {
34			break
35		}
36		if a != "t-crasher" && b != "t-crasher" {
37			println("played:", arena.PlayTournament(cross(cur), id))
38			continue
39		}
40		// t-crasher would cancel a one-transaction match: create the match,
41		// then play it in step mode until its move fails.
42		mid := arena.NextTournamentMatch(cross(cur), id)
43		arena.StartStepMode(cross(cur), mid)
44		for j := 0; j < 200; j++ {
45			if revive(func() { arena.SubmitMove(cross(cur), mid) }) != nil {
46				break
47			}
48		}
49		testing.SkipHeights(arena.MoveTimeout + 1)
50		println("forfeit:", arena.ClaimForfeit(cross(cur), mid))
51	}
52	try("play after the end", func() { arena.PlayTournament(cross(cur), id) })
53	println(arena.Render("tournament/1"))
54}
55
56// Output:
57// join twice: t-hunter is already entered
58// play before start: tournament is open for entries
59// join after start: tournament is not open for entries
60// forfeit: #1 t-trickster wins by forfeit: t-crasher missed its move deadline on turn 10
61// forfeit: #2 t-hunter wins by forfeit: t-crasher missed its move deadline on turn 10
62// played: #3 t-hunter 10 - 16 t-trickster, t-trickster wins
63// play after the end: tournament is finished
64// # Tournament #1: Friday Night Brawl
65//
66// **finished** · 3/4 bots · created by `g1hurj7dkh03kd0ezwj2fktpmua023xgv4ya9crn`
67//
68// **Winner: [t-trickster](/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/arena/v2:bot/t-trickster)**
69//
70// ## Table
71//
72// | # | Bot | P | W | D | L | Gold | Pts |
73// |---|---|---|---|---|---|---|---|
74// | 1 | [t-trickster](/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/arena/v2:bot/t-trickster) | 2 | 2 | 0 | 0 | 18:11 | **6** |
75// | 2 | [t-hunter](/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/arena/v2:bot/t-hunter) | 2 | 1 | 0 | 1 | 15:20 | **3** |
76// | 3 | [t-crasher](/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/arena/v2:bot/t-crasher) | 2 | 0 | 0 | 2 | 5:7 | **0** |
77//
78// ## Schedule
79//
80// 1. [#1 t-trickster wins by forfeit: t-crasher missed its move deadline on turn 10](/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/arena/v2:match/1)
81// 2. [#2 t-hunter wins by forfeit: t-crasher missed its move deadline on turn 10](/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/arena/v2:match/2)
82// 3. [#3 t-hunter 10 - 16 t-trickster, t-trickster wins](/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/arena/v2:match/3)
83//
84// [All tournaments](/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/arena/v2:tournaments) · [Back to the arena](/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/arena/v2)