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.

render.gno

5.38 Kb · 142 lines
  1package kewrchess_v2
  2
  3import (
  4	"gno.land/p/g1g7dna0gp4nec5rza4q25htj0cjgswrxefp37ep/chess"
  5	"gno.land/p/nt/ufmt/v0"
  6)
  7
  8func Render(path string) string {
  9	output := "# ♟️ KewrChess - Gno.land Edition\n\n"
 10	output += "---\n\n"
 11
 12	// On-chain Matchmaking Queue Status
 13	if len(matchmakingQueue) > 0 {
 14		output += ufmt.Sprintf("### ⏳ Matchmaking Queue (%d players waiting)\n\n", len(matchmakingQueue))
 15		for i, qAddr := range matchmakingQueue {
 16			output += ufmt.Sprintf("- Position #%d: `%s`\n", i+1, qAddr)
 17		}
 18		output += "\n---\n\n"
 19	}
 20
 21	if len(games) == 0 {
 22		output += "Never Sold His Soul wkwk!\n\n"
 23		output += "No active chess games found.\n"
 24		return output
 25	}
 26
 27	for _, g := range games {
 28		output += ufmt.Sprintf("### ⚔️ Game #%d\n", g.id)
 29
 30		statusText := "`PLAYING` 🟢"
 31		if g.status == "WHITE_WON" {
 32			if g.resignedBy != "" {
 33				statusText = "`WHITE WON (Black Resigned)` 🏳️ 🏆"
 34			} else {
 35				statusText = "`WHITE WON` 🏆"
 36			}
 37		} else if g.status == "BLACK_WON" {
 38			if g.resignedBy != "" {
 39				statusText = "`BLACK WON (White Resigned)` 🏳️ 🏆"
 40			} else {
 41				statusText = "`BLACK WON` 🏆"
 42			}
 43		} else if g.status == "DRAW" {
 44			statusText = "`DRAW` 🤝"
 45		}
 46
 47		output += ufmt.Sprintf("> **Status**: %s\n", statusText)
 48
 49		if g.settledBy != "" {
 50			output += ufmt.Sprintf("> ⛓️ **On-Chain Settlement**: Settled by `%s`\n", g.settledBy)
 51		}
 52
 53		if g.status == "PLAYING" && g.drawOfferedBy != "" {
 54			offeredColor := "Black"
 55			if g.drawOfferedBy == g.white {
 56				offeredColor = "White"
 57			}
 58			output += ufmt.Sprintf("> 🤝 **Draw Offer**: Offered by %s (`%s`)\n", offeredColor, g.drawOfferedBy)
 59		}
 60
 61		turnText := "Black (⚫)"
 62		if g.isWhiteTurn {
 63			turnText = "White (⚪)"
 64		}
 65		output += ufmt.Sprintf("> **Turn**: %s\n>\n", turnText)
 66		output += ufmt.Sprintf("> * ⚪ **White**: `%s`\n", g.white)
 67		output += ufmt.Sprintf("> * ⚫ **Black**: `%s`\n\n", g.black)
 68
 69		output += "| | | | | | | | |\n"
 70		output += "| :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: |\n"
 71
 72		for r := 0; r < 8; r++ {
 73			output += "|"
 74
 75			for c := 0; c < 8; c++ {
 76				piece := g.board[r][c]
 77				if piece == "." {
 78					square := "⬜"
 79					if (r+c)%2 != 0 {
 80						square = "🟩"
 81					}
 82					output += ufmt.Sprintf(" <span style=\"font-size:32px;\">%s</span> |", square)
 83				} else {
 84					emoji := chess.GetPieceEmoji(piece)
 85					output += ufmt.Sprintf(" <span style=\"font-size:32px;\">%s</span> |", emoji)
 86				}
 87			}
 88			output += "\n"
 89		}
 90		output += "\n---\n\n"
 91	}
 92
 93	output += "### 💡 How to Play:\n"
 94	output += "```bash\n"
 95	output += "# Join automatic matchmaking queue (Find Match on-chain):\n"
 96	output += "gno call gno.land/r/g1g7dna0gp4nec5rza4q25htj0cjgswrxefp37ep/kewrchess_v2 JoinQueue\n\n"
 97	output += "# Leave / cancel matchmaking queue:\n"
 98	output += "gno call gno.land/r/g1g7dna0gp4nec5rza4q25htj0cjgswrxefp37ep/kewrchess_v2 LeaveQueue\n\n"
 99	output += "# Standard move (default auto-promotion to Queen):\n"
100	output += "gno call gno.land/r/g1g7dna0gp4nec5rza4q25htj0cjgswrxefp37ep/kewrchess_v2 MakeMove \\\n"
101	output += "  --args [gameID] \\\n"
102	output += "  --args [fromRow] --args [fromCol] \\\n"
103	output += "  --args [toRow] --args [toCol]\n\n"
104	output += "# Move with promotion choice (Q = Queen, N = Knight, R = Rook, B = Bishop):\n"
105	output += "gno call gno.land/r/g1g7dna0gp4nec5rza4q25htj0cjgswrxefp37ep/kewrchess_v2 MakeMovePromote \\\n"
106	output += "  --args [gameID] \\\n"
107	output += "  --args [fromRow] --args [fromCol] \\\n"
108	output += "  --args [toRow] --args [toCol] \\\n"
109	output += "  --args \"N\"\n\n"
110	output += "# Resign:\n"
111	output += "gno call gno.land/r/g1g7dna0gp4nec5rza4q25htj0cjgswrxefp37ep/kewrchess_v2 Resign \\\n"
112	output += "  --args [gameID]\n\n"
113	output += "# Offer a draw:\n"
114	output += "gno call gno.land/r/g1g7dna0gp4nec5rza4q25htj0cjgswrxefp37ep/kewrchess_v2 OfferDraw \\\n"
115	output += "  --args [gameID]\n\n"
116	output += "# Accept draw offer:\n"
117	output += "gno call gno.land/r/g1g7dna0gp4nec5rza4q25htj0cjgswrxefp37ep/kewrchess_v2 AcceptDraw \\\n"
118	output += "  --args [gameID]\n\n"
119	output += "# Decline draw offer:\n"
120	output += "gno call gno.land/r/g1g7dna0gp4nec5rza4q25htj0cjgswrxefp37ep/kewrchess_v2 DeclineDraw \\\n"
121	output += "  --args [gameID]\n\n"
122	output += "# Final settlement (Officially settle match result on-chain via move verification):\n"
123	output += "gno call gno.land/r/g1g7dna0gp4nec5rza4q25htj0cjgswrxefp37ep/kewrchess_v2 SettleGame \\\n"
124	output += "  --args [gameID] \\\n"
125	output += "  --args \"e2e4 e7e5 d1h5 b8c6 f1c4 g8f6 h5f7\"   # Full UCI chess move history\n\n"
126	output += "# Confirm settlement result by opponent (Instant approval):\n"
127	output += "gno call gno.land/r/g1g7dna0gp4nec5rza4q25htj0cjgswrxefp37ep/kewrchess_v2 ConfirmSettlement \\\n"
128	output += "  --args [gameID]\n\n"
129	output += "# Dispute fraudulent settlement proposal:\n"
130	output += "gno call gno.land/r/g1g7dna0gp4nec5rza4q25htj0cjgswrxefp37ep/kewrchess_v2 DisputeSettlement \\\n"
131	output += "  --args [gameID]\n\n"
132	output += "# Start turn timer if opponent is AFK / rage quits:\n"
133	output += "gno call gno.land/r/g1g7dna0gp4nec5rza4q25htj0cjgswrxefp37ep/kewrchess_v2 StartTurnTimer \\\n"
134	output += "  --args [gameID] \\\n"
135	output += "  --args \"[current_moves_uci]\"\n\n"
136	output += "# Claim win due to opponent abandonment / timeout:\n"
137	output += "gno call gno.land/r/g1g7dna0gp4nec5rza4q25htj0cjgswrxefp37ep/kewrchess_v2 ClaimTimeout \\\n"
138	output += "  --args [gameID]\n"
139	output += "```\n"
140
141	return output
142}