-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
279 lines (259 loc) · 10.2 KB
/
Copy pathindex.html
File metadata and controls
279 lines (259 loc) · 10.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>cube-state-engine — Rubik's cube state tracking</title>
<meta
name="description"
content="A dependency-free JavaScript engine that tracks Rubik's cube state across every move, reports what's solved, and breaks a recorded solve into stages."
/>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Archivo:wght@400;500;600;700;800&family=Martian+Mono:wght@400;500;600;700&display=swap"
rel="stylesheet"
/>
<link href="styles.css" rel="stylesheet" />
<script src="https://cdn.cubing.net/v0/js/cubing/twisty" type="module"></script>
</head>
<body>
<header class="masthead">
<div class="shell masthead__inner">
<span class="wordmark">cube<span>-state-</span>engine</span>
<nav class="masthead__links">
<a href="https://www.npmjs.com/package/cube-state-engine">npm</a>
<a href="https://github.com/bryanlundberg/cube-state-engine">GitHub</a>
<a href="https://github.com/bryanlundberg/NexusTimer">NexusTimer</a>
</nav>
</div>
</header>
<main>
<section class="shell hero">
<h1>A Rubik's cube, held in memory.</h1>
<p class="hero__lead">
Feed it moves and it tells you what the cube looks like, which stages
are solved, and how a recorded solve was actually put together.
</p>
<p class="facts">
<span><b>0</b> runtime dependencies</span>
<span><b>3x3</b> and <b>2x2</b></span>
<span>CJS + ESM + types</span>
<span>MIT</span>
</p>
<div class="install">
<code id="install-cmd">npm install cube-state-engine</code>
<button class="copy" id="copy-btn" type="button">Copy</button>
</div>
</section>
<!-- ===================== live instrument ===================== -->
<section class="shell section">
<div class="section__head">
<h2>Turn the cube</h2>
<p class="prose">
The 3D view, the flat net and the checks below all read from one
<code>CubeEngine</code> instance. Press a key, or scramble it.
</p>
</div>
<div class="rig">
<div class="panel">
<div class="panel__bar">
<span class="label">3D view</span>
<span class="label">cubing.js</span>
</div>
<div class="viewport">
<twisty-player
control-panel="none"
back-view="top-right"
background="none"
></twisty-player>
</div>
</div>
<div class="panel">
<div class="panel__bar">
<span class="label">state()</span>
<span class="label" id="net-size">3 x 3</span>
</div>
<div class="panel__body">
<div class="net" id="net"></div>
</div>
</div>
<div class="panel">
<div class="panel__bar"><span class="label">Readout</span></div>
<div class="panel__body">
<div class="readout">
<div class="readout__row">
<span class="label">isSolved()</span>
<span
class="readout__val"
id="is-solved"
data-state="true"
aria-live="polite"
>true</span
>
</div>
<div class="readout__row">
<span class="label">Moves recorded</span>
<span class="readout__val" id="move-count">0</span>
</div>
<div class="readout__row">
<span class="label">simplifyMoves()</span>
<span class="readout__val" id="simplified-count">0</span>
</div>
<div class="readout__row">
<p class="history" id="history"></p>
</div>
</div>
</div>
</div>
<div class="panel">
<div class="panel__bar">
<span class="label">Predicates</span>
<span class="label">live</span>
</div>
<div class="panel__body">
<ul class="lamps" id="lamps"></ul>
</div>
</div>
<div class="panel rig__wide">
<div class="panel__bar">
<span class="label">Controls</span>
<div class="controls">
<button class="btn" id="scramble-btn" type="button">Scramble</button>
<button class="btn" id="reset-btn" type="button">Reset cube</button>
<button
class="btn"
id="auto-btn"
type="button"
aria-pressed="false"
>
Auto-turn
</button>
</div>
</div>
<div class="panel__body">
<p class="label" style="margin-bottom: 0.75rem">Keyboard</p>
<div class="keys" id="keys"></div>
</div>
</div>
</div>
</section>
<!-- ===================== analyzer ===================== -->
<section class="shell section">
<div class="section__head">
<h2>Break a solve into stages</h2>
<p class="prose">
Hand <code>analyzeSolution()</code> a timed move list and it replays
the solve, works out which method was used, and reports when each
stage finished. This is a real recorded solve from the test suite.
</p>
</div>
<div class="panel">
<div class="panel__bar">
<span class="label" id="analysis-src">test/cfop-1.json</span>
<span class="label" id="analysis-method">analyzing…</span>
</div>
<div class="panel__body analysis" id="analysis"></div>
</div>
</section>
<!-- ===================== api ===================== -->
<section class="shell section">
<div class="section__head">
<h2>The API</h2>
<p class="prose">
Everything is a named export. Predicates accept a
<code>CubeEngine</code>, a <code>state()</code> object, or a flat
sticker array.
</p>
</div>
<div class="api">
<div class="api__group">
<h3>Engine</h3>
<ul>
<li>
<b>new CubeEngine(scramble?, { size })</b>
<em>Size 2 or 3. The scramble is applied but not recorded.</em>
</li>
<li>
<b>applyMoves(seq, { record })</b>
<em>U D L R F B, wide Uw Dw Lw Rw Fw, slices M E S, rotations x y z, with ' and 2.</em>
</li>
<li><b>state()</b><em>Six faces as color matrices.</em></li>
<li><b>isSolved()</b><em>Every face a single color.</em></li>
<li><b>getMoves(asString?)</b><em>Move history.</em></li>
<li><b>reset()</b><em>Back to solved, history cleared.</em></li>
<li>
<b>rotateU / D / L / R / F / B</b>
<em>Plus Uw Dw Lw Rw Fw, M E S, and X Y Z. Each takes a clockwise flag.</em>
</li>
</ul>
</div>
<div class="api__group">
<h3>Predicates</h3>
<ul>
<li><b>isCubeSolved(cube)</b></li>
<li><b>isCrossComplete(cube, { color })</b></li>
<li><b>isF2LComplete(cube, { cross })</b></li>
<li><b>isLastLayerOriented(cube, { face })</b></li>
<li><b>areLastLayerCornersSolved(cube, { face })</b></li>
<li>
<b>matchesGoal(cube, goal)</b>
<em>full · cross · f2l · oll · oll+cp, or your own function.</em>
</li>
<li>
<b>getCubeGeometry(size)</b>
<em>Derived edges, corners, neighbors and opposites.</em>
</li>
</ul>
</div>
<div class="api__group">
<h3>Analysis</h3>
<ul>
<li>
<b>analyzeSolution(moves, { size })</b>
<em>Detects CFOP and Roux. Reports per-stage timing and TPS.</em>
</li>
<li>
<b>simplifyMoves(moves)</b>
<em>Joins identical quarter turns into doubles. Never cancels.</em>
</li>
<li>
<b>invertSequence(tokens)</b>
<em>Reverses and inverts a move list.</em>
</li>
<li>
<b>getMovePermutations(size)</b>
<em>The cached permutation tables the engine runs on.</em>
</li>
</ul>
</div>
</div>
<pre class="code" style="margin-top: var(--gap)"><i>// How this page is wired</i>
<u>import</u> { CubeEngine, matchesGoal, simplifyMoves } <u>from</u> <b>"cube-state-engine"</b>;
<u>const</u> cube = <u>new</u> CubeEngine();
<u>function</u> onKey(move) {
cube.applyMoves(move, { record: <b>true</b> });
paintNet(cube.state());
player.alg = cube.getMoves();
solvedEl.textContent = cube.isSolved();
crossLamp.dataset.on = matchesGoal(cube, <b>"cross"</b>);
countEl.textContent = simplifyMoves(cube.getMoves(<b>false</b>)).length;
}</pre>
</section>
</main>
<footer class="shell footer">
<p>
Built by
<a href="https://github.com/bryanlundberg">Bryan Lundberg</a>. Powers the
solve tracking in
<a href="https://github.com/bryanlundberg/NexusTimer">NexusTimer</a>.
</p>
<nav>
<a href="https://www.npmjs.com/package/cube-state-engine">npm</a>
<a href="https://github.com/bryanlundberg/cube-state-engine">Source</a>
<a href="https://github.com/bryanlundberg/cube-state-engine/blob/main/LICENSE">MIT</a>
</nav>
</footer>
<script src="main.js" type="module"></script>
</body>
</html>