author | Oleksandr Gavenko <gavenkoa@gmail.com> |
Tue, 09 Sep 2014 20:33:17 +0300 | |
changeset 33 | f1bbe12e2c3d |
parent 32 | f48151863cdf |
child 34 | 16b711a81a16 |
permissions | -rw-r--r-- |
0 | 1 |
<!DOCTYPE html> |
2 |
<html> |
|
3 |
<head> |
|
4 |
<title>2048 AI</title> |
|
5 |
<meta name="viewport" content="width=device-width; initial-scale=1.0"/> |
|
6 |
<meta charset="utf-8"/> |
|
7 |
||
10
70ece7f758a0
Move rule and AI engine to separate files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
7
diff
changeset
|
8 |
<script src="rule.js"></script> |
7
d8106c8c0481
Rename methods and use sequential numbers instead of power of 2.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
4
diff
changeset
|
9 |
<script src="board.js"></script> |
d8106c8c0481
Rename methods and use sequential numbers instead of power of 2.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
4
diff
changeset
|
10 |
<script src="perf.js"></script> |
10
70ece7f758a0
Move rule and AI engine to separate files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
7
diff
changeset
|
11 |
<script src="ai.js"></script> |
7
d8106c8c0481
Rename methods and use sequential numbers instead of power of 2.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
4
diff
changeset
|
12 |
|
0 | 13 |
<style> |
27
8f96d09a4d94
Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
26
diff
changeset
|
14 |
body { |
8f96d09a4d94
Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
26
diff
changeset
|
15 |
font-size: 11pt; |
8f96d09a4d94
Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
26
diff
changeset
|
16 |
} |
4 | 17 |
h1, div.area { |
0 | 18 |
text-align: center; |
4 | 19 |
margin: 10px auto; |
0 | 20 |
} |
21 |
#board { |
|
22 |
margin: 10px auto; |
|
23 |
} |
|
24 |
#board td { |
|
25 |
width: 40px; |
|
26 |
height: 40px; |
|
27 |
border: 1px solid red; |
|
28 |
margin: 0; |
|
29 |
text-align: center; |
|
30 |
} |
|
33
f1bbe12e2c3d
Highlight score area.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
32
diff
changeset
|
31 |
div.ai-control, div.move-control, div.score-conrol { |
30
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
32 |
border: 1px red solid; |
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
33 |
display: inline-block; |
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
34 |
margin: 10px 0 2px 0; |
31 | 35 |
background-color: cornsilk; |
36 |
} |
|
33
f1bbe12e2c3d
Highlight score area.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
32
diff
changeset
|
37 |
div.move-control, div.score-conrol { |
f1bbe12e2c3d
Highlight score area.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
32
diff
changeset
|
38 |
padding: 3px; |
31 | 39 |
} |
40 |
div.ai-control { |
|
30
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
41 |
padding: 2px 2px 2px 1em; |
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
42 |
} |
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
43 |
div.ai-control:before { |
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
44 |
content: "AI: "; |
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
45 |
margin-left: -.5em; |
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
46 |
padding: 0; |
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
47 |
} |
4 | 48 |
.report > .name { |
49 |
font-weight: bold; |
|
50 |
} |
|
25
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
51 |
div.ai { |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
52 |
border: 1px red solid; |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
53 |
margin-top: 20px; |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
54 |
padding: 2px; |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
55 |
position: relative; |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
56 |
background-color: cornsilk; |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
57 |
} |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
58 |
div.ai.enabled { |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
59 |
background-color: wheat; |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
60 |
} |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
61 |
div.ai > h5 { |
27
8f96d09a4d94
Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
26
diff
changeset
|
62 |
margin: 2px 0 2px 6em; |
25
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
63 |
} |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
64 |
button.ai { |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
65 |
position: absolute; |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
66 |
left: 1em; |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
67 |
top: -1em; |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
68 |
} |
27
8f96d09a4d94
Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
26
diff
changeset
|
69 |
div.ai > div.option { |
8f96d09a4d94
Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
26
diff
changeset
|
70 |
display: inline-block; |
8f96d09a4d94
Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
26
diff
changeset
|
71 |
float: left; |
8f96d09a4d94
Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
26
diff
changeset
|
72 |
margin: 1px 4px; |
8f96d09a4d94
Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
26
diff
changeset
|
73 |
} |
8f96d09a4d94
Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
26
diff
changeset
|
74 |
.clearfix { |
8f96d09a4d94
Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
26
diff
changeset
|
75 |
clear: both; |
8f96d09a4d94
Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
26
diff
changeset
|
76 |
} |
31 | 77 |
#test { |
78 |
display: none; |
|
79 |
} |
|
0 | 80 |
</style> |
81 |
</head> |
|
82 |
<body> |
|
83 |
||
84 |
<h1>2048</h1> |
|
85 |
||
33
f1bbe12e2c3d
Highlight score area.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
32
diff
changeset
|
86 |
<div id="score-area" class="area"> |
f1bbe12e2c3d
Highlight score area.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
32
diff
changeset
|
87 |
<div class="score-conrol"> |
f1bbe12e2c3d
Highlight score area.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
32
diff
changeset
|
88 |
Score: <span id="score">0</span>, Max: <span id="max">0</span>, Turn: <span id="turn">0</span>, Speed: <span id="speed">0</span> t/s |
f1bbe12e2c3d
Highlight score area.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
32
diff
changeset
|
89 |
</div> |
f1bbe12e2c3d
Highlight score area.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
32
diff
changeset
|
90 |
</div> |
0 | 91 |
|
4 | 92 |
<div id="message-area" class="area"></div> |
0 | 93 |
|
94 |
<table id="board"> |
|
95 |
<tr> |
|
96 |
<td></td> |
|
97 |
<td></td> |
|
98 |
<td></td> |
|
99 |
<td></td> |
|
100 |
</tr> |
|
101 |
<tr> |
|
102 |
<td></td> |
|
103 |
<td></td> |
|
104 |
<td></td> |
|
105 |
<td></td> |
|
106 |
</tr> |
|
107 |
<tr> |
|
108 |
<td></td> |
|
109 |
<td></td> |
|
110 |
<td></td> |
|
111 |
<td></td> |
|
112 |
</tr> |
|
113 |
<tr> |
|
114 |
<td></td> |
|
115 |
<td></td> |
|
116 |
<td></td> |
|
117 |
<td></td> |
|
118 |
</tr> |
|
119 |
</table> |
|
120 |
||
4 | 121 |
<div id="control-area" class="area"> |
0 | 122 |
<div> |
123 |
<button id="start">Start</button> |
|
30
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
124 |
</div> |
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
125 |
<div class="ai-control"> |
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
126 |
<button id="suggest">Suggest</button> |
0 | 127 |
<button id="step">Step</button> |
128 |
<button id="finish">Finish</button> |
|
129 |
</div> |
|
31 | 130 |
<div class="clearfix"></div> |
131 |
<div class="move-control"> |
|
132 |
<table> |
|
133 |
<tr> |
|
134 |
<td></td><td><button id="up">up</button></td><td></td> |
|
135 |
</tr> |
|
136 |
<tr> |
|
137 |
<td><button id="left">left</button></td><td><button id="down">down</button></td><td><button id="right">right</button></td> |
|
138 |
</tr> |
|
139 |
</table> |
|
12
a9a44cfc3e08
Moves for 2d array board + test toolkit.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
11
diff
changeset
|
140 |
<button id="test">test</button> |
0 | 141 |
</div> |
25
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
142 |
<h1>AIs</h1> |
0 | 143 |
<div> |
25
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
144 |
<div class="ai" id="ai-random"> |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
145 |
<button class="ai">enable</button> |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
146 |
<h5>bling random</h5> |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
147 |
</div> |
27
8f96d09a4d94
Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
26
diff
changeset
|
148 |
<div class="ai" id="ai-blind-cycle"> |
25
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
149 |
<button class="ai">enable</button> |
27
8f96d09a4d94
Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
26
diff
changeset
|
150 |
<h5>blind cycle</h5> |
8f96d09a4d94
Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
26
diff
changeset
|
151 |
<div class="option"> |
8f96d09a4d94
Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
26
diff
changeset
|
152 |
<input type="checkbox" name="clockwise"/> clockwise |
8f96d09a4d94
Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
26
diff
changeset
|
153 |
</div> |
8f96d09a4d94
Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
26
diff
changeset
|
154 |
<div class="option"> |
8f96d09a4d94
Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
26
diff
changeset
|
155 |
<input type="checkbox" name="whilePossible"/> max move in one direction |
8f96d09a4d94
Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
26
diff
changeset
|
156 |
</div> |
8f96d09a4d94
Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
26
diff
changeset
|
157 |
<div class="clearfix"></div> |
25
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
158 |
</div> |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
159 |
<div class="ai" id="ai-next-max-value"> |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
160 |
<button class="ai">enable</button> |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
161 |
<h5>next merge makes max value</h5> |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
162 |
</div> |
26 | 163 |
<div class="ai" id="ai-deep-max-score"> |
25
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
164 |
<button class="ai">enable</button> |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
165 |
<h5>deep merges without simulation make max score</h5> |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
166 |
</div> |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
167 |
<div class="ai" id="ai-deep-max-score-corner"> |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
168 |
<button class="ai">enable</button> |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
169 |
<h5>deep merges without simulation make max score + bonus if max value at corner/edge</h5> |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
170 |
</div> |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
171 |
<div class="ai" id="ai-expectimax"> |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
172 |
<button class="ai">enable</button> |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
173 |
<h5>expectimax</h5> |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
174 |
</div> |
0 | 175 |
</div> |
176 |
</div> |
|
177 |
||
4 | 178 |
<div id="report-area" class="area"> |
179 |
<h1>Reports</h1> |
|
180 |
<div class="report" class="area"> |
|
181 |
<div class="name">next max score</div> |
|
182 |
<table> |
|
183 |
<tr> |
|
184 |
<th>Max</th> |
|
185 |
<th>Count</th> |
|
186 |
<th>%</th> |
|
187 |
</tr> |
|
188 |
<tr> |
|
189 |
<td>128</td><td>8</td><td><div style="background: red; width: 100px">x</div></td> |
|
190 |
</tr> |
|
191 |
<tr> |
|
192 |
<td>256</td><td>4</td><td><div style="background: red; width: 50px">x</div></td> |
|
193 |
</tr> |
|
194 |
<tr> |
|
195 |
<td>512</td><td>12</td><td><div style="background: red; width: 150px">x</div></td> |
|
196 |
</tr> |
|
197 |
</table> |
|
198 |
</div> |
|
199 |
</div> |
|
200 |
||
0 | 201 |
<script> |
202 |
"use strict"; |
|
203 |
||
204 |
var boardDom = document.getElementById("board"); |
|
205 |
var ui = {}; |
|
206 |
ui.board = {}; |
|
15
0fa97e430a9e
ui.board.set care about 'val' argument.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
14
diff
changeset
|
207 |
/* 'val' typesafe. */ |
0 | 208 |
ui.board.set = function(i, j, val) { |
16 | 209 |
if (typeof val !== 'number') |
15
0fa97e430a9e
ui.board.set care about 'val' argument.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
14
diff
changeset
|
210 |
val = 0; |
13
b3bfa9d1b537
Add color to board depending on values..
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
12
diff
changeset
|
211 |
var dom = boardDom.querySelectorAll("tr")[i].querySelectorAll("td")[j]; |
15
0fa97e430a9e
ui.board.set care about 'val' argument.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
14
diff
changeset
|
212 |
if (0 < val && val < 15) { |
0fa97e430a9e
ui.board.set care about 'val' argument.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
14
diff
changeset
|
213 |
dom.innerHTML = val; |
0fa97e430a9e
ui.board.set care about 'val' argument.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
14
diff
changeset
|
214 |
var rgb = 'rgb(255,'+ (255-5*val-2*(val%2)) +','+ (255-10*val-5*((val-1)%2)) +')'; |
0fa97e430a9e
ui.board.set care about 'val' argument.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
14
diff
changeset
|
215 |
} else { |
0fa97e430a9e
ui.board.set care about 'val' argument.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
14
diff
changeset
|
216 |
dom.innerHTML = ''; |
0fa97e430a9e
ui.board.set care about 'val' argument.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
14
diff
changeset
|
217 |
var rgb = 'white'; |
0fa97e430a9e
ui.board.set care about 'val' argument.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
14
diff
changeset
|
218 |
} |
13
b3bfa9d1b537
Add color to board depending on values..
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
12
diff
changeset
|
219 |
dom.style.backgroundColor = rgb; |
0 | 220 |
} |
221 |
ui.board.update = function(brd) { |
|
222 |
for (var i = 0; i < 4; i++) { |
|
223 |
for (var j = 0; j < 4; j++) { |
|
15
0fa97e430a9e
ui.board.set care about 'val' argument.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
14
diff
changeset
|
224 |
ui.board.set(i, j, brd[i][j]); |
0 | 225 |
} |
226 |
} |
|
227 |
} |
|
17 | 228 |
ui.board.handleEdit = function(tdDom, i, j) { |
229 |
if (!tdDom.firstChild || tdDom.firstChild.nodeType === Node.TEXT_NODE) { |
|
230 |
if (tdDom.firstChild) |
|
231 |
tdDom.removeChild(tdDom.firstChild); |
|
232 |
var inputDom = document.createElement('input'); |
|
233 |
inputDom.value = board.current[i][j]; |
|
234 |
inputDom.style.width = '1em'; |
|
235 |
tdDom.appendChild(inputDom); |
|
236 |
inputDom.focus(); |
|
237 |
inputDom.select(); |
|
238 |
inputDom.addEventListener("blur", function(tdDom, i, j) { |
|
239 |
return function(event) { |
|
240 |
ui.board.handleEdit(tdDom, i, j); |
|
241 |
return false; |
|
242 |
} |
|
243 |
}(tdDom, i, j)); |
|
244 |
} else { |
|
245 |
var inputDom = tdDom.firstChild; |
|
246 |
var val = parseInt(inputDom.value); |
|
247 |
if (0 <= val && val < 15) { |
|
248 |
board.current[i][j] = val; |
|
249 |
ui.board.set(i, j, val); |
|
250 |
} else { |
|
251 |
ui.board.set(i, j, board.current[i][j]); |
|
252 |
} |
|
253 |
} |
|
254 |
} |
|
255 |
ui.board.enableEdit = function() { |
|
256 |
var trDoms = boardDom.querySelectorAll("tr"); |
|
257 |
for (var i = 0; i < 4; i++) { |
|
258 |
var tdDoms = trDoms[i].querySelectorAll("td"); |
|
259 |
for (var j = 0; j < 4; j++) { |
|
260 |
var tdDom = tdDoms[j]; |
|
261 |
tdDom.addEventListener("click", function(tdDom, i, j) { |
|
262 |
return function(event) { |
|
263 |
ui.board.handleEdit(tdDom, i, j); |
|
264 |
return false; |
|
265 |
} |
|
266 |
}(tdDom, i, j)); |
|
267 |
tdDom.addEventListener("keyup", function(tdDom, i, j) { |
|
268 |
return function(event) { |
|
269 |
if (event.keyCode === 13) |
|
270 |
ui.board.handleEdit(tdDom, i, j); |
|
271 |
} |
|
272 |
}(tdDom, i, j)); |
|
273 |
} |
|
274 |
} |
|
275 |
} |
|
276 |
ui.board.enableEdit(); |
|
277 |
||
0 | 278 |
ui.score = {}; |
279 |
var scoreDom = document.getElementById("score"); |
|
280 |
var maxDom = document.getElementById("max"); |
|
1 | 281 |
var speedDom = document.getElementById("speed"); |
282 |
var turnDom = document.getElementById("turn"); |
|
0 | 283 |
ui.score.clear = function(brd) { |
284 |
scoreDom.innerHTML = '0'; |
|
285 |
maxDom.innerHTML = '0'; |
|
1 | 286 |
speedDom.innerHTML = '0'; |
287 |
turnDom.innerHTML = '0'; |
|
0 | 288 |
} |
289 |
ui.score.update = function(brd) { |
|
290 |
var score = board.score(brd); |
|
291 |
scoreDom.innerHTML = '' + score.score; |
|
292 |
maxDom.innerHTML = '' + score.max; |
|
293 |
} |
|
1 | 294 |
ui.score.speed = function(speed, turn) { |
295 |
speedDom.innerHTML = '' + speed; |
|
296 |
turnDom.innerHTML = '' + turn; |
|
297 |
} |
|
0 | 298 |
|
30
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
299 |
ui.action = {}; |
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
300 |
|
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
301 |
ui.action.start = function() { |
0 | 302 |
ui.score.clear(); |
303 |
ui.message.clear(); |
|
304 |
board.current = board.create(); |
|
7
d8106c8c0481
Rename methods and use sequential numbers instead of power of 2.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
4
diff
changeset
|
305 |
board.putRandom(board.current); |
0 | 306 |
ui.board.update(board.current); |
307 |
} |
|
30
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
308 |
document.getElementById("start").addEventListener("click", ui.action.start); |
0 | 309 |
|
30
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
310 |
ui.action.up = function() { |
0 | 311 |
var updated = board.move.up(board.current); |
312 |
if (updated) { |
|
7
d8106c8c0481
Rename methods and use sequential numbers instead of power of 2.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
4
diff
changeset
|
313 |
board.putRandom(board.current); |
0 | 314 |
ui.board.update(board.current); |
315 |
ui.score.update(board.current); |
|
30
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
316 |
ui.ai.current && ui.ai.current.cleanup(); |
0 | 317 |
} |
318 |
} |
|
30
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
319 |
document.getElementById("up").addEventListener("click", ui.action.up); |
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
320 |
ui.action.down = function() { |
0 | 321 |
var updated = board.move.down(board.current); |
322 |
if (updated) { |
|
7
d8106c8c0481
Rename methods and use sequential numbers instead of power of 2.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
4
diff
changeset
|
323 |
board.putRandom(board.current); |
0 | 324 |
ui.board.update(board.current); |
325 |
ui.score.update(board.current); |
|
30
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
326 |
ui.ai.current && ui.ai.current.cleanup(); |
0 | 327 |
} |
328 |
} |
|
30
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
329 |
document.getElementById("down").addEventListener("click", ui.action.down); |
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
330 |
ui.action.left = function() { |
0 | 331 |
var updated = board.move.left(board.current); |
332 |
if (updated) { |
|
7
d8106c8c0481
Rename methods and use sequential numbers instead of power of 2.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
4
diff
changeset
|
333 |
board.putRandom(board.current); |
0 | 334 |
ui.board.update(board.current); |
335 |
ui.score.update(board.current); |
|
30
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
336 |
ui.ai.current && ui.ai.current.cleanup(); |
0 | 337 |
} |
338 |
} |
|
30
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
339 |
document.getElementById("left").addEventListener("click", ui.action.left); |
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
340 |
ui.action.right = function() { |
0 | 341 |
var updated = board.move.right(board.current); |
342 |
if (updated) { |
|
7
d8106c8c0481
Rename methods and use sequential numbers instead of power of 2.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
4
diff
changeset
|
343 |
board.putRandom(board.current); |
0 | 344 |
ui.board.update(board.current); |
345 |
ui.score.update(board.current); |
|
30
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
346 |
ui.ai.current && ui.ai.current.cleanup(); |
0 | 347 |
} |
348 |
} |
|
30
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
349 |
document.getElementById("right").addEventListener("click", ui.action.right); |
0 | 350 |
|
351 |
document.body.addEventListener("keydown", function(event) { |
|
352 |
var key = event.keyCode || event.which; |
|
353 |
switch (key) { |
|
30
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
354 |
case 38: ui.action.up(); break; |
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
355 |
case 40: ui.action.down(); break; |
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
356 |
case 37: ui.action.left(); break; |
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
357 |
case 39: ui.action.right(); break; |
0 | 358 |
} |
359 |
return false; |
|
360 |
}); |
|
12
a9a44cfc3e08
Moves for 2d array board + test toolkit.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
11
diff
changeset
|
361 |
|
a9a44cfc3e08
Moves for 2d array board + test toolkit.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
11
diff
changeset
|
362 |
document.getElementById("test").addEventListener("click", function() { |
a9a44cfc3e08
Moves for 2d array board + test toolkit.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
11
diff
changeset
|
363 |
board.move.replaceByBoardJS(ui.brdEngine); |
a9a44cfc3e08
Moves for 2d array board + test toolkit.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
11
diff
changeset
|
364 |
}); |
0 | 365 |
|
366 |
ui.message = {}; |
|
367 |
var messageDom = document.getElementById("message-area"); |
|
368 |
ui.message.clear = function() { |
|
369 |
messageDom.innerHTML = ""; |
|
370 |
} |
|
371 |
ui.message.set = function(msg) { |
|
372 |
messageDom.innerHTML = msg; |
|
373 |
} |
|
374 |
||
375 |
function step() { |
|
376 |
ui.message.clear(); |
|
377 |
if (board.gameOver(board.current)) { |
|
378 |
ui.message.set("Game over!"); |
|
379 |
return; |
|
380 |
} |
|
381 |
var tmpBrd = board.create(); |
|
382 |
board.copy(board.current, tmpBrd); |
|
25
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
383 |
var move = ui.ai.current.analyse(tmpBrd); |
10
70ece7f758a0
Move rule and AI engine to separate files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
7
diff
changeset
|
384 |
if (typeof move === 'undefined') { |
0 | 385 |
ui.message.set("I don't know how to move!"); |
386 |
return; |
|
387 |
} |
|
10
70ece7f758a0
Move rule and AI engine to separate files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
7
diff
changeset
|
388 |
var updated = board.move[move].call(null, board.current); |
0 | 389 |
if (updated) { |
7
d8106c8c0481
Rename methods and use sequential numbers instead of power of 2.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
4
diff
changeset
|
390 |
board.putRandom(board.current); |
0 | 391 |
ui.board.update(board.current); |
392 |
ui.score.update(board.current); |
|
393 |
} else { |
|
394 |
ui.message.set("Wrong move!"); |
|
395 |
} |
|
396 |
} |
|
397 |
document.getElementById("step").addEventListener("click", step); |
|
398 |
||
30
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
399 |
ui.action.finish = function() { |
0 | 400 |
ui.message.clear(); |
1 | 401 |
var step = 0; |
402 |
var tsFrom = new Date().getTime(); |
|
0 | 403 |
while (!board.gameOver(board.current)) { |
404 |
var tmpBrd = board.create(); |
|
405 |
board.copy(board.current, tmpBrd); |
|
25
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
406 |
var move = ui.ai.current.analyse(tmpBrd); |
10
70ece7f758a0
Move rule and AI engine to separate files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
7
diff
changeset
|
407 |
if (typeof move === 'undefined') { |
0 | 408 |
ui.message.set("I don't know how to move!"); |
409 |
return; |
|
410 |
} |
|
10
70ece7f758a0
Move rule and AI engine to separate files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
7
diff
changeset
|
411 |
var updated = board.move[move].call(null, board.current); |
0 | 412 |
if (updated) { |
7
d8106c8c0481
Rename methods and use sequential numbers instead of power of 2.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
4
diff
changeset
|
413 |
board.putRandom(board.current); |
0 | 414 |
} else { |
415 |
ui.board.update(board.current); |
|
416 |
ui.score.update(board.current); |
|
417 |
ui.message.set("Wrong move!"); |
|
418 |
return; |
|
419 |
} |
|
1 | 420 |
step++; |
0 | 421 |
} |
1 | 422 |
var tsTo = new Date().getTime(); |
0 | 423 |
ui.board.update(board.current); |
424 |
ui.score.update(board.current); |
|
1 | 425 |
ui.score.speed(step*1000.0/(tsTo-tsFrom), step); |
0 | 426 |
ui.message.set("Game over!"); |
30
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
427 |
ui.ai.current && ui.ai.current.cleanup(); |
0 | 428 |
} |
30
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
429 |
document.getElementById("finish").addEventListener("click", ui.action.finish); |
0 | 430 |
|
10
70ece7f758a0
Move rule and AI engine to separate files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
7
diff
changeset
|
431 |
//////////////////////////////////////////////////////////////// |
70ece7f758a0
Move rule and AI engine to separate files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
7
diff
changeset
|
432 |
// Register AIs. |
0 | 433 |
|
25
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
434 |
ui.ai = {}; |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
435 |
ui.ai.current = null; |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
436 |
ui.ai.algList = { |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
437 |
"ai-random": function() { |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
438 |
return new ai.random(ui.brdEngine); |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
439 |
}, |
27
8f96d09a4d94
Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
26
diff
changeset
|
440 |
"ai-blind-cycle": function(aiDom) { |
8f96d09a4d94
Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
26
diff
changeset
|
441 |
var cfg = {}; |
8f96d09a4d94
Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
26
diff
changeset
|
442 |
cfg.clockwise = aiDom.querySelectorAll("input[name='clockwise']")[0].checked; |
8f96d09a4d94
Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
26
diff
changeset
|
443 |
cfg.whilePossible = aiDom.querySelectorAll("input[name='whilePossible']")[0].checked; |
8f96d09a4d94
Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
26
diff
changeset
|
444 |
return new ai.blindCycle(ui.brdEngine, cfg); |
8f96d09a4d94
Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
26
diff
changeset
|
445 |
}, |
25
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
446 |
"ai-next-max-score": function() { |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
447 |
return new ai.nextMaxScore(ui.brdEngine); |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
448 |
}, |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
449 |
"ai-next-max-value": function() { |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
450 |
return new ai.nextMaxValue(ui.brdEngine); |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
451 |
}, |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
452 |
"ai-deep-max-score": function() { |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
453 |
return new ai.deepMaxScore(ui.brdEngine); |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
454 |
}, |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
455 |
"ai-deep-max-score-corner": function() { |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
456 |
return new ai.deepMaxScoreCorner(ui.brdEngine); |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
457 |
}, |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
458 |
"ai-expectimax": function() { |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
459 |
return new ai.expectimax(ui.brdEngine); |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
460 |
}, |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
461 |
// "": function() { |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
462 |
// return new ai.(ui.brdEngine); |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
463 |
// }, |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
464 |
}; |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
465 |
ui.ai.domList = document.querySelectorAll('div.ai'); |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
466 |
for (var i = 0; i < ui.ai.domList.length; i++) { |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
467 |
ui.ai.domList[i].querySelectorAll('button.ai')[0].addEventListener("click", function (event) { |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
468 |
ui.ai.enable(event.target.parentNode); |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
469 |
}); |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
470 |
} |
0 | 471 |
|
25
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
472 |
ui.ai.moveToTop = function(aiDom) { |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
473 |
for (var i = 0; i < ui.ai.domList.length; i++) { |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
474 |
ui.ai.domList[i].classList.remove('enabled'); |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
475 |
} |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
476 |
var rootDom = aiDom.parentNode; |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
477 |
rootDom.removeChild(aiDom); |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
478 |
rootDom.insertBefore(aiDom, rootDom.firstChild); |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
479 |
aiDom.classList.add('enabled'); |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
480 |
} |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
481 |
ui.ai.enable = function(aiDom) { |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
482 |
if (ui.ai.current) |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
483 |
ui.ai.current.cleanup(); |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
484 |
ui.ai.moveToTop(aiDom); |
27
8f96d09a4d94
Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
26
diff
changeset
|
485 |
ui.ai.current = ui.ai.algList[aiDom.id](aiDom); |
25
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
486 |
} |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
487 |
|
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
488 |
ui.brdEngine = BoardArr2d; // TODO make user selectable |
0 | 489 |
|
32
f48151863cdf
Start game after page load.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
31
diff
changeset
|
490 |
ui.action.start(); |
f48151863cdf
Start game after page load.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
31
diff
changeset
|
491 |
|
0 | 492 |
</script> |
493 |
||
494 |
</body> |
|
495 |
</html> |