return best || { x: 5 + Math.random() * 80, y: 5 + Math.random() * 75 };
}
+ shuffle_tiles() {
+ const pool = document.querySelector(".center-pool");
+ if (!pool) return;
+
+ const rect = pool.getBoundingClientRect();
+ const tile_size = 48; /* tile width + gap */
+ const pad = 16; /* padding in px */
+ const usable_w = rect.width - 2 * pad;
+ const usable_h = rect.height - 2 * pad;
+ const cols = Math.max(1, Math.floor(usable_w / tile_size));
+
+ /* Shuffle the tile IDs. */
+ const ids = this.state.center.map(t => t.id);
+ for (let i = ids.length - 1; i > 0; i--) {
+ const j = Math.floor(Math.random() * (i + 1));
+ [ids[i], ids[j]] = [ids[j], ids[i]];
+ }
+
+ const positions = { ...this.state.tile_positions };
+ ids.forEach((id, i) => {
+ const col = i % cols;
+ const row = Math.floor(i / cols);
+ positions[id] = {
+ x: (pad + col * tile_size) / rect.width * 100,
+ y: (pad + row * tile_size) / rect.height * 100
+ };
+ });
+
+ this.setState({ tile_positions: positions });
+ }
+
/*****************************************************
* Keyboard input during claiming *
*****************************************************/
onTouchMove={(e) => this.on_center_touch_move(e)}
onTouchEnd={(e) => this.on_center_touch_end(e)}
onTouchCancel={(e) => this.on_center_touch_end(e)}>
+ {center.length > 0 ? (
+ <svg className="shuffle-btn"
+ onClick={() => this.shuffle_tiles()}
+ viewBox="0 0 24 24" width="24" height="24">
+ <title>Shuffle tiles</title>
+ <defs>
+ <marker id="arr" viewBox="0 0 6 6" refX="3" refY="3"
+ markerWidth="4" markerHeight="4" orient="auto-start-reverse">
+ <path d="M0,0 L6,3 L0,6 Z" fill="currentColor"/>
+ </marker>
+ </defs>
+ <polyline points="2,7 8,7 16,17 22,17"
+ fill="none" stroke="currentColor" strokeWidth="2"
+ strokeLinecap="round" strokeLinejoin="round"
+ markerEnd="url(#arr)"/>
+ <line x1="8.5" y1="16" x2="2" y2="16" fill="none"
+ stroke="currentColor" strokeWidth="2" strokeLinecap="round"/>
+ <line x1="15.5" y1="8" x2="22" y2="8" fill="none"
+ stroke="currentColor" strokeWidth="2" strokeLinecap="round"
+ markerEnd="url(#arr)"/>
+ </svg>
+ ) : null}
{center.length === 0 ? (
<div className="status">
No letters yet. Press the bag to request one.