-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4direction.html
388 lines (384 loc) · 8.88 KB
/
4direction.html
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="keywords" content="wtf2l f2l oll pll trainer rubiks cube timer main page cubing speedcubing speedsolving fast fridrich method cfop">
<meta name="description" content="WTF2L cube algs">
<title>WTF2L Cube Algs</title>
<title>F2L Trainer</title>
<style type="text/css">
<!--
#stat { position:absolute; left:5px; top:5px; }
-->
</style>
<script language="JavaScript" src="jquery-1.3.2.min.js"></script>
<script language="JavaScript">
var f2lfd = "nnnnunnnnnnnrrrrrrnnnffffffdddddddddnnnllllllnnnbbbbbb"; // F2L的面定义
var imgsize = 120; //题目图片大小
var excount = 18; //题目数量
// 246 240 230 F6 F0 E6
var imgurl = "http://cube.crider.co.uk/visualcube.php?size=" + imgsize + "&fmt=png&bg=EEE";
var scheme = "yrbwog"; // 白底
var alg_pos = 0; // 任意槽
var alg_slot = 5; // 无空槽
var view = "";
var ms = 0;
var state = 2;
var displayidx = 0;
var imgload = 0;
var algs = new Array(
"",
"(R U' U' R' U)2 y'(R' U' R)",
"(U R U' R' U') y'(R' U R)",
"y U'(L' U L U)y' (R U' R')",
"(R U R' U')(R U'U' R' U')(R U R')",
"(R U' R U)y(R U' R' F2)",
"y'(R' U' R U)(R' U' R)",
"(R U' R' U)(R U' R')",
"(R U'U')(R U R' U)(R U'U')R2",
"R2 y(R U R' U')y'(R' U R')",
"y' (R' U)(R U')(R' U R)",
"(R U R' U' )(R U R')",
"(R U R' U')2 (R U R')",
"d' z U'(R2 U)(R' U' R U)z'",
"y'(R' U2)(R U R' U')R",
"(R U' R') y' (R' U2 R)",
"F' L' U2 r U x'",
"y' (U2 R2' U2)(R U R' U R2)",
"(U2 R2' U2)(R' U' R U' R2)",
"R y (R U2 R' F')",
"U(R U'U')(R' U R U' )R' ",
"(R U'U')(R' U' R U)R'",
"U'(R U')(R' U2)(R U' R')",
"U' (R U R') d (R' U' R)",
"d (R' U R U')(R' U' R)",
"y' (R' U' R)",
"(R2 U)y(R U' R' F2)",
"y' (R U'U')R'2 U' R2 U' R'",
"y' (R' U)(R d' U')(R U R')",
"y' R2 y'(R' U' R U)y R2",
"U' (R U'U')(R' U2)(R U' R')",
"U R U' R'",
"U' (R U'U' R' U)(R U R')",
"d (R' U' R) d' (R U R')",
"x(U R' U' l)",
"R2 y (R U R' U')y' R2",
"d (R' U2)(R U'U')(R' U R)",
"(R U' R' U)(d R' U' R)",
"(R U R')",
"y' (R2 U')(F' U F)R2",
"(R' U2)(R2' U)(R2' U R)",
"U' (R U' R' U)(R U R')"
);
// 统计信息
var stat = {
"totalcount":0,
"totaltime":0,
"counts":[0,0,0,0],
"times":[0,0,0,0],
"current":0
};
$(function(){
for(var i = 0; i < algs.length; i++) {
algs[i] = normalalg(algs[i]);
}
$("#startbutton").click(start);
$("#stopbutton").click(stop);
$(document).keydown(function(evt){
if(state != 2 && evt.keyCode == 32) {
ondown();
}
});
$(document).keyup(function(evt){
if(state != 2 && evt.keyCode == 32) {
onup();
}
});
$("#subject").append("<img id=\"img\" src=\"\" width="+imgsize+" height="+imgsize+"/>");
$("#subject img").load(imgonload);
changesubject(0);
// init subject
$("#scheme").change(function(){
scheme = this.value;
changesubject(0);
});
$("#alg_pos").change(function(){
alg_pos = this.value;
changesubject(0);
});
$("#alg_slot").change(function(){
alg_slot = this.value;
changesubject(0);
});
displaytime();
});
function updatestat(ms)
{
stat.totalcount++;
stat.totaltime+=ms;
stat.counts[stat.current]++;
stat.times[stat.current]+=ms;
var str = "";
str += "次数:"+stat.totalcount+"<br/>";
str += "平均:"+second2str(stat.totaltime/stat.totalcount)+"<br/>";
var a = ["FR","BR","BL","FL"];
for(var i = 0; i < 4; i++)
str += a[i]+":"+second2str(stat.times[i]/stat.counts[i])+"/"+stat.counts[i]+"<br/>";
$("#stat").html(str);
}
// 标准化公式,去括号空格
function normalalg(alg) {
var re;
re = /\(([udlrfbMESxyz'\s]*)\)\s*2/gi;
alg = alg.replace(re, "$1$1");
alg = alg.replace(/[\s\(\)]/g,"");
alg = alg.replace(/(\w)(')(2)/g,"$1$3$2");
return alg;
//debug(alg+"<br/>");
}
function debug(str)
{
document.getElementById("debug").innerHTML+=str;
}
function debugimg(img)
{
document.getElementById("debug").innerHTML+="<img src=\""+img+"\"/>";
}
function getcube(index) {
var cube = new Object();
cube.sch = scheme;
cube.view = view;
cube.fd = f2lfd;
if(alg_pos == 0) {
pos = Math.floor(Math.random() * 4);
} else {
pos = alg_pos - 1;
}
if(alg_slot == 0) {
slot = Math.floor(Math.random() * 4);
} else {
slot = alg_slot - 1;
}
alg = algs[index];
// 随机选择颜色和U层方位
r = Math.floor(Math.random() * 4);
while(r--) alg += "y";
r = Math.floor(Math.random() * 4);
while(r--) alg = "U" + alg;
if(pos == 0) {
cube.r = "y30x-34";
} else if(pos == 1) {
alg = "y" + alg;
cube.r = "y30x-34";
} else if(pos == 2) {
alg = "y2" + alg;
cube.r = "y-30x-34";
} else if(pos == 3) {
alg = "y'" + alg;
cube.r = "y30x-34";
}
// 槽位受到旋转影响
if(slot != pos && slot < 4) {
slot = (slot - pos + 4) % 4;
var a = cube.fd.split("");
if(slot == 0) {
a[12]=a[15]=a[23]=a[26] = 'n';
} else if(slot == 1) {
a[14]=a[17]=a[48]=a[51] = 'n';
} else if(slot == 2) {
a[39]=a[42]=a[50]=a[53] = 'n';
} else if(slot == 3) {
a[21]=a[24]=a[41]=a[44] = 'n';
}
cube.fd = a.join("");
}
stat.current = pos;
cube['case'] = alg;
//cube.r = "";
return cube2str(cube);
}
function cube2str(cube) {
var s = "";
for(key in cube) {
s += "&"+key+"="+cube[key];
}
return s;
}
function changesubject(r) {
imgload = 0;
$("#subject img").each(function(i){
var s;
if(r == undefined)
r = Math.floor(Math.random() * (algs.length - 1)) + 1;
s = getcube(r);
this.src = imgurl + s;
});
}
function displaytime()
{
setTimeout("displaytime();", 10);
if (state == 1)
{
now = new Date();
ms = now.getTime() - then.getTime();
displayidx++;
displayidx %= 6;
if(displayidx == 0)
drawtime(ms);
}
}
function second2str(diff)
{
if(isNaN(diff)) return "--:--.--";
totalsec=Math.floor(diff/1000);
sec=totalsec%60;
if(sec<10)
{
secdis="0"+sec;
}
else
{
secdis=sec;
}
min=(totalsec-sec)/60;
if (min<10)
{
mindis="0"+min;
}
else
{
mindis=min;
}
subsec=Math.floor((diff%1000)/10);
if (subsec<10)
{
subsecdis="0"+subsec;
}
else
{
subsecdis=subsec;
}
nowSeconds=mindis+":"+secdis+"."+subsecdis;
return nowSeconds;
}
function drawtime(diff)
{
var nowSeconds = second2str(diff)
document.getElementById("watch").innerHTML=nowSeconds;
}
function start()
{
if (state == 2)
{
$("#startbutton").attr("disabled","disabled");
$("#stopbutton").removeAttr("disabled");
$("#startbutton").val("按空格键开始");
state = 0;
imgload = 0;
}
}
function stop()
{
if (state == 0 || state == 1)
{
$("#stopbutton").attr("disabled","disabled");
$("#startbutton").removeAttr("disabled").val("Begin");
state = 2;
}
}
var keypressed = 0;
var keyrepeat = 0;
function ondown()
{
if (state == 1) // 计时中, 按下停止计时
{
keypressed = 1;
state = 0;
imgload = 0;
now = new Date();
ms = now.getTime() - then.getTime();
drawtime(ms);
updatestat(ms);
$("#startbutton").val("按空格键开始");
}
else if (state == 0) // 停止状态, 按下准备
{
// 准备
if (imgload == 1)
{
// nothing
}
else if(!keyrepeat)
{
// 换图片
$("#startbutton").val("Waiting...");
changesubject();
keyrepeat = 1;
}
}
}
function onup()
{
if(keypressed == 1 && state == 0) // 停止时按下,在此释放
{
keypressed = 0;
}
// ready
else if (state == 0 && imgload == 1)
{
state = 1; //计时开始
then = new Date();
$("#startbutton").val("Go");
//then.setTime(then.getTime() - ms);
}
keyrepeat = 0;
}
function imgonload() {
if(state == 0) {
imgload = 1;
drawtime(0);
$("#startbutton").val("Ready");
}
}
</script>
</head>
<body>
<div id="stat">统计信息</div>
<center>
<div id="debug"></div>
<h2>F2L Trainer</h2>
</center>
<center>
<div id="subject"></div>
<form name="stpw">
<div id="watch" style="filter:shadraw(x=1,y=1,color=black);position:relative;width: 359px; height: 80px ; font-size:48pt; font-family:Arial; font-weight:bold; color:navy; text-align:center" >00:00.00</div>
<input size="150" value="Begin" id="startbutton" type="BUTTON">
<input size="150" value="End" id="stopbutton" disabled="disabled" type="BUTTON">
<p></p>
底色:<select id="scheme" size="1" >
<option value="yrbwog" selected="selected">白底</option>
<option value="wobyrg">黄底</option>
<option value="gwrbyo">蓝底</option>
<option value="bwogyr">绿底</option>
<option value="obwrgy">红底</option>
<option value="rgwoby">橙底</option>
</select>
方位:<select id="alg_pos" size="1" >
<option value="0" selected="selected">任意</option>
<option value="1">FR</option>
<option value="2">BR</option>
<option value="3">BL</option>
<option value="4">FL</option>
</select>
空槽:<select id="alg_slot" size="1" >
<option value="5" selected="selected">无</option>
<option value="0">任意</option>
<option value="1">FR</option>
<option value="2">BR</option>
<option value="3">BL</option>
<option value="4">FL</option>
</select><br/>
</form>
<br>
<p>Images generated by <a href="http://cube.crider.co.uk/visualcube.php">VisualCube</a></p>
<p><a href="mailto:[email protected]">Email me</a> for comments or suggestions</p>
</center>
</body></html>