author | Oleksandr Gavenko <gavenkoa@gmail.com> |
Thu, 25 Sep 2014 01:10:01 +0300 | |
changeset 138 | 23cd36180bf9 |
parent 137 | be8ee2240a17 |
child 146 | a7b42ea88ac5 |
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 |
} |
|
112
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
31 |
div.control { |
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
32 |
text-align: left; |
30
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
33 |
border: 1px red solid; |
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
34 |
display: inline-block; |
112
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
35 |
margin: 3px 2px; |
31 | 36 |
background-color: cornsilk; |
112
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
37 |
padding: 2px; |
31 | 38 |
} |
112
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
39 |
div.move.control button.suggestion { |
34 | 40 |
background-color: cyan; |
41 |
} |
|
112
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
42 |
div.wide.control { |
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
43 |
display: block; |
30
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
44 |
} |
112
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
45 |
div.ai.control { |
25
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
46 |
position: relative; |
112
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
47 |
margin-bottom: 1em; |
25
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
48 |
} |
112
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
49 |
div.ai.control.enabled { |
25
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
50 |
background-color: wheat; |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
51 |
} |
112
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
52 |
div.control h5 { |
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
53 |
text-align: center; |
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
54 |
margin: 2px 0; |
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
55 |
} |
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
56 |
div.ai.control h5 { |
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
57 |
margin-left: 6em; |
25
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
58 |
} |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
59 |
button.ai { |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
60 |
position: absolute; |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
61 |
left: 1em; |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
62 |
top: -1em; |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
63 |
} |
98
eb4f89e2a001
Clean statistics button.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
97
diff
changeset
|
64 |
button#statistic, button#statistic-clean { |
62 | 65 |
display: inline-block; |
66 |
margin: 3px 4px; |
|
67 |
} |
|
112
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
68 |
div.control > div.option { |
27
8f96d09a4d94
Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
26
diff
changeset
|
69 |
display: inline-block; |
8f96d09a4d94
Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
26
diff
changeset
|
70 |
margin: 1px 4px; |
36
a18fc2601ce8
Add blind eight random AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
35
diff
changeset
|
71 |
padding: 2px; |
a18fc2601ce8
Add blind eight random AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
35
diff
changeset
|
72 |
border: 1px solid tan; |
a18fc2601ce8
Add blind eight random AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
35
diff
changeset
|
73 |
border-radius: 4px; |
a18fc2601ce8
Add blind eight random AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
35
diff
changeset
|
74 |
} |
112
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
75 |
div.control input { |
36
a18fc2601ce8
Add blind eight random AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
35
diff
changeset
|
76 |
text-align: right; |
a18fc2601ce8
Add blind eight random AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
35
diff
changeset
|
77 |
max-width: 4em; |
61
eed17c93d420
Fix: Unknown property 'margin-rght'. Declaration dropped.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
59
diff
changeset
|
78 |
margin-right: 2px; |
27
8f96d09a4d94
Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
26
diff
changeset
|
79 |
} |
31 | 80 |
#test { |
81 |
display: none; |
|
82 |
} |
|
71
aa0240db128a
Show statistic reports.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
70
diff
changeset
|
83 |
table.report-by-maxval { |
aa0240db128a
Show statistic reports.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
70
diff
changeset
|
84 |
border-collapse: collapse; |
aa0240db128a
Show statistic reports.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
70
diff
changeset
|
85 |
margin: 2px; |
73
a50828ac954d
Remove code duplication.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
72
diff
changeset
|
86 |
font-size: 10pt; |
133
69e0ef5b24f4
Highlight mean values.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
132
diff
changeset
|
87 |
text-align: right; |
71
aa0240db128a
Show statistic reports.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
70
diff
changeset
|
88 |
} |
aa0240db128a
Show statistic reports.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
70
diff
changeset
|
89 |
table.report-by-maxval > tr > th { |
aa0240db128a
Show statistic reports.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
70
diff
changeset
|
90 |
border: 2px solid green; |
aa0240db128a
Show statistic reports.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
70
diff
changeset
|
91 |
padding: 2px; |
aa0240db128a
Show statistic reports.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
70
diff
changeset
|
92 |
} |
aa0240db128a
Show statistic reports.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
70
diff
changeset
|
93 |
table.report-by-maxval > tr > td { |
aa0240db128a
Show statistic reports.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
70
diff
changeset
|
94 |
border: 1px solid green; |
aa0240db128a
Show statistic reports.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
70
diff
changeset
|
95 |
padding: 2px; |
aa0240db128a
Show statistic reports.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
70
diff
changeset
|
96 |
} |
74
93cb48b73b39
Enable config for expectimax. Fix weight function for expectimax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
73
diff
changeset
|
97 |
table.report-by-maxval > tr > td:nth-child(3) { |
134
5b772474bf17
Fix color to satisfy schema.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
133
diff
changeset
|
98 |
background-color: gold; |
74
93cb48b73b39
Enable config for expectimax. Fix weight function for expectimax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
73
diff
changeset
|
99 |
} |
133
69e0ef5b24f4
Highlight mean values.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
132
diff
changeset
|
100 |
table.report-by-maxval > tr > td:nth-child(5), |
69e0ef5b24f4
Highlight mean values.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
132
diff
changeset
|
101 |
table.report-by-maxval > tr > td:nth-child(8), |
69e0ef5b24f4
Highlight mean values.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
132
diff
changeset
|
102 |
table.report-by-maxval > tr > td:nth-child(11) { |
69e0ef5b24f4
Highlight mean values.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
132
diff
changeset
|
103 |
background-color: wheat; |
69e0ef5b24f4
Highlight mean values.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
132
diff
changeset
|
104 |
} |
0 | 105 |
</style> |
106 |
</head> |
|
107 |
<body> |
|
108 |
||
88
97acd9f4288b
Fix navigation header.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
86
diff
changeset
|
109 |
<div class="area">[ <a href="README.html">About</a> | <a href="CHANGES.html">Changes</a> | <a href="HACKING.html">Hacking</a> | <a href="AUTHORS.html">Authors</a> ]</div> |
77 | 110 |
|
0 | 111 |
<h1>2048</h1> |
112 |
||
33
f1bbe12e2c3d
Highlight score area.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
32
diff
changeset
|
113 |
<div id="score-area" class="area"> |
112
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
114 |
<div class="control"> |
33
f1bbe12e2c3d
Highlight score area.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
32
diff
changeset
|
115 |
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
|
116 |
</div> |
f1bbe12e2c3d
Highlight score area.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
32
diff
changeset
|
117 |
</div> |
0 | 118 |
|
4 | 119 |
<div id="message-area" class="area"></div> |
0 | 120 |
|
121 |
<table id="board"> |
|
122 |
<tr> |
|
123 |
<td></td> |
|
124 |
<td></td> |
|
125 |
<td></td> |
|
126 |
<td></td> |
|
127 |
</tr> |
|
128 |
<tr> |
|
129 |
<td></td> |
|
130 |
<td></td> |
|
131 |
<td></td> |
|
132 |
<td></td> |
|
133 |
</tr> |
|
134 |
<tr> |
|
135 |
<td></td> |
|
136 |
<td></td> |
|
137 |
<td></td> |
|
138 |
<td></td> |
|
139 |
</tr> |
|
140 |
<tr> |
|
141 |
<td></td> |
|
142 |
<td></td> |
|
143 |
<td></td> |
|
144 |
<td></td> |
|
145 |
</tr> |
|
146 |
</table> |
|
147 |
||
4 | 148 |
<div id="control-area" class="area"> |
112
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
149 |
<div class="control"> |
0 | 150 |
<button id="start">Start</button> |
112
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
151 |
<div class="option"><input type="checkbox" id="2048" checked> 2048</div> |
113
fc058d27e829
Make board engine selectable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
112
diff
changeset
|
152 |
<div class="option"> |
fc058d27e829
Make board engine selectable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
112
diff
changeset
|
153 |
<select id="board-engine"> |
fc058d27e829
Make board engine selectable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
112
diff
changeset
|
154 |
<option value="BoardObj">BoardObj</option> |
fc058d27e829
Make board engine selectable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
112
diff
changeset
|
155 |
<option value="BoardArr2d">BoardArr2d</option> |
fc058d27e829
Make board engine selectable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
112
diff
changeset
|
156 |
<option value="BoardArr">BoardArr</option> |
fc058d27e829
Make board engine selectable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
112
diff
changeset
|
157 |
</select> engine |
fc058d27e829
Make board engine selectable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
112
diff
changeset
|
158 |
</div> |
30
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
159 |
</div> |
112
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
160 |
<br> |
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
161 |
<div class="control"> |
30
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
162 |
<button id="suggest">Suggest</button> |
0 | 163 |
<button id="step">Step</button> |
123
fc6019d22a38
Visual AI actions mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
113
diff
changeset
|
164 |
<button id="visual-finish">Visual</button> |
0 | 165 |
<button id="finish">Finish</button> |
138
23cd36180bf9
Add ability to enable browser profile.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
137
diff
changeset
|
166 |
<div class="option"><input type="checkbox" id="profile"> profile</div> |
0 | 167 |
</div> |
112
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
168 |
<br> |
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
169 |
<div class="control"> |
94
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
170 |
<button id="until">Continue</button> |
112
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
171 |
<div class="option">until <input type="text" class="positive" id="until-score" value="10000"> score</div> |
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
172 |
and <div class="option"><input type="text" class="positive" id="until-max-value" value="9"> max value</div> |
94
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
173 |
</div> |
112
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
174 |
<br> |
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
175 |
<div class="move control"> |
31 | 176 |
<table> |
177 |
<tr> |
|
63
251c39718d67
Replace words with arrows to show directions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
62
diff
changeset
|
178 |
<td></td><td><button id="up">↑</button></td><td></td> |
31 | 179 |
</tr> |
180 |
<tr> |
|
63
251c39718d67
Replace words with arrows to show directions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
62
diff
changeset
|
181 |
<td><button id="left">←</button></td><td><button id="down">↓</button></td><td><button id="right">→</button></td> |
31 | 182 |
</tr> |
183 |
</table> |
|
12
a9a44cfc3e08
Moves for 2d array board + test toolkit.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
11
diff
changeset
|
184 |
<button id="test">test</button> |
0 | 185 |
</div> |
25
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
186 |
<h1>AIs</h1> |
112
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
187 |
<div class="ai-list"> |
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
188 |
<div class="ai wide control" id="ai-blind-random"> |
25
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
189 |
<button class="ai">enable</button> |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
190 |
<h5>bling random</h5> |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
191 |
</div> |
112
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
192 |
<div class="ai wide control" id="ai-blind-weight-random"> |
36
a18fc2601ce8
Add blind eight random AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
35
diff
changeset
|
193 |
<button class="ai">enable</button> |
a18fc2601ce8
Add blind eight random AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
35
diff
changeset
|
194 |
<h5>bling weight random</h5> |
a18fc2601ce8
Add blind eight random AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
35
diff
changeset
|
195 |
<div class="option"> |
55
8ba9dc89be87
Automatically extract config from DOM.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
53
diff
changeset
|
196 |
<input type="text" name="left" class="positive" pattern="[0-9]*[.]?[0-9]*" value="1"/> left weight |
36
a18fc2601ce8
Add blind eight random AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
35
diff
changeset
|
197 |
</div> |
a18fc2601ce8
Add blind eight random AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
35
diff
changeset
|
198 |
<div class="option"> |
104
47d42234dd5c
Set better coefficient for blind-weight-random AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
103
diff
changeset
|
199 |
<input type="text" name="right" class="positive" pattern="[0-9]*[.]?[0-9]*" value="16"/> right weight |
36
a18fc2601ce8
Add blind eight random AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
35
diff
changeset
|
200 |
</div> |
a18fc2601ce8
Add blind eight random AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
35
diff
changeset
|
201 |
<div class="option"> |
104
47d42234dd5c
Set better coefficient for blind-weight-random AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
103
diff
changeset
|
202 |
<input type="text" name="up" class="positive" pattern="[0-9]*[.]?[0-9]*" value="4"/> up weight |
36
a18fc2601ce8
Add blind eight random AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
35
diff
changeset
|
203 |
</div> |
a18fc2601ce8
Add blind eight random AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
35
diff
changeset
|
204 |
<div class="option"> |
104
47d42234dd5c
Set better coefficient for blind-weight-random AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
103
diff
changeset
|
205 |
<input type="text" name="down" class="positive" pattern="[0-9]*[.]?[0-9]*" value="8"/> down weight |
36
a18fc2601ce8
Add blind eight random AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
35
diff
changeset
|
206 |
</div> |
a18fc2601ce8
Add blind eight random AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
35
diff
changeset
|
207 |
</div> |
112
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
208 |
<div class="ai wide control" id="ai-blind-cycle"> |
25
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
209 |
<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
|
210 |
<h5>blind cycle</h5> |
8f96d09a4d94
Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
26
diff
changeset
|
211 |
<div class="option"> |
8f96d09a4d94
Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
26
diff
changeset
|
212 |
<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
|
213 |
</div> |
8f96d09a4d94
Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
26
diff
changeset
|
214 |
<div class="option"> |
8f96d09a4d94
Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
26
diff
changeset
|
215 |
<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
|
216 |
</div> |
25
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
217 |
</div> |
112
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
218 |
<div class="ai wide control" id="ai-one-step-ahead"> |
25
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
219 |
<button class="ai">enable</button> |
99 | 220 |
<h5>one step ahead</h5> |
53
ee53cd2cb69a
Join all one step deep AIs into one with linear weight function.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
52
diff
changeset
|
221 |
<div class="option"> |
55
8ba9dc89be87
Automatically extract config from DOM.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
53
diff
changeset
|
222 |
<input type="text" name="scoreCoef" class="positive" pattern="[0-9]*[.]?[0-9]*" value="1"/> score weight |
53
ee53cd2cb69a
Join all one step deep AIs into one with linear weight function.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
52
diff
changeset
|
223 |
</div> |
ee53cd2cb69a
Join all one step deep AIs into one with linear weight function.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
52
diff
changeset
|
224 |
<div class="option"> |
55
8ba9dc89be87
Automatically extract config from DOM.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
53
diff
changeset
|
225 |
<input type="text" name="maxValCoef" class="positive" pattern="[0-9]*[.]?[0-9]*" value="0"/> max value weight |
53
ee53cd2cb69a
Join all one step deep AIs into one with linear weight function.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
52
diff
changeset
|
226 |
</div> |
ee53cd2cb69a
Join all one step deep AIs into one with linear weight function.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
52
diff
changeset
|
227 |
<div class="option"> |
55
8ba9dc89be87
Automatically extract config from DOM.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
53
diff
changeset
|
228 |
<input type="text" name="cornerBonus" class="positive" pattern="[0-9]*[.]?[0-9]*" value="100"/> max value at corner bonus |
53
ee53cd2cb69a
Join all one step deep AIs into one with linear weight function.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
52
diff
changeset
|
229 |
</div> |
ee53cd2cb69a
Join all one step deep AIs into one with linear weight function.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
52
diff
changeset
|
230 |
<div class="option"> |
55
8ba9dc89be87
Automatically extract config from DOM.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
53
diff
changeset
|
231 |
<input type="text" name="edgeBonus" class="positive" pattern="[0-9]*[.]?[0-9]*" value="0"/> max value at edge bonus |
53
ee53cd2cb69a
Join all one step deep AIs into one with linear weight function.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
52
diff
changeset
|
232 |
</div> |
ee53cd2cb69a
Join all one step deep AIs into one with linear weight function.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
52
diff
changeset
|
233 |
<div class="option"> |
55
8ba9dc89be87
Automatically extract config from DOM.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
53
diff
changeset
|
234 |
<input type="text" name="freeBonus" class="positive" pattern="[0-9]*[.]?[0-9]*" value="10"/> free cell coefficient |
53
ee53cd2cb69a
Join all one step deep AIs into one with linear weight function.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
52
diff
changeset
|
235 |
</div> |
25
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
236 |
</div> |
112
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
237 |
<div class="ai wide control" id="ai-static-deep-merges"> |
25
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
238 |
<button class="ai">enable</button> |
110
e3a91b336976
Join N level deep on score value without random simulation AIs and add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
104
diff
changeset
|
239 |
<h5>deep merges without random simulation</h5> |
e3a91b336976
Join N level deep on score value without random simulation AIs and add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
104
diff
changeset
|
240 |
<div class="option"> |
e3a91b336976
Join N level deep on score value without random simulation AIs and add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
104
diff
changeset
|
241 |
<input type="text" name="scoreCoef" class="positive" pattern="[0-9]*[.]?[0-9]*" value="1"/> score weight |
e3a91b336976
Join N level deep on score value without random simulation AIs and add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
104
diff
changeset
|
242 |
</div> |
e3a91b336976
Join N level deep on score value without random simulation AIs and add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
104
diff
changeset
|
243 |
<div class="option"> |
e3a91b336976
Join N level deep on score value without random simulation AIs and add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
104
diff
changeset
|
244 |
<input type="text" name="maxValCoef" class="positive" pattern="[0-9]*[.]?[0-9]*" value="0"/> max value weight |
e3a91b336976
Join N level deep on score value without random simulation AIs and add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
104
diff
changeset
|
245 |
</div> |
e3a91b336976
Join N level deep on score value without random simulation AIs and add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
104
diff
changeset
|
246 |
<div class="option"> |
e3a91b336976
Join N level deep on score value without random simulation AIs and add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
104
diff
changeset
|
247 |
<input type="text" name="cornerBonus" class="positive" pattern="[0-9]*[.]?[0-9]*" value="100"/> max value at corner bonus |
e3a91b336976
Join N level deep on score value without random simulation AIs and add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
104
diff
changeset
|
248 |
</div> |
e3a91b336976
Join N level deep on score value without random simulation AIs and add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
104
diff
changeset
|
249 |
<div class="option"> |
e3a91b336976
Join N level deep on score value without random simulation AIs and add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
104
diff
changeset
|
250 |
<input type="text" name="edgeBonus" class="positive" pattern="[0-9]*[.]?[0-9]*" value="0"/> max value at edge bonus |
e3a91b336976
Join N level deep on score value without random simulation AIs and add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
104
diff
changeset
|
251 |
</div> |
e3a91b336976
Join N level deep on score value without random simulation AIs and add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
104
diff
changeset
|
252 |
<div class="option"> |
e3a91b336976
Join N level deep on score value without random simulation AIs and add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
104
diff
changeset
|
253 |
<input type="text" name="freeBonus" class="positive" pattern="[0-9]*[.]?[0-9]*" value="10"/> free cell coefficient |
e3a91b336976
Join N level deep on score value without random simulation AIs and add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
104
diff
changeset
|
254 |
</div> |
e3a91b336976
Join N level deep on score value without random simulation AIs and add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
104
diff
changeset
|
255 |
<div class="option"> |
e3a91b336976
Join N level deep on score value without random simulation AIs and add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
104
diff
changeset
|
256 |
<input type="text" name="weightThreshold" class="positive" pattern="[0-9]*[.]?[0-9]*" value="10"/> score threshold |
e3a91b336976
Join N level deep on score value without random simulation AIs and add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
104
diff
changeset
|
257 |
</div> |
25
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
258 |
</div> |
112
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
259 |
<div class="ai wide control" id="ai-expectimax"> |
25
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
260 |
<button class="ai">enable</button> |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
261 |
<h5>expectimax</h5> |
74
93cb48b73b39
Enable config for expectimax. Fix weight function for expectimax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
73
diff
changeset
|
262 |
<div class="option"> |
93cb48b73b39
Enable config for expectimax. Fix weight function for expectimax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
73
diff
changeset
|
263 |
<input type="text" name="depth" class="positive" pattern="[0-9]*" value="3"/> recursion depth |
93cb48b73b39
Enable config for expectimax. Fix weight function for expectimax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
73
diff
changeset
|
264 |
</div> |
93cb48b73b39
Enable config for expectimax. Fix weight function for expectimax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
73
diff
changeset
|
265 |
<div class="option"> |
93cb48b73b39
Enable config for expectimax. Fix weight function for expectimax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
73
diff
changeset
|
266 |
<input type="text" name="balance" class="positive" pattern="[0-9]*[.]?[0-9]*" value=".9"/> probability of 2 |
93cb48b73b39
Enable config for expectimax. Fix weight function for expectimax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
73
diff
changeset
|
267 |
</div> |
93cb48b73b39
Enable config for expectimax. Fix weight function for expectimax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
73
diff
changeset
|
268 |
<div class="option"> |
93cb48b73b39
Enable config for expectimax. Fix weight function for expectimax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
73
diff
changeset
|
269 |
<input type="text" name="scoreCoef" class="positive" pattern="[0-9]*[.]?[0-9]*" value="1"/> score weight |
93cb48b73b39
Enable config for expectimax. Fix weight function for expectimax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
73
diff
changeset
|
270 |
</div> |
93cb48b73b39
Enable config for expectimax. Fix weight function for expectimax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
73
diff
changeset
|
271 |
<div class="option"> |
93cb48b73b39
Enable config for expectimax. Fix weight function for expectimax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
73
diff
changeset
|
272 |
<input type="text" name="maxValCoef" class="positive" pattern="[0-9]*[.]?[0-9]*" value="0"/> max value weight |
93cb48b73b39
Enable config for expectimax. Fix weight function for expectimax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
73
diff
changeset
|
273 |
</div> |
93cb48b73b39
Enable config for expectimax. Fix weight function for expectimax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
73
diff
changeset
|
274 |
<div class="option"> |
93cb48b73b39
Enable config for expectimax. Fix weight function for expectimax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
73
diff
changeset
|
275 |
<input type="text" name="cornerBonus" class="positive" pattern="[0-9]*[.]?[0-9]*" value="100"/> max value at corner bonus |
93cb48b73b39
Enable config for expectimax. Fix weight function for expectimax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
73
diff
changeset
|
276 |
</div> |
93cb48b73b39
Enable config for expectimax. Fix weight function for expectimax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
73
diff
changeset
|
277 |
<div class="option"> |
93cb48b73b39
Enable config for expectimax. Fix weight function for expectimax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
73
diff
changeset
|
278 |
<input type="text" name="edgeBonus" class="positive" pattern="[0-9]*[.]?[0-9]*" value="0"/> max value at edge bonus |
93cb48b73b39
Enable config for expectimax. Fix weight function for expectimax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
73
diff
changeset
|
279 |
</div> |
93cb48b73b39
Enable config for expectimax. Fix weight function for expectimax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
73
diff
changeset
|
280 |
<div class="option"> |
93cb48b73b39
Enable config for expectimax. Fix weight function for expectimax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
73
diff
changeset
|
281 |
<input type="text" name="freeBonus" class="positive" pattern="[0-9]*[.]?[0-9]*" value="10"/> free cell coefficient |
93cb48b73b39
Enable config for expectimax. Fix weight function for expectimax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
73
diff
changeset
|
282 |
</div> |
25
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
283 |
</div> |
0 | 284 |
</div> |
285 |
</div> |
|
286 |
||
112
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
287 |
<div id="report-area" class="area"> |
4 | 288 |
<h1>Reports</h1> |
112
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
289 |
<div class="control"> |
129
e0958e521716
Break limit on script execution time for statistic gathering
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
128
diff
changeset
|
290 |
<div class="option">up to <input type="text" id="stat-count-limit" value="100"> times</div> |
e0958e521716
Break limit on script execution time for statistic gathering
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
128
diff
changeset
|
291 |
<div class="option">up to <input type="text" id="stat-time-limit" value="10"> sec</div> |
e0958e521716
Break limit on script execution time for statistic gathering
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
128
diff
changeset
|
292 |
<button id="statistic-start">Start</button> |
130
28694f058ea4
Make a way to stop statistic gathering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
129
diff
changeset
|
293 |
<button id="statistic-stop">Stop</button> |
98
eb4f89e2a001
Clean statistics button.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
97
diff
changeset
|
294 |
<button id="statistic-clean">Clean</button> |
112
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
295 |
<div class="option"><input type="checkbox" id="report-score"/> score</div> |
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
296 |
<div class="option"><input type="checkbox" id="report-turn"/> turn</div> |
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
297 |
<div class="option"><input type="checkbox" id="report-speed"/> speed</div> |
62 | 298 |
</div> |
112
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
299 |
<div id="reports" class="wide control"></div> |
4 | 300 |
</div> |
301 |
||
0 | 302 |
<script> |
303 |
"use strict"; |
|
304 |
||
73
a50828ac954d
Remove code duplication.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
72
diff
changeset
|
305 |
var ui = {}; |
a50828ac954d
Remove code duplication.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
72
diff
changeset
|
306 |
|
a50828ac954d
Remove code duplication.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
72
diff
changeset
|
307 |
//////////////////////////////////////////////////////////////// |
a50828ac954d
Remove code duplication.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
72
diff
changeset
|
308 |
// UI widgets. |
a50828ac954d
Remove code duplication.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
72
diff
changeset
|
309 |
|
a50828ac954d
Remove code duplication.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
72
diff
changeset
|
310 |
ui.dom = {}; |
132
8715659bcce6
Add newline processing in report table cells.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
131
diff
changeset
|
311 |
ui.dom.putBr = function(parentDom, text) { |
8715659bcce6
Add newline processing in report table cells.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
131
diff
changeset
|
312 |
var lines = text.split('\n'); |
8715659bcce6
Add newline processing in report table cells.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
131
diff
changeset
|
313 |
parentDom.appendChild(document.createTextNode(lines[0])); |
8715659bcce6
Add newline processing in report table cells.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
131
diff
changeset
|
314 |
for (var i = 1; i < lines.length; i++) { |
8715659bcce6
Add newline processing in report table cells.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
131
diff
changeset
|
315 |
parentDom.appendChild(document.createElement('br')); |
8715659bcce6
Add newline processing in report table cells.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
131
diff
changeset
|
316 |
parentDom.appendChild(document.createTextNode(lines[i])); |
8715659bcce6
Add newline processing in report table cells.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
131
diff
changeset
|
317 |
} |
8715659bcce6
Add newline processing in report table cells.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
131
diff
changeset
|
318 |
} |
73
a50828ac954d
Remove code duplication.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
72
diff
changeset
|
319 |
ui.dom.table = function(tbl, cols, cfg) { |
a50828ac954d
Remove code duplication.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
72
diff
changeset
|
320 |
var tableDom = document.createElement('table'); |
102
6c057ac86c97
Show AI config in report as title.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
101
diff
changeset
|
321 |
if (typeof cfg.tblClass === 'string') |
6c057ac86c97
Show AI config in report as title.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
101
diff
changeset
|
322 |
tableDom.classList.add(cfg.tblClass); |
6c057ac86c97
Show AI config in report as title.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
101
diff
changeset
|
323 |
if (typeof cfg.tblTitle === 'string') |
6c057ac86c97
Show AI config in report as title.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
101
diff
changeset
|
324 |
tableDom.title = cfg.tblTitle; |
73
a50828ac954d
Remove code duplication.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
72
diff
changeset
|
325 |
var trDom = document.createElement('tr'); |
a50828ac954d
Remove code duplication.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
72
diff
changeset
|
326 |
for (var i = 0; i < cols.length; i++) { |
a50828ac954d
Remove code duplication.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
72
diff
changeset
|
327 |
var thDom = document.createElement('td'); |
132
8715659bcce6
Add newline processing in report table cells.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
131
diff
changeset
|
328 |
ui.dom.putBr(thDom, cols[i]); |
73
a50828ac954d
Remove code duplication.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
72
diff
changeset
|
329 |
trDom.appendChild(thDom); |
a50828ac954d
Remove code duplication.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
72
diff
changeset
|
330 |
} |
a50828ac954d
Remove code duplication.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
72
diff
changeset
|
331 |
tableDom.appendChild(trDom); |
a50828ac954d
Remove code duplication.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
72
diff
changeset
|
332 |
for (var i = 0; i < tbl.length; i++) { |
a50828ac954d
Remove code duplication.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
72
diff
changeset
|
333 |
var row = tbl[i]; |
a50828ac954d
Remove code duplication.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
72
diff
changeset
|
334 |
var trDom = document.createElement('tr'); |
a50828ac954d
Remove code duplication.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
72
diff
changeset
|
335 |
for (var j = 0; j < row.length; j++) { |
a50828ac954d
Remove code duplication.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
72
diff
changeset
|
336 |
var tdDom = document.createElement('td'); |
a50828ac954d
Remove code duplication.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
72
diff
changeset
|
337 |
tdDom.appendChild(document.createTextNode(row[j])); |
a50828ac954d
Remove code duplication.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
72
diff
changeset
|
338 |
trDom.appendChild(tdDom); |
a50828ac954d
Remove code duplication.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
72
diff
changeset
|
339 |
} |
a50828ac954d
Remove code duplication.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
72
diff
changeset
|
340 |
tableDom.appendChild(trDom); |
a50828ac954d
Remove code duplication.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
72
diff
changeset
|
341 |
} |
a50828ac954d
Remove code duplication.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
72
diff
changeset
|
342 |
return tableDom; |
a50828ac954d
Remove code duplication.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
72
diff
changeset
|
343 |
}; |
a50828ac954d
Remove code duplication.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
72
diff
changeset
|
344 |
|
a50828ac954d
Remove code duplication.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
72
diff
changeset
|
345 |
//////////////////////////////////////////////////////////////// |
a50828ac954d
Remove code duplication.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
72
diff
changeset
|
346 |
// Board. |
a50828ac954d
Remove code duplication.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
72
diff
changeset
|
347 |
|
0 | 348 |
var boardDom = document.getElementById("board"); |
349 |
ui.board = {}; |
|
38
d476efde7242
2 modes of value showing: 0,1,...,11 and 0,2,4,...,2048.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
37
diff
changeset
|
350 |
ui.board.val2048Dom = document.getElementById('2048'); |
d476efde7242
2 modes of value showing: 0,1,...,11 and 0,2,4,...,2048.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
37
diff
changeset
|
351 |
ui.board.val2048Dom.addEventListener("click", function(event) { |
65
b8028f3e30fb
Use preventDefault()/stopPropagation(). Add false to addEventListener().
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
64
diff
changeset
|
352 |
event.preventDefault(); event.stopPropagation(); |
45 | 353 |
ui.board.update(ui.board.position); |
43
8b1577211149
Save val2048 preference.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
42
diff
changeset
|
354 |
localStorage.val2048 = ui.board.val2048Dom.checked; |
38
d476efde7242
2 modes of value showing: 0,1,...,11 and 0,2,4,...,2048.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
37
diff
changeset
|
355 |
event.target.blur(); |
65
b8028f3e30fb
Use preventDefault()/stopPropagation(). Add false to addEventListener().
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
64
diff
changeset
|
356 |
}, false); |
38
d476efde7242
2 modes of value showing: 0,1,...,11 and 0,2,4,...,2048.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
37
diff
changeset
|
357 |
ui.board.val2048 = function(val) { |
d476efde7242
2 modes of value showing: 0,1,...,11 and 0,2,4,...,2048.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
37
diff
changeset
|
358 |
if (ui.board.val2048Dom.checked) |
d476efde7242
2 modes of value showing: 0,1,...,11 and 0,2,4,...,2048.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
37
diff
changeset
|
359 |
return Math.pow(2, val); |
d476efde7242
2 modes of value showing: 0,1,...,11 and 0,2,4,...,2048.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
37
diff
changeset
|
360 |
return val; |
d476efde7242
2 modes of value showing: 0,1,...,11 and 0,2,4,...,2048.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
37
diff
changeset
|
361 |
} |
113
fc058d27e829
Make board engine selectable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
112
diff
changeset
|
362 |
var boardEngineDom = document.getElementById("board-engine"); |
fc058d27e829
Make board engine selectable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
112
diff
changeset
|
363 |
boardEngineDom.addEventListener("change", function() { |
fc058d27e829
Make board engine selectable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
112
diff
changeset
|
364 |
var engine = boardEngineDom.value; |
fc058d27e829
Make board engine selectable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
112
diff
changeset
|
365 |
ui.brdEngine = window[engine]; |
fc058d27e829
Make board engine selectable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
112
diff
changeset
|
366 |
localStorage.brdEngine = engine; |
fc058d27e829
Make board engine selectable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
112
diff
changeset
|
367 |
}); |
15
0fa97e430a9e
ui.board.set care about 'val' argument.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
14
diff
changeset
|
368 |
/* 'val' typesafe. */ |
0 | 369 |
ui.board.set = function(i, j, val) { |
16 | 370 |
if (typeof val !== 'number') |
15
0fa97e430a9e
ui.board.set care about 'val' argument.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
14
diff
changeset
|
371 |
val = 0; |
13
b3bfa9d1b537
Add color to board depending on values..
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
12
diff
changeset
|
372 |
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
|
373 |
if (0 < val && val < 15) { |
38
d476efde7242
2 modes of value showing: 0,1,...,11 and 0,2,4,...,2048.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
37
diff
changeset
|
374 |
dom.innerHTML = ui.board.val2048(val); |
15
0fa97e430a9e
ui.board.set care about 'val' argument.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
14
diff
changeset
|
375 |
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
|
376 |
} else { |
0fa97e430a9e
ui.board.set care about 'val' argument.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
14
diff
changeset
|
377 |
dom.innerHTML = ''; |
0fa97e430a9e
ui.board.set care about 'val' argument.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
14
diff
changeset
|
378 |
var rgb = 'white'; |
0fa97e430a9e
ui.board.set care about 'val' argument.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
14
diff
changeset
|
379 |
} |
13
b3bfa9d1b537
Add color to board depending on values..
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
12
diff
changeset
|
380 |
dom.style.backgroundColor = rgb; |
0 | 381 |
} |
382 |
ui.board.update = function(brd) { |
|
383 |
for (var i = 0; i < 4; i++) { |
|
384 |
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
|
385 |
ui.board.set(i, j, brd[i][j]); |
0 | 386 |
} |
387 |
} |
|
388 |
} |
|
17 | 389 |
ui.board.handleEdit = function(tdDom, i, j) { |
390 |
if (!tdDom.firstChild || tdDom.firstChild.nodeType === Node.TEXT_NODE) { |
|
391 |
if (tdDom.firstChild) |
|
392 |
tdDom.removeChild(tdDom.firstChild); |
|
393 |
var inputDom = document.createElement('input'); |
|
45 | 394 |
inputDom.value = ui.board.position[i][j]; |
17 | 395 |
inputDom.style.width = '1em'; |
396 |
tdDom.appendChild(inputDom); |
|
397 |
inputDom.focus(); |
|
398 |
inputDom.select(); |
|
399 |
inputDom.addEventListener("blur", function(tdDom, i, j) { |
|
400 |
return function(event) { |
|
65
b8028f3e30fb
Use preventDefault()/stopPropagation(). Add false to addEventListener().
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
64
diff
changeset
|
401 |
event.preventDefault(); event.stopPropagation(); |
17 | 402 |
ui.board.handleEdit(tdDom, i, j); |
403 |
} |
|
65
b8028f3e30fb
Use preventDefault()/stopPropagation(). Add false to addEventListener().
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
64
diff
changeset
|
404 |
}(tdDom, i, j), false); |
17 | 405 |
} else { |
406 |
var inputDom = tdDom.firstChild; |
|
407 |
var val = parseInt(inputDom.value); |
|
408 |
if (0 <= val && val < 15) { |
|
45 | 409 |
ui.board.position[i][j] = val; |
17 | 410 |
ui.board.set(i, j, val); |
411 |
} else { |
|
45 | 412 |
ui.board.set(i, j, ui.board.position[i][j]); |
17 | 413 |
} |
414 |
} |
|
415 |
} |
|
416 |
ui.board.enableEdit = function() { |
|
417 |
var trDoms = boardDom.querySelectorAll("tr"); |
|
418 |
for (var i = 0; i < 4; i++) { |
|
419 |
var tdDoms = trDoms[i].querySelectorAll("td"); |
|
420 |
for (var j = 0; j < 4; j++) { |
|
421 |
var tdDom = tdDoms[j]; |
|
422 |
tdDom.addEventListener("click", function(tdDom, i, j) { |
|
423 |
return function(event) { |
|
65
b8028f3e30fb
Use preventDefault()/stopPropagation(). Add false to addEventListener().
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
64
diff
changeset
|
424 |
event.preventDefault(); event.stopPropagation(); |
17 | 425 |
ui.board.handleEdit(tdDom, i, j); |
426 |
} |
|
65
b8028f3e30fb
Use preventDefault()/stopPropagation(). Add false to addEventListener().
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
64
diff
changeset
|
427 |
}(tdDom, i, j), false); |
17 | 428 |
tdDom.addEventListener("keyup", function(tdDom, i, j) { |
429 |
return function(event) { |
|
65
b8028f3e30fb
Use preventDefault()/stopPropagation(). Add false to addEventListener().
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
64
diff
changeset
|
430 |
event.preventDefault(); event.stopPropagation(); |
17 | 431 |
if (event.keyCode === 13) |
432 |
ui.board.handleEdit(tdDom, i, j); |
|
433 |
} |
|
65
b8028f3e30fb
Use preventDefault()/stopPropagation(). Add false to addEventListener().
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
64
diff
changeset
|
434 |
}(tdDom, i, j), false); |
17 | 435 |
} |
436 |
} |
|
437 |
} |
|
438 |
ui.board.enableEdit(); |
|
439 |
||
41
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
440 |
//////////////////////////////////////////////////////////////// |
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
441 |
// Score statistic. |
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
442 |
|
0 | 443 |
ui.score = {}; |
444 |
var scoreDom = document.getElementById("score"); |
|
445 |
var maxDom = document.getElementById("max"); |
|
1 | 446 |
var speedDom = document.getElementById("speed"); |
447 |
var turnDom = document.getElementById("turn"); |
|
0 | 448 |
ui.score.clear = function(brd) { |
449 |
scoreDom.innerHTML = '0'; |
|
450 |
maxDom.innerHTML = '0'; |
|
1 | 451 |
speedDom.innerHTML = '0'; |
452 |
turnDom.innerHTML = '0'; |
|
0 | 453 |
} |
46
4dadaff6eba4
Update/store/restore game turn. Show max value according to value settings.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
45
diff
changeset
|
454 |
ui.score.update = function(brd, turn) { |
0 | 455 |
var score = board.score(brd); |
456 |
scoreDom.innerHTML = '' + score.score; |
|
46
4dadaff6eba4
Update/store/restore game turn. Show max value according to value settings.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
45
diff
changeset
|
457 |
maxDom.innerHTML = '' + ui.board.val2048(score.max); |
4dadaff6eba4
Update/store/restore game turn. Show max value according to value settings.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
45
diff
changeset
|
458 |
turnDom.innerHTML = '' + turn; |
0 | 459 |
} |
97
b3cadad6ef14
Fix: turn value sometimes cleared or incorect.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
96
diff
changeset
|
460 |
ui.score.speed = function(speed) { |
1 | 461 |
speedDom.innerHTML = '' + speed; |
462 |
} |
|
0 | 463 |
|
39
a75cc5aa5d19
Some renaming and reordering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
38
diff
changeset
|
464 |
//////////////////////////////////////////////////////////////// |
41
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
465 |
// Suggestion UI. |
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
466 |
|
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
467 |
ui.suggestion = {}; |
112
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
468 |
ui.suggestion.btns = document.querySelectorAll('div.move.control button'); |
41
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
469 |
ui.suggestion.clear = function() { |
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
470 |
for (var i = 0; i < ui.suggestion.btns.length; i++) |
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
471 |
ui.suggestion.btns[i].classList.remove('suggestion'); |
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
472 |
} |
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
473 |
ui.suggestion.set = function(dir) { |
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
474 |
document.getElementById(dir).classList.add('suggestion'); |
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
475 |
} |
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
476 |
|
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
477 |
//////////////////////////////////////////////////////////////// |
39
a75cc5aa5d19
Some renaming and reordering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
38
diff
changeset
|
478 |
// Game flow. |
a75cc5aa5d19
Some renaming and reordering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
38
diff
changeset
|
479 |
|
40 | 480 |
ui.game = {}; |
481 |
ui.game.dirs = ["up", "right", "down", "left"]; |
|
39
a75cc5aa5d19
Some renaming and reordering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
38
diff
changeset
|
482 |
|
a75cc5aa5d19
Some renaming and reordering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
38
diff
changeset
|
483 |
var messageDom = document.getElementById("message-area"); |
a75cc5aa5d19
Some renaming and reordering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
38
diff
changeset
|
484 |
ui.game.clearMessage = function() { |
a75cc5aa5d19
Some renaming and reordering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
38
diff
changeset
|
485 |
messageDom.innerHTML = ""; |
a75cc5aa5d19
Some renaming and reordering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
38
diff
changeset
|
486 |
} |
a75cc5aa5d19
Some renaming and reordering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
38
diff
changeset
|
487 |
ui.game.setMessage = function(msg) { |
a75cc5aa5d19
Some renaming and reordering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
38
diff
changeset
|
488 |
messageDom.innerHTML = msg; |
a75cc5aa5d19
Some renaming and reordering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
38
diff
changeset
|
489 |
} |
a75cc5aa5d19
Some renaming and reordering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
38
diff
changeset
|
490 |
|
a75cc5aa5d19
Some renaming and reordering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
38
diff
changeset
|
491 |
ui.game.checkGameOver = function() { |
45 | 492 |
if (board.gameOver(ui.board.position)) { |
39
a75cc5aa5d19
Some renaming and reordering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
38
diff
changeset
|
493 |
ui.game.setMessage("Game over!"); |
a75cc5aa5d19
Some renaming and reordering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
38
diff
changeset
|
494 |
return true; |
a75cc5aa5d19
Some renaming and reordering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
38
diff
changeset
|
495 |
} else { |
a75cc5aa5d19
Some renaming and reordering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
38
diff
changeset
|
496 |
return false; |
a75cc5aa5d19
Some renaming and reordering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
38
diff
changeset
|
497 |
} |
a75cc5aa5d19
Some renaming and reordering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
38
diff
changeset
|
498 |
} |
a75cc5aa5d19
Some renaming and reordering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
38
diff
changeset
|
499 |
ui.game.checkMoveValid = function(move) { |
a75cc5aa5d19
Some renaming and reordering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
38
diff
changeset
|
500 |
var tmpBrd = board.create(); |
45 | 501 |
board.copy(ui.board.position, tmpBrd); |
40 | 502 |
if (ui.game.dirs.indexOf(move) === -1) { |
39
a75cc5aa5d19
Some renaming and reordering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
38
diff
changeset
|
503 |
ui.game.setMessage("AI can't find move!"); |
a75cc5aa5d19
Some renaming and reordering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
38
diff
changeset
|
504 |
return false; |
a75cc5aa5d19
Some renaming and reordering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
38
diff
changeset
|
505 |
} |
a75cc5aa5d19
Some renaming and reordering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
38
diff
changeset
|
506 |
if ( ! board.move[move].call(null, tmpBrd)) { |
a75cc5aa5d19
Some renaming and reordering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
38
diff
changeset
|
507 |
ui.game.setMessage("AI move "+move+" is ivalid!"); |
a75cc5aa5d19
Some renaming and reordering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
38
diff
changeset
|
508 |
return false; |
a75cc5aa5d19
Some renaming and reordering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
38
diff
changeset
|
509 |
} |
a75cc5aa5d19
Some renaming and reordering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
38
diff
changeset
|
510 |
return true; |
a75cc5aa5d19
Some renaming and reordering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
38
diff
changeset
|
511 |
} |
a75cc5aa5d19
Some renaming and reordering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
38
diff
changeset
|
512 |
|
41
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
513 |
ui.game.beginStep = function() { |
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
514 |
ui.suggestion.clear(); |
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
515 |
ui.game.clearMessage(); |
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
516 |
if (ui.game.checkGameOver()) |
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
517 |
return false; |
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
518 |
return true; |
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
519 |
} |
94
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
520 |
ui.game.refresh = function() { |
45 | 521 |
ui.board.update(ui.board.position); |
46
4dadaff6eba4
Update/store/restore game turn. Show max value according to value settings.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
45
diff
changeset
|
522 |
ui.score.update(ui.board.position, ui.board.turn); |
45 | 523 |
localStorage.savedBoard = JSON.stringify(ui.board.position); |
46
4dadaff6eba4
Update/store/restore game turn. Show max value according to value settings.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
45
diff
changeset
|
524 |
localStorage.savedTurn = ui.board.turn; |
41
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
525 |
} |
94
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
526 |
ui.game.finishStep = function() { |
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
527 |
board.putRandom(ui.board.position); |
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
528 |
ui.board.turn++; |
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
529 |
ui.game.refresh(); |
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
530 |
} |
41
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
531 |
|
39
a75cc5aa5d19
Some renaming and reordering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
38
diff
changeset
|
532 |
//////////////////////////////////////////////////////////////// |
a75cc5aa5d19
Some renaming and reordering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
38
diff
changeset
|
533 |
// Actions. |
a75cc5aa5d19
Some renaming and reordering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
38
diff
changeset
|
534 |
|
30
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
535 |
ui.action = {}; |
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
536 |
|
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
537 |
ui.action.start = function() { |
0 | 538 |
ui.score.clear(); |
41
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
539 |
ui.suggestion.clear(); |
39
a75cc5aa5d19
Some renaming and reordering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
38
diff
changeset
|
540 |
ui.game.clearMessage(); |
46
4dadaff6eba4
Update/store/restore game turn. Show max value according to value settings.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
45
diff
changeset
|
541 |
ui.board.turn = 0; |
45 | 542 |
ui.board.position = board.create(); |
543 |
board.putRandom(ui.board.position); |
|
544 |
ui.board.update(ui.board.position); |
|
0 | 545 |
} |
65
b8028f3e30fb
Use preventDefault()/stopPropagation(). Add false to addEventListener().
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
64
diff
changeset
|
546 |
document.getElementById("start").addEventListener("click", ui.action.start, false); |
0 | 547 |
|
40 | 548 |
for (var i = 0; i < ui.game.dirs.length; i++) { |
549 |
var dir = ui.game.dirs[i]; |
|
550 |
ui.action[dir] = function(dir) { |
|
65
b8028f3e30fb
Use preventDefault()/stopPropagation(). Add false to addEventListener().
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
64
diff
changeset
|
551 |
return function(event) { |
b8028f3e30fb
Use preventDefault()/stopPropagation(). Add false to addEventListener().
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
64
diff
changeset
|
552 |
event.preventDefault(); event.stopPropagation(); |
40 | 553 |
if (ui.game.checkGameOver()) |
554 |
return; |
|
41
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
555 |
ui.suggestion.clear(); |
45 | 556 |
var updated = board.move[dir](ui.board.position); |
40 | 557 |
if (updated) { |
41
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
558 |
ui.game.finishStep(); |
40 | 559 |
ui.ai.current && ui.ai.current.cleanup(); |
560 |
} |
|
561 |
} |
|
562 |
} (dir); |
|
65
b8028f3e30fb
Use preventDefault()/stopPropagation(). Add false to addEventListener().
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
64
diff
changeset
|
563 |
document.getElementById(dir).addEventListener("click", ui.action[dir], false); |
0 | 564 |
} |
565 |
||
566 |
document.body.addEventListener("keydown", function(event) { |
|
37
fe75d168a605
Ignore board movement when user edit input.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
36
diff
changeset
|
567 |
if (document.activeElement.value) |
44
518ab579d24b
Prevent from blocking Firefox key binding.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
43
diff
changeset
|
568 |
return; |
52
e4e21d2fcbe7
Ignore moves if shift/alt/control key pressed.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
46
diff
changeset
|
569 |
if (event.altKey || event.ctrlKey || event.shiftKey || event.metaKey) |
e4e21d2fcbe7
Ignore moves if shift/alt/control key pressed.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
46
diff
changeset
|
570 |
return; |
0 | 571 |
var key = event.keyCode || event.which; |
44
518ab579d24b
Prevent from blocking Firefox key binding.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
43
diff
changeset
|
572 |
var keyMoves = {38: "up", 40: "down", 37: "left", 39: "right"}; |
518ab579d24b
Prevent from blocking Firefox key binding.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
43
diff
changeset
|
573 |
if (key in keyMoves) { |
65
b8028f3e30fb
Use preventDefault()/stopPropagation(). Add false to addEventListener().
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
64
diff
changeset
|
574 |
ui.action[keyMoves[key]](event); |
0 | 575 |
} |
65
b8028f3e30fb
Use preventDefault()/stopPropagation(). Add false to addEventListener().
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
64
diff
changeset
|
576 |
}, false); |
12
a9a44cfc3e08
Moves for 2d array board + test toolkit.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
11
diff
changeset
|
577 |
|
a9a44cfc3e08
Moves for 2d array board + test toolkit.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
11
diff
changeset
|
578 |
document.getElementById("test").addEventListener("click", function() { |
65
b8028f3e30fb
Use preventDefault()/stopPropagation(). Add false to addEventListener().
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
64
diff
changeset
|
579 |
event.preventDefault(); event.stopPropagation(); |
12
a9a44cfc3e08
Moves for 2d array board + test toolkit.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
11
diff
changeset
|
580 |
board.move.replaceByBoardJS(ui.brdEngine); |
65
b8028f3e30fb
Use preventDefault()/stopPropagation(). Add false to addEventListener().
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
64
diff
changeset
|
581 |
}, false); |
34 | 582 |
|
65
b8028f3e30fb
Use preventDefault()/stopPropagation(). Add false to addEventListener().
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
64
diff
changeset
|
583 |
ui.action.suggest = function(event) { |
b8028f3e30fb
Use preventDefault()/stopPropagation(). Add false to addEventListener().
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
64
diff
changeset
|
584 |
event.preventDefault(); event.stopPropagation(); |
41
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
585 |
if ( ! ui.ai.current) { |
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
586 |
ui.game.setMessage('Select AI!'); |
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
587 |
return; |
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
588 |
} |
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
589 |
if ( ! ui.game.beginStep()) |
0 | 590 |
return; |
591 |
var tmpBrd = board.create(); |
|
45 | 592 |
board.copy(ui.board.position, tmpBrd); |
25
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
593 |
var move = ui.ai.current.analyse(tmpBrd); |
34 | 594 |
ui.ai.current.cleanup(); |
39
a75cc5aa5d19
Some renaming and reordering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
38
diff
changeset
|
595 |
if ( ! ui.game.checkMoveValid(move)) |
34 | 596 |
return; |
41
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
597 |
ui.suggestion.set(move); |
34 | 598 |
} |
65
b8028f3e30fb
Use preventDefault()/stopPropagation(). Add false to addEventListener().
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
64
diff
changeset
|
599 |
document.getElementById("suggest").addEventListener("click", ui.action.suggest, false); |
34 | 600 |
ui.action.step = function() { |
41
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
601 |
if ( ! ui.ai.current) { |
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
602 |
ui.game.setMessage('Select AI!'); |
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
603 |
return; |
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
604 |
} |
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
605 |
if ( ! ui.game.beginStep()) |
0 | 606 |
return; |
34 | 607 |
var tmpBrd = board.create(); |
45 | 608 |
board.copy(ui.board.position, tmpBrd); |
34 | 609 |
var move = ui.ai.current.analyse(tmpBrd); |
610 |
ui.ai.current.cleanup(); |
|
39
a75cc5aa5d19
Some renaming and reordering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
38
diff
changeset
|
611 |
if ( ! ui.game.checkMoveValid(move)) |
34 | 612 |
return; |
45 | 613 |
board.move[move].call(null, ui.board.position); |
41
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
614 |
ui.game.finishStep(); |
0 | 615 |
} |
65
b8028f3e30fb
Use preventDefault()/stopPropagation(). Add false to addEventListener().
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
64
diff
changeset
|
616 |
document.getElementById("step").addEventListener("click", ui.action.step, false); |
0 | 617 |
|
131 | 618 |
ui.action.visualFinishAux = function() { |
123
fc6019d22a38
Visual AI actions mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
113
diff
changeset
|
619 |
if ( ! ui.game.beginStep()) |
fc6019d22a38
Visual AI actions mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
113
diff
changeset
|
620 |
return; |
fc6019d22a38
Visual AI actions mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
113
diff
changeset
|
621 |
var brd = board.create(); |
fc6019d22a38
Visual AI actions mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
113
diff
changeset
|
622 |
board.copy(ui.board.position, brd); |
fc6019d22a38
Visual AI actions mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
113
diff
changeset
|
623 |
var move = ui.ai.current.analyse(brd); |
fc6019d22a38
Visual AI actions mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
113
diff
changeset
|
624 |
if ( ! ui.game.checkMoveValid(move)) |
fc6019d22a38
Visual AI actions mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
113
diff
changeset
|
625 |
return; |
fc6019d22a38
Visual AI actions mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
113
diff
changeset
|
626 |
board.move[move].call(null, ui.board.position); |
fc6019d22a38
Visual AI actions mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
113
diff
changeset
|
627 |
ui.game.finishStep(); |
fc6019d22a38
Visual AI actions mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
113
diff
changeset
|
628 |
setTimeout(ui.action.visualFinishAux, 10); |
fc6019d22a38
Visual AI actions mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
113
diff
changeset
|
629 |
} |
fc6019d22a38
Visual AI actions mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
113
diff
changeset
|
630 |
ui.action.visualFinish = function() { |
fc6019d22a38
Visual AI actions mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
113
diff
changeset
|
631 |
if ( ! ui.ai.current) { |
fc6019d22a38
Visual AI actions mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
113
diff
changeset
|
632 |
ui.game.setMessage('Select AI!'); |
fc6019d22a38
Visual AI actions mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
113
diff
changeset
|
633 |
return; |
fc6019d22a38
Visual AI actions mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
113
diff
changeset
|
634 |
} |
fc6019d22a38
Visual AI actions mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
113
diff
changeset
|
635 |
ui.action.visualFinishAux(); |
fc6019d22a38
Visual AI actions mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
113
diff
changeset
|
636 |
}; |
fc6019d22a38
Visual AI actions mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
113
diff
changeset
|
637 |
document.getElementById("visual-finish").addEventListener("click", ui.action.visualFinish, false); |
fc6019d22a38
Visual AI actions mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
113
diff
changeset
|
638 |
|
30
1d19768ca71d
Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
27
diff
changeset
|
639 |
ui.action.finish = function() { |
138
23cd36180bf9
Add ability to enable browser profile.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
137
diff
changeset
|
640 |
var isProfile = document.getElementById("profile").checked; |
23cd36180bf9
Add ability to enable browser profile.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
137
diff
changeset
|
641 |
if (isProfile) |
23cd36180bf9
Add ability to enable browser profile.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
137
diff
changeset
|
642 |
console.profile(); |
41
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
643 |
if ( ! ui.ai.current) { |
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
644 |
ui.game.setMessage('Select AI!'); |
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
645 |
return; |
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
646 |
} |
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
647 |
ui.game.beginStep(); |
1 | 648 |
var step = 0; |
66
c62a1051cef7
Move object creation out of loop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
65
diff
changeset
|
649 |
var safeBdr = board.create(); |
1 | 650 |
var tsFrom = new Date().getTime(); |
45 | 651 |
while (!board.gameOver(ui.board.position)) { |
66
c62a1051cef7
Move object creation out of loop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
65
diff
changeset
|
652 |
board.copy(ui.board.position, safeBdr); |
c62a1051cef7
Move object creation out of loop.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
65
diff
changeset
|
653 |
var move = ui.ai.current.analyse(safeBdr); |
10
70ece7f758a0
Move rule and AI engine to separate files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
7
diff
changeset
|
654 |
if (typeof move === 'undefined') { |
39
a75cc5aa5d19
Some renaming and reordering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
38
diff
changeset
|
655 |
ui.game.setMessage("I don't know how to move!"); |
0 | 656 |
return; |
657 |
} |
|
45 | 658 |
var updated = board.move[move].call(null, ui.board.position); |
0 | 659 |
if (updated) { |
45 | 660 |
board.putRandom(ui.board.position); |
0 | 661 |
} else { |
97
b3cadad6ef14
Fix: turn value sometimes cleared or incorect.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
96
diff
changeset
|
662 |
ui.board.turn += step; |
b3cadad6ef14
Fix: turn value sometimes cleared or incorect.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
96
diff
changeset
|
663 |
ui.game.refresh(); |
39
a75cc5aa5d19
Some renaming and reordering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
38
diff
changeset
|
664 |
ui.game.setMessage("Wrong move!"); |
0 | 665 |
return; |
666 |
} |
|
1 | 667 |
step++; |
0 | 668 |
} |
1 | 669 |
var tsTo = new Date().getTime(); |
97
b3cadad6ef14
Fix: turn value sometimes cleared or incorect.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
96
diff
changeset
|
670 |
ui.board.turn += step; |
137
be8ee2240a17
Fix: error thrown, wrong function called.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
134
diff
changeset
|
671 |
ui.game.refresh(); |
97
b3cadad6ef14
Fix: turn value sometimes cleared or incorect.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
96
diff
changeset
|
672 |
ui.score.speed(parseFloat((step*1000.0/(tsTo-tsFrom)).toPrecision(3))); |
39
a75cc5aa5d19
Some renaming and reordering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
38
diff
changeset
|
673 |
ui.game.setMessage("Game over!"); |
96
a9a6e08c9e35
Remove unnecessary check.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
95
diff
changeset
|
674 |
ui.ai.current.cleanup(); |
138
23cd36180bf9
Add ability to enable browser profile.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
137
diff
changeset
|
675 |
if (isProfile) |
23cd36180bf9
Add ability to enable browser profile.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
137
diff
changeset
|
676 |
console.profileEnd(); |
0 | 677 |
} |
65
b8028f3e30fb
Use preventDefault()/stopPropagation(). Add false to addEventListener().
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
64
diff
changeset
|
678 |
document.getElementById("finish").addEventListener("click", ui.action.finish, false); |
0 | 679 |
|
94
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
680 |
ui.action.until = function() { |
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
681 |
if ( ! ui.ai.current) { |
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
682 |
ui.game.setMessage('Select AI!'); |
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
683 |
return; |
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
684 |
} |
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
685 |
if ( ! ui.game.beginStep()) |
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
686 |
return; |
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
687 |
var step = 0; |
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
688 |
var safeBdr = board.create(); |
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
689 |
var tsFrom = new Date().getTime(); |
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
690 |
var scoreLimit = parseInt(document.getElementById("until-score").value); |
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
691 |
if (!isFinite(scoreLimit) || scoreLimit < 0) { |
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
692 |
scoreLimit = 1; |
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
693 |
document.getElementById("until-score").value = scoreLimit; |
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
694 |
} |
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
695 |
var maxValLimit = parseInt(document.getElementById("until-max-value").value); |
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
696 |
if (!isFinite(maxValLimit) || maxValLimit < 0 || maxValLimit > 13) { |
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
697 |
maxValLimit = 1; |
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
698 |
document.getElementById("until-max-value").value = maxValLimit; |
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
699 |
} |
95
804e751a3b7f
Save and restore continuation limits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
94
diff
changeset
|
700 |
localStorage.untilScore = scoreLimit; |
804e751a3b7f
Save and restore continuation limits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
94
diff
changeset
|
701 |
localStorage.untilMaxVal = maxValLimit; |
94
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
702 |
while (true) { |
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
703 |
if (board.gameOver(ui.board.position)) { |
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
704 |
ui.game.setMessage("Game over!"); |
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
705 |
break; |
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
706 |
} |
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
707 |
var stat = board.score(ui.board.position); |
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
708 |
if (stat.score >= scoreLimit && stat.max >= maxValLimit) |
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
709 |
break; |
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
710 |
board.copy(ui.board.position, safeBdr); |
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
711 |
var move = ui.ai.current.analyse(safeBdr); |
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
712 |
if (typeof move === 'undefined') { |
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
713 |
ui.game.setMessage("I don't know how to move!"); |
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
714 |
return; |
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
715 |
} |
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
716 |
var updated = board.move[move].call(null, ui.board.position); |
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
717 |
if (updated) { |
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
718 |
board.putRandom(ui.board.position); |
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
719 |
} else { |
41
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
720 |
ui.game.finishStep(); |
39
a75cc5aa5d19
Some renaming and reordering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
38
diff
changeset
|
721 |
ui.game.setMessage("Wrong move!"); |
0 | 722 |
return; |
723 |
} |
|
1 | 724 |
step++; |
0 | 725 |
} |
1 | 726 |
var tsTo = new Date().getTime(); |
97
b3cadad6ef14
Fix: turn value sometimes cleared or incorect.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
96
diff
changeset
|
727 |
ui.board.turn += step; |
94
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
728 |
ui.game.refresh(); |
97
b3cadad6ef14
Fix: turn value sometimes cleared or incorect.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
96
diff
changeset
|
729 |
ui.score.speed(parseFloat((step*1000.0/(tsTo-tsFrom)).toPrecision(3))); |
96
a9a6e08c9e35
Remove unnecessary check.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
95
diff
changeset
|
730 |
ui.ai.current.cleanup(); |
0 | 731 |
} |
94
8bbd7570f437
Iterate by AI until score or max value occur.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
88
diff
changeset
|
732 |
document.getElementById("until").addEventListener("click", ui.action.until, false); |
0 | 733 |
|
10
70ece7f758a0
Move rule and AI engine to separate files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
7
diff
changeset
|
734 |
//////////////////////////////////////////////////////////////// |
70ece7f758a0
Move rule and AI engine to separate files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
7
diff
changeset
|
735 |
// Register AIs. |
0 | 736 |
|
25
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
737 |
ui.ai = {}; |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
738 |
ui.ai.current = null; |
53
ee53cd2cb69a
Join all one step deep AIs into one with linear weight function.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
52
diff
changeset
|
739 |
ui.ai.parseCfg = function(aiDom, cfg) { |
102
6c057ac86c97
Show AI config in report as title.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
101
diff
changeset
|
740 |
cfg = cfg || {}; |
55
8ba9dc89be87
Automatically extract config from DOM.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
53
diff
changeset
|
741 |
var optDoms = aiDom.querySelectorAll("div.option > input.positive[type='text']"); |
53
ee53cd2cb69a
Join all one step deep AIs into one with linear weight function.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
52
diff
changeset
|
742 |
for (var i = 0; i < optDoms.length; i++) { |
ee53cd2cb69a
Join all one step deep AIs into one with linear weight function.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
52
diff
changeset
|
743 |
var val = parseFloat(optDoms[i].value); |
55
8ba9dc89be87
Automatically extract config from DOM.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
53
diff
changeset
|
744 |
if (val === NaN || val < 0) { |
8ba9dc89be87
Automatically extract config from DOM.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
53
diff
changeset
|
745 |
ui.game.setMessage('' + optDoms[i].name + ' is not a positive number!'); |
8ba9dc89be87
Automatically extract config from DOM.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
53
diff
changeset
|
746 |
cfg[optDoms[i].name] = 1; |
53
ee53cd2cb69a
Join all one step deep AIs into one with linear weight function.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
52
diff
changeset
|
747 |
continue; |
ee53cd2cb69a
Join all one step deep AIs into one with linear weight function.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
52
diff
changeset
|
748 |
} |
ee53cd2cb69a
Join all one step deep AIs into one with linear weight function.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
52
diff
changeset
|
749 |
cfg[optDoms[i].name] = val; |
ee53cd2cb69a
Join all one step deep AIs into one with linear weight function.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
52
diff
changeset
|
750 |
} |
103
54dfc3b4e7d3
Parse checkbox AI config automatically.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
102
diff
changeset
|
751 |
var optDoms = aiDom.querySelectorAll("div.option > input[type='checkbox']"); |
54dfc3b4e7d3
Parse checkbox AI config automatically.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
102
diff
changeset
|
752 |
for (var i = 0; i < optDoms.length; i++) { |
54dfc3b4e7d3
Parse checkbox AI config automatically.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
102
diff
changeset
|
753 |
cfg[optDoms[i].name] = optDoms[i].checked; |
54dfc3b4e7d3
Parse checkbox AI config automatically.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
102
diff
changeset
|
754 |
} |
102
6c057ac86c97
Show AI config in report as title.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
101
diff
changeset
|
755 |
return cfg; |
6c057ac86c97
Show AI config in report as title.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
101
diff
changeset
|
756 |
} |
6c057ac86c97
Show AI config in report as title.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
101
diff
changeset
|
757 |
ui.ai.cfgTitle = function(aiName) { |
6c057ac86c97
Show AI config in report as title.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
101
diff
changeset
|
758 |
var title = JSON.stringify(ui.ai.parseCfg(document.getElementById(aiName))).replace(":", ": ", "g").replace(",", "\n", "g"); |
6c057ac86c97
Show AI config in report as title.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
101
diff
changeset
|
759 |
title = title.substr(1); |
6c057ac86c97
Show AI config in report as title.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
101
diff
changeset
|
760 |
title = title.substr(0, title.length-1); |
6c057ac86c97
Show AI config in report as title.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
101
diff
changeset
|
761 |
return title; |
53
ee53cd2cb69a
Join all one step deep AIs into one with linear weight function.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
52
diff
changeset
|
762 |
} |
55
8ba9dc89be87
Automatically extract config from DOM.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
53
diff
changeset
|
763 |
|
25
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
764 |
ui.ai.algList = { |
35 | 765 |
"ai-blind-random": function() { |
59 | 766 |
return new ai.BlindRandom(ui.brdEngine); |
25
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
767 |
}, |
36
a18fc2601ce8
Add blind eight random AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
35
diff
changeset
|
768 |
"ai-blind-weight-random": function(aiDom) { |
102
6c057ac86c97
Show AI config in report as title.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
101
diff
changeset
|
769 |
var cfg = ui.ai.parseCfg(aiDom); |
59 | 770 |
return new ai.BlindWeightRandom(ui.brdEngine, cfg); |
36
a18fc2601ce8
Add blind eight random AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
35
diff
changeset
|
771 |
}, |
27
8f96d09a4d94
Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
26
diff
changeset
|
772 |
"ai-blind-cycle": function(aiDom) { |
103
54dfc3b4e7d3
Parse checkbox AI config automatically.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
102
diff
changeset
|
773 |
var cfg = ui.ai.parseCfg(aiDom); |
59 | 774 |
return new ai.BlindCycle(ui.brdEngine, cfg); |
27
8f96d09a4d94
Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
26
diff
changeset
|
775 |
}, |
99 | 776 |
"ai-one-step-ahead": function(aiDom) { |
102
6c057ac86c97
Show AI config in report as title.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
101
diff
changeset
|
777 |
var cfg = ui.ai.parseCfg(aiDom); |
99 | 778 |
return new ai.OneStepAhead(ui.brdEngine, cfg); |
25
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
779 |
}, |
110
e3a91b336976
Join N level deep on score value without random simulation AIs and add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
104
diff
changeset
|
780 |
"ai-static-deep-merges": function(aiDom) { |
e3a91b336976
Join N level deep on score value without random simulation AIs and add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
104
diff
changeset
|
781 |
var cfg = ui.ai.parseCfg(aiDom); |
e3a91b336976
Join N level deep on score value without random simulation AIs and add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
104
diff
changeset
|
782 |
return new ai.StaticDeepMerges(ui.brdEngine, cfg); |
25
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
783 |
}, |
74
93cb48b73b39
Enable config for expectimax. Fix weight function for expectimax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
73
diff
changeset
|
784 |
"ai-expectimax": function(aiDom) { |
102
6c057ac86c97
Show AI config in report as title.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
101
diff
changeset
|
785 |
var cfg = ui.ai.parseCfg(aiDom); |
74
93cb48b73b39
Enable config for expectimax. Fix weight function for expectimax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
73
diff
changeset
|
786 |
return new ai.expectimax(ui.brdEngine, cfg); |
25
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
787 |
}, |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
788 |
// "": function() { |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
789 |
// return new ai.(ui.brdEngine); |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
790 |
// }, |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
791 |
}; |
112
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
792 |
ui.ai.domList = document.querySelectorAll('div.ai-list > div.ai'); |
25
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
793 |
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
|
794 |
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
|
795 |
ui.ai.enable(event.target.parentNode); |
65
b8028f3e30fb
Use preventDefault()/stopPropagation(). Add false to addEventListener().
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
64
diff
changeset
|
796 |
}, false); |
25
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
797 |
} |
0 | 798 |
|
25
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
799 |
ui.ai.moveToTop = function(aiDom) { |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
800 |
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
|
801 |
ui.ai.domList[i].classList.remove('enabled'); |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
802 |
} |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
803 |
var rootDom = aiDom.parentNode; |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
804 |
rootDom.removeChild(aiDom); |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
805 |
rootDom.insertBefore(aiDom, rootDom.firstChild); |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
806 |
aiDom.classList.add('enabled'); |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
807 |
} |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
808 |
ui.ai.enable = function(aiDom) { |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
809 |
if (ui.ai.current) |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
810 |
ui.ai.current.cleanup(); |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
811 |
ui.ai.moveToTop(aiDom); |
27
8f96d09a4d94
Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
26
diff
changeset
|
812 |
ui.ai.current = ui.ai.algList[aiDom.id](aiDom); |
71
aa0240db128a
Show statistic reports.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
70
diff
changeset
|
813 |
ui.ai.currentName = aiDom.id; |
25
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
814 |
} |
2ef10a49a28f
Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
21
diff
changeset
|
815 |
|
62 | 816 |
|
817 |
//////////////////////////////////////////////////////////////// |
|
818 |
// Reports and statistic. |
|
819 |
||
71
aa0240db128a
Show statistic reports.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
70
diff
changeset
|
820 |
var reportsDom = document.getElementById('reports'); |
aa0240db128a
Show statistic reports.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
70
diff
changeset
|
821 |
|
73
a50828ac954d
Remove code duplication.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
72
diff
changeset
|
822 |
ui.report = {}; |
101
7f944bece417
Add number to statistic reports.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
100
diff
changeset
|
823 |
ui.report.statNo = 1; |
73
a50828ac954d
Remove code duplication.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
72
diff
changeset
|
824 |
|
128
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
825 |
ui.report.update = function(histo, brd, tsDelta, turn) { |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
826 |
var stat = board.score(brd); |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
827 |
var speed = turn * 1000 / tsDelta; |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
828 |
var score = stat.score; |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
829 |
var max = stat.max; |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
830 |
if ( ! histo[max]) { |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
831 |
var row = histo[max] = { n: 1 }; |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
832 |
row.minScore = score; row.meanScore = score; row.maxScore = score; |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
833 |
row.minSpeed = speed; row.meanSpeed = speed; row.maxSpeed = speed; |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
834 |
row.minTurn = turn; row.meanTurn = turn; row.maxTurn = turn; |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
835 |
} else { |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
836 |
var row = histo[max]; |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
837 |
row.n++; |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
838 |
row.minScore = Math.min(row.minScore, score); |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
839 |
row.meanScore += score; |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
840 |
row.maxScore = Math.max(row.maxScore, score); |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
841 |
row.minSpeed = Math.min(row.minSpeed, speed); |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
842 |
row.meanSpeed += speed; |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
843 |
row.maxSpeed = Math.max(row.maxSpeed, speed); |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
844 |
row.minTurn = Math.min(row.minTurn, turn); |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
845 |
row.meanTurn += turn; |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
846 |
row.maxTurn = Math.max(row.maxTurn, turn); |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
847 |
} |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
848 |
} |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
849 |
ui.report.fix = function(histo) { |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
850 |
for (var i in histo) { |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
851 |
var row = histo[i]; |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
852 |
var n = row.n; |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
853 |
row.meanScore = row.meanScore / n; |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
854 |
row.meanTurn = row.meanTurn / n; |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
855 |
row.meanSpeed = row.meanSpeed / n; |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
856 |
} |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
857 |
} |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
858 |
ui.report.show = function(histo, gameCnt) { |
127
4cc0421184ac
Don't store intermediate statistic data.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
123
diff
changeset
|
859 |
var scoreChecked = document.getElementById('report-score').checked; |
4cc0421184ac
Don't store intermediate statistic data.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
123
diff
changeset
|
860 |
var turnChecked = document.getElementById('report-turn').checked; |
4cc0421184ac
Don't store intermediate statistic data.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
123
diff
changeset
|
861 |
var speedChecked = document.getElementById('report-speed').checked; |
71
aa0240db128a
Show statistic reports.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
70
diff
changeset
|
862 |
var reportDom = document.createElement('div'); |
112
4bb8ed8448bc
Reduce CSS style classes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
111
diff
changeset
|
863 |
reportDom.classList.add('option'); |
71
aa0240db128a
Show statistic reports.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
70
diff
changeset
|
864 |
var h5Dom = document.createElement('h5'); |
101
7f944bece417
Add number to statistic reports.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
100
diff
changeset
|
865 |
h5Dom.appendChild(document.createTextNode(ui.ai.currentName + " #" + ui.report.statNo++)); |
71
aa0240db128a
Show statistic reports.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
70
diff
changeset
|
866 |
reportDom.appendChild(h5Dom); |
72
0d1e5bbcde82
Fix value ordering. Fix game counting when time limit reached.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
71
diff
changeset
|
867 |
var maxVals = Object.keys(histo).sort(function(a,b){return a - b}); |
73
a50828ac954d
Remove code duplication.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
72
diff
changeset
|
868 |
var tbl = []; |
71
aa0240db128a
Show statistic reports.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
70
diff
changeset
|
869 |
for (var i = maxVals.length-1; i >= 0; i--) { |
aa0240db128a
Show statistic reports.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
70
diff
changeset
|
870 |
var maxVal = maxVals[i]; |
aa0240db128a
Show statistic reports.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
70
diff
changeset
|
871 |
var row = histo[maxVals[i]]; |
73
a50828ac954d
Remove code duplication.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
72
diff
changeset
|
872 |
var perc = parseFloat((100 * row.n / gameCnt).toPrecision(3)); |
75
ab74c80beffd
Add score, turn and speed statistic selection.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
74
diff
changeset
|
873 |
var tblRow = [maxVal, row.n, perc]; |
ab74c80beffd
Add score, turn and speed statistic selection.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
74
diff
changeset
|
874 |
if (scoreChecked) { |
ab74c80beffd
Add score, turn and speed statistic selection.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
74
diff
changeset
|
875 |
tblRow.push(row.minScore); |
ab74c80beffd
Add score, turn and speed statistic selection.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
74
diff
changeset
|
876 |
var meanScore = parseFloat(row.meanScore.toPrecision(3)); |
ab74c80beffd
Add score, turn and speed statistic selection.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
74
diff
changeset
|
877 |
tblRow.push(meanScore); |
ab74c80beffd
Add score, turn and speed statistic selection.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
74
diff
changeset
|
878 |
tblRow.push(row.maxScore); |
ab74c80beffd
Add score, turn and speed statistic selection.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
74
diff
changeset
|
879 |
} |
ab74c80beffd
Add score, turn and speed statistic selection.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
74
diff
changeset
|
880 |
if (turnChecked) { |
ab74c80beffd
Add score, turn and speed statistic selection.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
74
diff
changeset
|
881 |
tblRow.push(row.minTurn); |
ab74c80beffd
Add score, turn and speed statistic selection.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
74
diff
changeset
|
882 |
tblRow.push(Math.floor(row.meanTurn)); |
ab74c80beffd
Add score, turn and speed statistic selection.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
74
diff
changeset
|
883 |
tblRow.push(row.maxTurn); |
ab74c80beffd
Add score, turn and speed statistic selection.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
74
diff
changeset
|
884 |
} |
ab74c80beffd
Add score, turn and speed statistic selection.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
74
diff
changeset
|
885 |
if (speedChecked) { |
ab74c80beffd
Add score, turn and speed statistic selection.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
74
diff
changeset
|
886 |
tblRow.push(parseFloat(row.minSpeed.toPrecision(3))); |
ab74c80beffd
Add score, turn and speed statistic selection.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
74
diff
changeset
|
887 |
tblRow.push(parseFloat(row.meanSpeed.toPrecision(3))); |
ab74c80beffd
Add score, turn and speed statistic selection.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
74
diff
changeset
|
888 |
tblRow.push(parseFloat(row.maxSpeed.toPrecision(3))); |
ab74c80beffd
Add score, turn and speed statistic selection.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
74
diff
changeset
|
889 |
} |
ab74c80beffd
Add score, turn and speed statistic selection.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
74
diff
changeset
|
890 |
tbl.push(tblRow); |
71
aa0240db128a
Show statistic reports.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
70
diff
changeset
|
891 |
} |
132
8715659bcce6
Add newline processing in report table cells.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
131
diff
changeset
|
892 |
var tblCols = ['max\nval', 'n', '%']; |
75
ab74c80beffd
Add score, turn and speed statistic selection.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
74
diff
changeset
|
893 |
if (scoreChecked) { |
132
8715659bcce6
Add newline processing in report table cells.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
131
diff
changeset
|
894 |
tblCols.push('min\nscore'); |
8715659bcce6
Add newline processing in report table cells.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
131
diff
changeset
|
895 |
tblCols.push('mean\nscore'); |
8715659bcce6
Add newline processing in report table cells.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
131
diff
changeset
|
896 |
tblCols.push('max\nscore'); |
75
ab74c80beffd
Add score, turn and speed statistic selection.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
74
diff
changeset
|
897 |
} |
ab74c80beffd
Add score, turn and speed statistic selection.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
74
diff
changeset
|
898 |
if (turnChecked) { |
132
8715659bcce6
Add newline processing in report table cells.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
131
diff
changeset
|
899 |
tblCols.push('min\nturn'); |
8715659bcce6
Add newline processing in report table cells.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
131
diff
changeset
|
900 |
tblCols.push('mean\nturn'); |
8715659bcce6
Add newline processing in report table cells.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
131
diff
changeset
|
901 |
tblCols.push('max\nturn'); |
75
ab74c80beffd
Add score, turn and speed statistic selection.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
74
diff
changeset
|
902 |
} |
ab74c80beffd
Add score, turn and speed statistic selection.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
74
diff
changeset
|
903 |
if (speedChecked) { |
132
8715659bcce6
Add newline processing in report table cells.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
131
diff
changeset
|
904 |
tblCols.push('min\nspeed'); |
8715659bcce6
Add newline processing in report table cells.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
131
diff
changeset
|
905 |
tblCols.push('mean\nspeed'); |
8715659bcce6
Add newline processing in report table cells.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
131
diff
changeset
|
906 |
tblCols.push('max\nspeed'); |
75
ab74c80beffd
Add score, turn and speed statistic selection.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
74
diff
changeset
|
907 |
} |
102
6c057ac86c97
Show AI config in report as title.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
101
diff
changeset
|
908 |
var tableDom = ui.dom.table(tbl, tblCols, { tblClass: 'report-by-maxval', tblTitle: ui.ai.cfgTitle(ui.ai.currentName) }); |
71
aa0240db128a
Show statistic reports.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
70
diff
changeset
|
909 |
reportDom.appendChild(tableDom); |
aa0240db128a
Show statistic reports.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
70
diff
changeset
|
910 |
reportsDom.insertBefore(reportDom, reportsDom.firstChild); |
128
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
911 |
} |
129
e0958e521716
Break limit on script execution time for statistic gathering
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
128
diff
changeset
|
912 |
ui.report.start = function() { |
130
28694f058ea4
Make a way to stop statistic gathering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
129
diff
changeset
|
913 |
ui.report.executed = true; |
128
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
914 |
var histo = {}; |
129
e0958e521716
Break limit on script execution time for statistic gathering
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
128
diff
changeset
|
915 |
var gameCntLimit = parseInt(document.getElementById('stat-count-limit').value); |
e0958e521716
Break limit on script execution time for statistic gathering
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
128
diff
changeset
|
916 |
if (isNaN(gameCntLimit) || !isFinite(gameCntLimit) || gameCntLimit < 1) |
e0958e521716
Break limit on script execution time for statistic gathering
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
128
diff
changeset
|
917 |
gameCntLimit = 100; |
128
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
918 |
var tsLimit = parseFloat(document.getElementById('stat-count-limit').value); |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
919 |
if (isNaN(tsLimit) || !isFinite(tsLimit) || tsLimit < 1 || tsLimit > 60) |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
920 |
tsLimit = 1000 * 10; |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
921 |
else |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
922 |
tsLimit = 1000 * tsLimit; |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
923 |
var safeBdr = board.create(); |
129
e0958e521716
Break limit on script execution time for statistic gathering
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
128
diff
changeset
|
924 |
function play() { |
128
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
925 |
var turn = 0; |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
926 |
var brd = board.create(); |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
927 |
board.putRandom(brd); |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
928 |
var tsFrom = new Date().getTime(); |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
929 |
while (!board.gameOver(brd)) { |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
930 |
board.copy(brd, safeBdr); |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
931 |
var move = ui.ai.current.analyse(safeBdr); |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
932 |
if (ui.game.dirs.indexOf(move) < 0) { |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
933 |
ui.game.setMessage("I don't know how to move!"); |
129
e0958e521716
Break limit on script execution time for statistic gathering
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
128
diff
changeset
|
934 |
throw Error("AI make illegal move '" + move + "'..."); |
128
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
935 |
} |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
936 |
var updated = board.move[move].call(null, brd); |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
937 |
if (!updated) { |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
938 |
ui.game.setMessage("Wrong move!"); |
129
e0958e521716
Break limit on script execution time for statistic gathering
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
128
diff
changeset
|
939 |
throw Error("AI make illegal move '" + move + "'..."); |
128
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
940 |
} |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
941 |
board.putRandom(brd); |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
942 |
turn++; |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
943 |
} |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
944 |
var tsTo = new Date().getTime(); |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
945 |
ui.report.update(histo, brd, tsTo-tsFrom, turn); |
673743a1290d
Move statistic gathering and displaying logic to separate functions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
127
diff
changeset
|
946 |
} |
129
e0958e521716
Break limit on script execution time for statistic gathering
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
128
diff
changeset
|
947 |
var gameCnt = 0; |
e0958e521716
Break limit on script execution time for statistic gathering
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
128
diff
changeset
|
948 |
var tsFrom = new Date().getTime(), tsFrame = tsFrom; |
e0958e521716
Break limit on script execution time for statistic gathering
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
128
diff
changeset
|
949 |
function batch() { |
e0958e521716
Break limit on script execution time for statistic gathering
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
128
diff
changeset
|
950 |
/* console.profile(); */ |
130
28694f058ea4
Make a way to stop statistic gathering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
129
diff
changeset
|
951 |
while (gameCnt++ < gameCntLimit && ui.report.executed) { |
129
e0958e521716
Break limit on script execution time for statistic gathering
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
128
diff
changeset
|
952 |
play(); |
e0958e521716
Break limit on script execution time for statistic gathering
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
128
diff
changeset
|
953 |
var tsTo = new Date().getTime(); |
e0958e521716
Break limit on script execution time for statistic gathering
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
128
diff
changeset
|
954 |
if (tsTo - tsFrame > 7000) { |
e0958e521716
Break limit on script execution time for statistic gathering
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
128
diff
changeset
|
955 |
tsFrame = tsTo; |
e0958e521716
Break limit on script execution time for statistic gathering
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
128
diff
changeset
|
956 |
break; |
e0958e521716
Break limit on script execution time for statistic gathering
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
128
diff
changeset
|
957 |
} |
e0958e521716
Break limit on script execution time for statistic gathering
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
128
diff
changeset
|
958 |
if (tsTo - tsFrom >= tsLimit) |
e0958e521716
Break limit on script execution time for statistic gathering
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
128
diff
changeset
|
959 |
break; |
e0958e521716
Break limit on script execution time for statistic gathering
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
128
diff
changeset
|
960 |
} |
e0958e521716
Break limit on script execution time for statistic gathering
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
128
diff
changeset
|
961 |
/* console.profileEnd(); */ |
130
28694f058ea4
Make a way to stop statistic gathering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
129
diff
changeset
|
962 |
if (tsTo - tsFrom >= tsLimit || gameCnt >= gameCntLimit || ! ui.report.executed) { |
129
e0958e521716
Break limit on script execution time for statistic gathering
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
128
diff
changeset
|
963 |
ui.report.fix(histo); |
e0958e521716
Break limit on script execution time for statistic gathering
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
128
diff
changeset
|
964 |
ui.report.show(histo, gameCnt); |
e0958e521716
Break limit on script execution time for statistic gathering
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
128
diff
changeset
|
965 |
} else { |
e0958e521716
Break limit on script execution time for statistic gathering
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
128
diff
changeset
|
966 |
setTimeout(batch, 10); |
e0958e521716
Break limit on script execution time for statistic gathering
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
128
diff
changeset
|
967 |
} |
e0958e521716
Break limit on script execution time for statistic gathering
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
128
diff
changeset
|
968 |
} |
e0958e521716
Break limit on script execution time for statistic gathering
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
128
diff
changeset
|
969 |
batch(); |
62 | 970 |
} |
129
e0958e521716
Break limit on script execution time for statistic gathering
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
128
diff
changeset
|
971 |
var statisticStartBtn = document.getElementById("statistic-start"); |
e0958e521716
Break limit on script execution time for statistic gathering
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
128
diff
changeset
|
972 |
statisticStartBtn.addEventListener("click", ui.report.start, false); |
62 | 973 |
|
130
28694f058ea4
Make a way to stop statistic gathering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
129
diff
changeset
|
974 |
ui.report.stop = function() { |
28694f058ea4
Make a way to stop statistic gathering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
129
diff
changeset
|
975 |
ui.report.executed = false; |
28694f058ea4
Make a way to stop statistic gathering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
129
diff
changeset
|
976 |
} |
28694f058ea4
Make a way to stop statistic gathering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
129
diff
changeset
|
977 |
var statisticStopBtn = document.getElementById("statistic-stop"); |
28694f058ea4
Make a way to stop statistic gathering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
129
diff
changeset
|
978 |
statisticStopBtn.addEventListener("click", ui.report.stop, false); |
28694f058ea4
Make a way to stop statistic gathering.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
129
diff
changeset
|
979 |
|
129
e0958e521716
Break limit on script execution time for statistic gathering
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
128
diff
changeset
|
980 |
ui.report.clean = function() { |
98
eb4f89e2a001
Clean statistics button.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
97
diff
changeset
|
981 |
while (reportsDom.hasChildNodes()) { |
eb4f89e2a001
Clean statistics button.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
97
diff
changeset
|
982 |
reportsDom.removeChild(reportsDom.lastChild); |
eb4f89e2a001
Clean statistics button.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
97
diff
changeset
|
983 |
} |
eb4f89e2a001
Clean statistics button.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
97
diff
changeset
|
984 |
} |
eb4f89e2a001
Clean statistics button.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
97
diff
changeset
|
985 |
var statisticCleanBtn = document.getElementById('statistic-clean'); |
129
e0958e521716
Break limit on script execution time for statistic gathering
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
128
diff
changeset
|
986 |
statisticCleanBtn.addEventListener("click", ui.report.clean, false); |
62 | 987 |
|
988 |
//////////////////////////////////////////////////////////////// |
|
989 |
// Initialise game. |
|
990 |
||
113
fc058d27e829
Make board engine selectable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
112
diff
changeset
|
991 |
if (localStorage.brdEngine) { |
fc058d27e829
Make board engine selectable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
112
diff
changeset
|
992 |
boardEngineDom.value = localStorage.brdEngine; |
fc058d27e829
Make board engine selectable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
112
diff
changeset
|
993 |
ui.brdEngine = window[localStorage.brdEngine]; |
fc058d27e829
Make board engine selectable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
112
diff
changeset
|
994 |
} else { |
fc058d27e829
Make board engine selectable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
112
diff
changeset
|
995 |
ui.brdEngine = BoardArr2d; |
fc058d27e829
Make board engine selectable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
112
diff
changeset
|
996 |
} |
0 | 997 |
|
95
804e751a3b7f
Save and restore continuation limits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
94
diff
changeset
|
998 |
if (localStorage.untilScore) { |
804e751a3b7f
Save and restore continuation limits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
94
diff
changeset
|
999 |
var scoreLimit = parseInt(localStorage.untilScore); |
804e751a3b7f
Save and restore continuation limits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
94
diff
changeset
|
1000 |
if (isFinite(scoreLimit) && scoreLimit > 0) |
804e751a3b7f
Save and restore continuation limits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
94
diff
changeset
|
1001 |
document.getElementById("until-score").value = scoreLimit; |
804e751a3b7f
Save and restore continuation limits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
94
diff
changeset
|
1002 |
} |
804e751a3b7f
Save and restore continuation limits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
94
diff
changeset
|
1003 |
if (localStorage.untilMaxVal) { |
804e751a3b7f
Save and restore continuation limits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
94
diff
changeset
|
1004 |
var maxValLimit = parseInt(localStorage.untilMaxVal); |
804e751a3b7f
Save and restore continuation limits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
94
diff
changeset
|
1005 |
if (isFinite(maxValLimit) && maxValLimit > 0 && maxValLimit <= 13) |
804e751a3b7f
Save and restore continuation limits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
94
diff
changeset
|
1006 |
document.getElementById("until-max-value").value = maxValLimit; |
804e751a3b7f
Save and restore continuation limits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
94
diff
changeset
|
1007 |
} |
804e751a3b7f
Save and restore continuation limits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
94
diff
changeset
|
1008 |
|
43
8b1577211149
Save val2048 preference.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
42
diff
changeset
|
1009 |
if (localStorage.val2048) { |
8b1577211149
Save val2048 preference.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
42
diff
changeset
|
1010 |
try { |
8b1577211149
Save val2048 preference.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
42
diff
changeset
|
1011 |
ui.board.val2048Dom.checked = JSON.parse(localStorage.val2048); |
8b1577211149
Save val2048 preference.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
42
diff
changeset
|
1012 |
} catch (ex) { } |
8b1577211149
Save val2048 preference.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
42
diff
changeset
|
1013 |
} |
41
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
1014 |
if (localStorage.savedBoard) { |
42
716508d5494c
Save board between browser sessions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
41
diff
changeset
|
1015 |
try { |
45 | 1016 |
ui.board.position = JSON.parse(localStorage.savedBoard); |
46
4dadaff6eba4
Update/store/restore game turn. Show max value according to value settings.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
45
diff
changeset
|
1017 |
if (localStorage.savedTurn) |
4dadaff6eba4
Update/store/restore game turn. Show max value according to value settings.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
45
diff
changeset
|
1018 |
ui.board.turn = JSON.parse(localStorage.savedTurn); |
4dadaff6eba4
Update/store/restore game turn. Show max value according to value settings.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
45
diff
changeset
|
1019 |
else |
4dadaff6eba4
Update/store/restore game turn. Show max value according to value settings.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
45
diff
changeset
|
1020 |
ui.board.turn = 0; |
45 | 1021 |
ui.board.update(ui.board.position); |
46
4dadaff6eba4
Update/store/restore game turn. Show max value according to value settings.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
45
diff
changeset
|
1022 |
ui.score.update(ui.board.position, ui.board.turn); |
42
716508d5494c
Save board between browser sessions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
41
diff
changeset
|
1023 |
} catch (ex) { } |
41
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
1024 |
} else { |
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
1025 |
ui.action.start(); |
359719178176
Reorganise code. Warn about uninitialised AI.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
40
diff
changeset
|
1026 |
} |
32
f48151863cdf
Start game after page load.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
31
diff
changeset
|
1027 |
|
0 | 1028 |
</script> |
1029 |
||
1030 |
</body> |
|
1031 |
</html> |