Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

render.gno

5.93 Kb · 155 lines
  1package kewrchess
  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 JoinQueue \\\n"
 97	output += "  --args \"[your_address]\"\n\n"
 98	output += "# Leave / cancel matchmaking queue:\n"
 99	output += "gno call gno.land/r/g1g7dna0gp4nec5rza4q25htj0cjgswrxefp37ep/kewrchess LeaveQueue \\\n"
100	output += "  --args \"[your_address]\"\n\n"
101	output += "# Standard move (default auto-promotion to Queen):\n"
102	output += "gno call gno.land/r/g1g7dna0gp4nec5rza4q25htj0cjgswrxefp37ep/kewrchess MakeMove \\\n"
103	output += "  --args \"[your_address]\" \\\n"
104	output += "  --args [gameID] \\\n"
105	output += "  --args [fromRow] --args [fromCol] \\\n"
106	output += "  --args [toRow] --args [toCol]\n\n"
107	output += "# Move with promotion choice (Q = Queen, N = Knight, R = Rook, B = Bishop):\n"
108	output += "gno call gno.land/r/g1g7dna0gp4nec5rza4q25htj0cjgswrxefp37ep/kewrchess MakeMovePromote \\\n"
109	output += "  --args \"[your_address]\" \\\n"
110	output += "  --args [gameID] \\\n"
111	output += "  --args [fromRow] --args [fromCol] \\\n"
112	output += "  --args [toRow] --args [toCol] \\\n"
113	output += "  --args \"N\"\n\n"
114	output += "# Resign:\n"
115	output += "gno call gno.land/r/g1g7dna0gp4nec5rza4q25htj0cjgswrxefp37ep/kewrchess Resign \\\n"
116	output += "  --args \"[your_address]\" \\\n"
117	output += "  --args [gameID]\n\n"
118	output += "# Offer a draw:\n"
119	output += "gno call gno.land/r/g1g7dna0gp4nec5rza4q25htj0cjgswrxefp37ep/kewrchess OfferDraw \\\n"
120	output += "  --args \"[your_address]\" \\\n"
121	output += "  --args [gameID]\n\n"
122	output += "# Accept draw offer:\n"
123	output += "gno call gno.land/r/g1g7dna0gp4nec5rza4q25htj0cjgswrxefp37ep/kewrchess AcceptDraw \\\n"
124	output += "  --args \"[your_address]\" \\\n"
125	output += "  --args [gameID]\n\n"
126	output += "# Decline draw offer:\n"
127	output += "gno call gno.land/r/g1g7dna0gp4nec5rza4q25htj0cjgswrxefp37ep/kewrchess DeclineDraw \\\n"
128	output += "  --args \"[your_address]\" \\\n"
129	output += "  --args [gameID]\n\n"
130	output += "# Final settlement (Officially settle match result on-chain via move verification):\n"
131	output += "gno call gno.land/r/g1g7dna0gp4nec5rza4q25htj0cjgswrxefp37ep/kewrchess SettleGame \\\n"
132	output += "  --args \"[your_address]\" \\\n"
133	output += "  --args [gameID] \\\n"
134	output += "  --args \"e2e4 e7e5 d1h5 b8c6 f1c4 g8f6 h5f7\"   # Full UCI chess move history\n\n"
135	output += "# Confirm settlement result by opponent (Instant approval):\n"
136	output += "gno call gno.land/r/g1g7dna0gp4nec5rza4q25htj0cjgswrxefp37ep/kewrchess ConfirmSettlement \\\n"
137	output += "  --args \"[your_address]\" \\\n"
138	output += "  --args [gameID]\n\n"
139	output += "# Dispute fraudulent settlement proposal:\n"
140	output += "gno call gno.land/r/g1g7dna0gp4nec5rza4q25htj0cjgswrxefp37ep/kewrchess DisputeSettlement \\\n"
141	output += "  --args \"[your_address]\" \\\n"
142	output += "  --args [gameID]\n\n"
143	output += "# Start turn timer if opponent is AFK / rage quits:\n"
144	output += "gno call gno.land/r/g1g7dna0gp4nec5rza4q25htj0cjgswrxefp37ep/kewrchess StartTurnTimer \\\n"
145	output += "  --args \"[your_address]\" \\\n"
146	output += "  --args [gameID] \\\n"
147	output += "  --args \"[current_moves_uci]\"\n\n"
148	output += "# Claim win due to opponent abandonment / timeout:\n"
149	output += "gno call gno.land/r/g1g7dna0gp4nec5rza4q25htj0cjgswrxefp37ep/kewrchess ClaimTimeout \\\n"
150	output += "  --args \"[your_address]\" \\\n"
151	output += "  --args [gameID]\n"
152	output += "```\n"
153
154	return output
155}