-
Notifications
You must be signed in to change notification settings - Fork 1
/
tourist.html
241 lines (202 loc) · 6.55 KB
/
tourist.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<title>KnightTourist</title>
</head>
<style>
table, th, td {
padding: 4px;
text-align: center;
border: 1px solid black;
border-collapse: collapse;
}
svg {
display: block;
margin: auto ;
border: 1px solid black;
}
td {
width: 35px;
}
.backtrackDisplay {
display: block;
text-align: center;
}
.centered {
text-align: center;
}
</style>
<script src="js/evnts.js"></script> <!-- required for callback registration-->
<script src="js/bldrs.js"></script> <!-- required for html/svg building -->
<script src="js/chess_base.js"></script>
<script src="js/ktour.js"></script>
<script>
let showHint = false;
let showCounts = true;
function loadBoard() {
game= new Tourist(8);
game.init();
game.hints = showHint;
game.labels = showCounts;
return htmlForBoard(game.getBoard());
};
function setButtons() {
$(".pieceType").addClass("btn-secondary");
$(".pieceType").removeClass("btn-primary");
$("#" + CellType).removeClass("btn-secondary");
$("#" + CellType).addClass("btn-primary");
$("#boardDisplay").html(loadBoard());
};
$(document).ready(function(){
CellType = "knight";
$("#refresh").on("click", function(event){
console.log("refresh button clicked");
$("#boardDisplay").html(loadBoard());
game.startGame();
});
$("#backtrack").on("click", function(event){
console.log("backtrack button clicked");
//$("#boardDisplay").html(loadBoard());
game.backtrack();
});
$(".typeButton").on("click", function(event){
CellType = event.currentTarget.id;
setButtons();
game.startGame();
});
$(".checkbox").on('click',function(e){
showCounts = ($('#counts:checked').val()=='yes');
showHint = ($('#hint:checked').val()=='yes');
game.hints = showHint;
game.labels = showCounts;
game.updateColours();
});
});
/*
* The page registers callbacks to have its elements
* refreshed when things change. These pull what they
* require from the gameDisplay object.
*/
$(document).ready(function(){
evnts.addCallback("refreshMap", function() {
$("#mapDisplay").html(gameDisplay.map);
});
evnts.addCallback("refreshStatus", function() {
$("#finish").html(gameDisplay.statusMessage);
});
evnts.addCallback("refreshSteps", function() {
$("#missteps").html(gameDisplay.backtracks);
});
//after callbacks are registered, we start the game
$("#boardDisplay").html(loadBoard());
game.startGame();
});
</script>
<body>
<nav class="navbar navbar-default" style="margin-bottom:0px">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="..">
<img src="imgs/github_badge1.png" style="max-width:100%;max-height:100%" >
</a>
<p class="navbar-text navbar-right">
<a href=".." class="navbar-link">dmackinnon1.github.io</a>
</p>
</div>
</div>
</nav>
<br>
<div class="centered">
<div class="btn-group btn-group-md " role="group">
<a class="btn btn-default" href=".">Kixote</a>
<a class="btn btn-default" href="./hidato.html">Hidato</a>
<a class="btn btn-default" href="./numbrix.html">Numbrix</a>
<a class="btn btn-primary" href="./tourist.html">Tourist</a>
</div>
</div>
<div class="container-fluid">
<div class='row'>
<div class='col-sm-1'>
</div>
<div class='col-sm-10'>
<div class="page-header">
<h1>Tourist</h1>
</div>
<button type='button' class='btn btn-info' data-toggle='collapse' data-target='#full'>
About </button>
<div id='full' class='collapse '>
<br><hr>
<div class="media">
<a class="media-left media-middle" href="#">
<img class="media-object" src="imgs/picasso_don_quixote.jpg" alt="Knight Moves" width="150" height="150">
</a>
<div class="media-body">
<h4 class="media-heading">Chess Tourist</h4>
<p>
When a chess piece has traveled around a chessboard touching every square exactly once, it has complted a "tour" of the board.
Your task is to complete a tour on the board below using the selected chess piece.
</p>
<p>
Your tour has been started on a randomly
selected square.
</p>
<p>
<ul>
<li>The light green squares indicate a legal move. This is based on the type of chess piece you have selected.</li>
<li>If <strong> show counts</strong> is checked, the numbers on each
square tell you how many open moves are available from that square.</li>
<li> If <strong> show hints</strong> is checked, the legal moves with the
lowest number of move options are highlighted in dark green.
</ul>
<p> The recommended strategy for building knight tours is to follow the
The <em>Warnsdorff heuristic</em> which states that you should
always move to a square with the lowest number of available moves from it (the ones in dark green when
hints are turned on).
</p>
</div>
</div>
<br>
<hr><br>
</div>
<br>
<div class="centered">
<div class="btn-group btn-group-lg " role="group">
<button type="button" id="king" class="btn btn-secondary typeButton pieceType"><span class='glyphicon glyphicon-king'></span></button>
<button type="button" id="knight" class="btn btn-primary typeButton pieceType"><span class='glyphicon glyphicon-knight'></span></button>
<button type="button" id="rook" class="btn btn-secondary typeButton pieceType"><span class='glyphicon glyphicon-tower'></span></button>
<button type="button" id="queen" class="btn btn-secondary typeButton pieceType"><span class='glyphicon glyphicon-queen'></span></button>
</div>
</div>
<div id="finish" style="text-align=center"></div>
<hr>
<h3><div id="boardDisplay" style="text-align=center">
</div>
</h3>
<hr>
<form>
<div class="checkbox centered">
<label><input id="counts" type="checkbox" checked=true value="yes" >show counts</label>
<!-- add checked attribte to check by default -->
</div>
<div class="checkbox centered">
<label><input id="hint" type="checkbox" value="yes" >show hints</label>
<!-- add checked attribte to check by default -->
</div>
</form>
<div class="backtrackDisplay">
<button id="backtrack" style="text-align=center" class="btn btn-default">Backtrack</button>
<div id="missteps" style="text-align=center"></div>
</div>
<hr>
<div id="mapDisplay" style="text-align=center"></div>
<hr>
</div>
<div class='col-sm-1'>
</div>
</body>
</html>