feat: initialize majiang-rl project
This commit is contained in:
230
majiang_rl/ui/static/index.html
Normal file
230
majiang_rl/ui/static/index.html
Normal file
@@ -0,0 +1,230 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Mahjong RL Viewer</title>
|
||||
<style>
|
||||
:root {
|
||||
--bg: #f7f4ef;
|
||||
--ink: #1f1f1f;
|
||||
--accent: #b4572a;
|
||||
--panel: #ffffff;
|
||||
--muted: #6b6b6b;
|
||||
}
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: "IBM Plex Mono", "Courier New", monospace;
|
||||
background: radial-gradient(circle at 10% 10%, #fdf6e9, var(--bg));
|
||||
color: var(--ink);
|
||||
}
|
||||
header {
|
||||
padding: 24px;
|
||||
border-bottom: 2px solid #e5ddd1;
|
||||
}
|
||||
h1 {
|
||||
margin: 0 0 6px 0;
|
||||
font-size: 22px;
|
||||
letter-spacing: 1px;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
.subtitle {
|
||||
color: var(--muted);
|
||||
font-size: 13px;
|
||||
}
|
||||
.layout {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 2fr;
|
||||
gap: 20px;
|
||||
padding: 20px;
|
||||
}
|
||||
.panel {
|
||||
background: var(--panel);
|
||||
border: 2px solid #e5ddd1;
|
||||
border-radius: 12px;
|
||||
padding: 16px;
|
||||
box-shadow: 4px 6px 0 rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
.controls {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
button {
|
||||
background: var(--accent);
|
||||
color: #fff;
|
||||
border: none;
|
||||
padding: 8px 12px;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
font-weight: 600;
|
||||
}
|
||||
button.secondary {
|
||||
background: #3f3f3f;
|
||||
}
|
||||
.status {
|
||||
font-size: 14px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
.board {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
gap: 12px;
|
||||
}
|
||||
.player {
|
||||
border: 1px dashed #d2c4b2;
|
||||
padding: 10px;
|
||||
border-radius: 10px;
|
||||
}
|
||||
.player h3 {
|
||||
margin: 0 0 6px 0;
|
||||
font-size: 14px;
|
||||
color: var(--accent);
|
||||
}
|
||||
.tiles {
|
||||
font-size: 12px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.label {
|
||||
display: inline-block;
|
||||
min-width: 72px;
|
||||
color: var(--muted);
|
||||
}
|
||||
@media (max-width: 900px) {
|
||||
.layout {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>Mahjong RL Viewer</h1>
|
||||
<div class="subtitle">Playback of a simulated Guobiao round</div>
|
||||
</header>
|
||||
|
||||
<div class="layout">
|
||||
<div class="panel">
|
||||
<div class="controls">
|
||||
<button id="prev">Prev</button>
|
||||
<button id="next">Next</button>
|
||||
<button id="play" class="secondary">Play</button>
|
||||
<span id="counter" class="subtitle"></span>
|
||||
</div>
|
||||
<div id="status" class="status"></div>
|
||||
</div>
|
||||
<div class="panel">
|
||||
<div id="board" class="board"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
let events = [];
|
||||
let idx = 0;
|
||||
let timer = null;
|
||||
|
||||
function describe(event) {
|
||||
if (!event) return "";
|
||||
const type = event.type;
|
||||
if (type === "start") {
|
||||
return "Start of round";
|
||||
}
|
||||
if (type === "discard") {
|
||||
return `Player ${event.player} discarded ${event.tile}`;
|
||||
}
|
||||
if (type === "claim") {
|
||||
return `Player ${event.player} claimed ${event.claim} on ${event.tile} from Player ${event.from_player}`;
|
||||
}
|
||||
if (type === "win") {
|
||||
return `Player ${event.player} wins (${event.reason})`;
|
||||
}
|
||||
if (type === "draw") {
|
||||
return `Round ends in draw (${event.reason})`;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
function tilesToText(tiles) {
|
||||
if (!tiles || tiles.length === 0) return "-";
|
||||
return tiles.join(" ");
|
||||
}
|
||||
|
||||
function renderBoard(snapshot) {
|
||||
const board = document.getElementById("board");
|
||||
board.innerHTML = "";
|
||||
for (let i = 0; i < snapshot.hands.length; i += 1) {
|
||||
const player = document.createElement("div");
|
||||
player.className = "player";
|
||||
const title = document.createElement("h3");
|
||||
title.textContent = `Player ${i}`;
|
||||
const hand = document.createElement("div");
|
||||
hand.className = "tiles";
|
||||
hand.innerHTML = `<span class="label">Hand</span>${tilesToText(snapshot.hands[i])}`;
|
||||
const discards = document.createElement("div");
|
||||
discards.className = "tiles";
|
||||
discards.innerHTML = `<span class="label">Discards</span>${tilesToText(snapshot.discards[i])}`;
|
||||
const melds = document.createElement("div");
|
||||
melds.className = "tiles";
|
||||
melds.innerHTML = `<span class="label">Melds</span>${tilesToText(snapshot.melds[i].flat())}`;
|
||||
const flowers = document.createElement("div");
|
||||
flowers.className = "tiles";
|
||||
flowers.innerHTML = `<span class="label">Flowers</span>${tilesToText(snapshot.flowers[i])}`;
|
||||
player.appendChild(title);
|
||||
player.appendChild(hand);
|
||||
player.appendChild(discards);
|
||||
player.appendChild(melds);
|
||||
player.appendChild(flowers);
|
||||
board.appendChild(player);
|
||||
}
|
||||
}
|
||||
|
||||
function render() {
|
||||
const event = events[idx];
|
||||
if (!event) return;
|
||||
document.getElementById("counter").textContent = `Step ${idx + 1} / ${events.length}`;
|
||||
document.getElementById("status").textContent = `${describe(event)} | Wall: ${event.snapshot.wall_count}`;
|
||||
renderBoard(event.snapshot);
|
||||
}
|
||||
|
||||
function togglePlay() {
|
||||
const button = document.getElementById("play");
|
||||
if (timer) {
|
||||
clearInterval(timer);
|
||||
timer = null;
|
||||
button.textContent = "Play";
|
||||
return;
|
||||
}
|
||||
button.textContent = "Pause";
|
||||
timer = setInterval(() => {
|
||||
idx = Math.min(idx + 1, events.length - 1);
|
||||
render();
|
||||
if (idx >= events.length - 1) {
|
||||
togglePlay();
|
||||
}
|
||||
}, 700);
|
||||
}
|
||||
|
||||
document.getElementById("prev").addEventListener("click", () => {
|
||||
idx = Math.max(0, idx - 1);
|
||||
render();
|
||||
});
|
||||
document.getElementById("next").addEventListener("click", () => {
|
||||
idx = Math.min(events.length - 1, idx + 1);
|
||||
render();
|
||||
});
|
||||
document.getElementById("play").addEventListener("click", togglePlay);
|
||||
|
||||
fetch("steps.json")
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
events = data.events || [];
|
||||
idx = 0;
|
||||
render();
|
||||
})
|
||||
.catch(() => {
|
||||
document.getElementById("status").textContent = "Failed to load steps.json";
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user