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.

types.gno

2.15 Kb · 51 lines
 1package kewrchess
 2
 3import (
 4	"gno.land/p/g1g7dna0gp4nec5rza4q25htj0cjgswrxefp37ep/chess"
 5)
 6
 7// Game represents an on-chain chess game session
 8type Game struct {
 9	id            int
10	white         address              // Wallet address of White player
11	black         address              // Wallet address of Black player
12	board         chess.Board          // 8x8 chess board from package chess
13	isWhiteTurn   bool                 // True = White's turn, False = Black's turn
14	status        string               // "PLAYING", "WHITE_WON", "BLACK_WON", "DRAW"
15	castling      chess.CastlingRights // Castling rights for White & Black
16	enPassantCol  int                  // Pawn column vulnerable to en passant (-1 if none)
17	drawOfferedBy address              // Address of player offering a draw ("" if none)
18	resignedBy        address              // Address of player who resigned ("" if none)
19	settledBy         address              // Address of player who recorded final settlement on blockchain ("" if not yet)
20
21	// Anti-Cheat Protection: Proposal & Challenge Period
22	proposedBy        address              // Player submitting victory claim
23	pendingStatus     string               // Proposed settlement status ("WHITE_WON", "BLACK_WON", "DRAW")
24	challengeDeadline int64                // Unix timestamp deadline for challenging settlement proposal
25	
26	// Anti-RageQuit Protection: Timeout & Abandonment
27	turnDeadline      int64                // Unix timestamp deadline for opponent's turn response
28	turnChallengedBy  address              // Player demanding turn response due to AFK opponent
29}
30
31// NewGame initializes a new game with the standard chess starting layout
32func NewGame(id int, white, black address) *Game {
33	return &Game{
34		id:                id,
35		white:             white,
36		black:             black,
37		board:             chess.NewInitialBoard(),
38		isWhiteTurn:       true,
39		status:            "PLAYING",
40		castling:          chess.CastlingRights{},
41		enPassantCol:      -1,
42		drawOfferedBy:     "",
43		resignedBy:        "",
44		settledBy:         "",
45		proposedBy:        "",
46		pendingStatus:     "",
47		challengeDeadline: 0,
48		turnDeadline:      0,
49		turnChallengedBy:  "",
50	}
51}