-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
181 lines (175 loc) · 5.44 KB
/
index.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
<!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>Knaves and Knights</title>
</head>
<style>
ul {
padding-left: 40px;
list-style-type: none;
}
li {
padding-bottom: 10px;
}
table, tr {
padding: 4px;
text-align: center;
border: 1px solid black;
border-collapse: collapse;
margin: auto;
}
th, td {
padding: 4px;
}
.buttonDiv {
display: inline-block;
padding: 2px;
border: 2px;
}
.centered {
text-align: center;
}
</style>
<script src="js/knaves.js"></script>
<script>
var pg; // a puzzle generator
var puzzleType = "easy";
var disabled = false;
$(document).ready(function() {
reset();
$("#solve").on("click", function(event){
if (disabled) return;
var solutionDisplay = document.getElementById("solutionDisplay");
solutionDisplay.innerHTML = pg.solutionSummary(knavesList, knightsList);
disabled = true;
controllers.disabled = true;
$("#reset").addClass("btn-success");
});
$("#reset").on("click", function(event){
reset();
});
$("#reasoning").on("click", function(event){
disabled = true;
controllers.disabled = true;
var reasoningDisplay = document.getElementById("reasoningDisplay");
reasoningDisplay.innerHTML = pg.showReasoning();
$("#reset").addClass("btn-success");
});
});
function reset() {
console.log("========= new puzzle ============");
pg = new PuzzleGenerator();
switch(puzzleType) {
case "easy":
pg.easy();
break;
case "tricky":
pg.medium();
break;
case "trickier":
pg.hard();
break;
}
var controller = pg.controller();
var islandersDisplay = document.getElementById("islandersDisplay");
islandersDisplay.innerHTML = controller.islandersDisplay();
var accusationDisplay = document.getElementById("accusationDisplay");
accusationDisplay.innerHTML = controller.accusationDisplay();
var solutionDisplay = document.getElementById("solutionDisplay");
solutionDisplay.innerHTML = "";
var reasoningDisplay = document.getElementById("reasoningDisplay");
reasoningDisplay.innerHTML = "";
knavesList = [];
knightsList = [];
disabled = false;
$("#reset").removeClass("btn-success");
};
function setButtons() {
$(".btn-primary").addClass("btn-secondary");
$(".btn-primary").removeClass("btn-primary");
$("#" + puzzleType).addClass("btn-primary");
$("#" + puzzleType).removeClass("btn-secondary");
$("#btnCurrentPage").addClass("btn-primary");
};
$(document).ready(function(){
$('.puzzleTypeBtn').on("click", function(event){
puzzleType = event.currentTarget.id;
setButtons();
reset();
});
});
</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>
<div class="container-fluid">
<div class='row'>
<div class='col-sm-1'></div>
<div class='col-sm-10'>
<div class="page-header">
<h1>The Island of Knights and Knaves
</h1>
</div>
<p>
On the island of Knights and Knaves, everyone is either a Knave or a Knight. Knights always tell the truth and Knaves always lie. You have encountered a group of islanders, and want to know who is a knave and who is a knight. The islanders have made some statments about each other - each statement should be taken independently: each is either a true statement or a false statement.
</p>
<p>
Categorize each islander as either a knight or a knave. When you think you are done, click the 'solve' button to see if you have solved the puzzle. In this puzzle, you should be able to decide whether each islander is a knave or a knight.
</p>
<hr>
<div class="centered">
<div class="btn-group btn-group-md " role="group">
<button type="button" id="easy" class="puzzleTypeBtn btn btn-primary">easy</button>
<button type="button" id="tricky" class="puzzleTypeBtn btn btn-secondary">tricky</button>
<button type="button" id="trickier" class="puzzleTypeBtn btn btn-secondary">trickier</button>
</div>
</div>
<hr>
<p> Here is your puzzle: </p>
<div id="accusationDisplay"></div>
<hr>
<div id="islandersDisplay" class="centered" style="text-align=center"></div>
<br>
<div id="soveButton">
<button type="button" id="solve" class="btn btn-secondary typeButton">Solve</span></button>
</div>
<div id="solutionDisplay"></div>
<hr>
<div id="reasoningButton">
<button type="button" id="reasoning" class="btn btn-secondary typeButton">Show Reasoning</span></button>
</div>
<div id="reasoningDisplay"></div>
<hr>
<div id="resetButton">
<button type="button" id="reset" class="btn btn-secondary typeButton">New Puzzle</span></button>
</div>
<br>
<br>
<div class='centered'>
<img src="imgs/knight_squire.png" style="max-width:100%;max-height:100%" >
<br>
<p> <em>Illustration by <a href='https://en.wikipedia.org/wiki/Howard_Pyle'>Howard Pyle</a><br> from "The Story of King Arthur and His Knights" (1924).</em></p>
<br>
</div>
<br>
</div>
<div class='col-sm-1'></div>
</div>
</div>
</body>
</html>