-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test Math (1).js
169 lines (153 loc) · 3.41 KB
/
Test Math (1).js
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
a=[[0,1,2,3,3],[4,4,4,2,4],[3,1,5,2,4],[5,5,3,2,1],[1,1,5,4,3],[6,6,6,6,6]];
a.toString = function (){
var l = "";
for(var j = 0; j < 6; j++){
for(var i = 0; i < 5; i++){
l += a[j][i];
}
}
return l.valueOf();
}
var logi = {};
col = ["black", "white", "red", "green", "cyan", "orange", "yellow"];
id="f";
var pos = {"line":0, "ring":0};
function show(){
var t = "<table>";
t += "<tr>"
for(var j = 0; j < 6; j++){
t += "<td>"
if(j == pos.line){
t += "<div class=sq style=\"background-color: grey;\"";
if(pos.ring >= 4) t += "></div>";
else t += " onclick=\"up();\">Up</div>";
}
t += "</td>"
}
t += "<td>"
t += "</td>"
t += "</tr>"
for(var i = 0; i < 5; i++){
t += "<tr>"
for(var j = 0; j < 6; j++){
t += "<td>"
t += "<div class=sq style=\"background-color: " + col[a[j][i]]+ ";\"></div>"
t += "</td>"
}
t += "<td>";
if(i != 0) t += "<div class=sq style=\"background-color: grey;\" onclick=\"rot('" + i + "')\">Rot " + i + "</div>";
t += "</td>";
t += "</tr>";
}
t += "<tr>"
for(var j = 0; j < 6; j++){
t += "<td>"
if(j == pos.line){
t += "<div class=sq style=\"background-color: grey;\"";
if(pos.ring <= 0) t += "></div>";
else t += " onclick=\"down();\">Down</div>";
}
t += "</td>"
}
t += "<td>"
t += "</td>"
t += "</tr>"
t += "</table>";
// t += "(" + pos.line + ";" + pos.ring + ")";
$("#" + id).html(t);
}
function rot(p){
var g = a.toString();
if(p <= pos.ring){
for(var j = 0; j < p; j++){
var tmp = a[5][j];
for(var i = 5; i > 0; i--){
a[i][j] = a[i-1][j];
}
a[0][j] = tmp;
}
}else{
for(var j = p; j < 5; j++){
var tmp = a[0][j];
for(var i = 0; i < 5; i++){
a[i][j] = a[i+1][j];
}
a[5][j] = tmp;
}
}
show();
var h = a.toString();
// $("#log").prepend(g + " r" + p +" -> " + h +"<br>");
if(typeof(logi[g]) != "object") logi[g] = {};
logi[g]["r" + p] = h;
return a;
}
function find(a){
for (var j = 0; j < 5; j++){
if(a[0][j] == 0) break;
}
pos = j;
return pos;
}
function up(){
var g = a.toString();
if(pos.ring < 4){
a[pos.line][pos.ring] = a[pos.line][++pos.ring];
a[pos.line][pos.ring] = 0;
}
show();
var h = a.toString();
// $("#log").prepend(g + " up" +" -> " + h +"<br>");
if(typeof(logi[g]) != "object") logi[g] = {};
logi[g]["up"] = h;
return a;
}
function down(){
var g = a.toString();
if(pos.ring > 0){
a[pos.line][pos.ring] = a[pos.line][--pos.ring];
a[pos.line][pos.ring] = 0;
}
show();
var h = a.toString();
// $("#log").prepend(g + " dn" +" -> " + h +"<br>");
if(typeof(logi[g]) != "object") logi[g] = {};
logi[g]["dn"] = h;
return a;
}
function meili(){
}
function rand(){
var ops = [];
var g = a.toString();
if(typeof(logi[g]) != "object") logi[g] = {};
if(pos.ring < 4){
if(typeof(logi[g].up) == "undefined") ops.push("up");
}
if(pos.ring > 0){
if(typeof(logi[g].dn) == "undefined") ops.push("dn");
}
for(var i = 1; i <= 4; i++){
if(typeof(logi[g]["r" + i]) == "undefined") ops.push("r" + i);
}
if(ops.length == 0) show();
// $("#log").prepend(ops.toString() + "<br>");
var op = Math.round(Math.random() * ops.length);
switch (ops[op]){
case "up": up(); break;
case "r1": rot(1); break;
case "r2": rot(2); break;
case "r3": rot(3); break;
case "r4": rot(4); break;
case "dn": down(); break;
default: break;
}
}
function run(){
rand();
setTimeout("run()", 0);
}
$(document).ready(function(){
show();
// run();
});