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