-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
167 lines (158 loc) · 6.02 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
<!DOCTYPE html>
<html lang="">
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"
/>
<title>Coding challenge - Chess</title>
<style>
body {
padding: 0;
margin: 0;
background-color: #1b1b1b;
}
button {
-webkit-tap-highlight-color: transparent; /* Prevent tap highlight color */
font-size: 16px; /* Use at least 16px to prevent zooming on focus */
padding: 10px;
}
canvas {
display: block;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
outline: none;
-webkit-tap-highlight-color: rgba(255, 255, 255, 0);
/* mobile webkit */
}
.full-width-input {
width: 100%; /* Makes the input take up 100% of its parent's width */
box-sizing: border-box; /* Includes padding and border in the element's width */
font-size: large;
font-family: 'Arial', sans-serif;
margin-bottom: 10px;
}
.body {
color: white
}
.computer-switcher {
width: 50%;
}
</style>
</style>
<script src="p5.min.js"></script>
<script src="chess.js"></script>
<script src="game.js"></script>
<script src="board-pieces.js"></script>
<script src="zobrist.js"></script>
<script src="bit-board.js"></script>
<script src="transposition-table.js"></script>
<script src="alpha-beta.js"></script>
<script src="board-data.js"></script>
<script src="board-moves.js"></script>
<script src="history.js"></script>
<script src="board.js"></script>
<script src="computerplayers.js"></script>
<script>
function handleSubmit(event) {
event.preventDefault();
const fenValue = document.getElementById('fen').value;
if (fenValue) {
window.location.hash = fenValue
window.location.reload();
}
}
function updateStatus(computer, status) {
const resultElement = document.getElementById('result');
if (computer === 'white') {
status === "ON" ? game.computerWhite.on().checkForAutoTurn() : game.computerWhite.off()
} else if (computer === 'black') {
status === "ON" ? game.computerBlack.on().checkForAutoTurn() : game.computerBlack.off()
}
}
document.addEventListener('DOMContentLoaded', function() {
setupFen();
});
function stats(depth, stat) {
setTimeout(function stats2() {
const testMovesResults = document.getElementById('testMovesResults');
testMovesResults.innerHTML = testMovesResults.innerHTML + "<br>"+depth+": "+stat
}, 100);
}
function testMovesStart() {
if (window.location.hostname !== "localhost1") {
const testMovesElement = document.getElementById('testMovesElem');
const testMovesResults = document.getElementById('testMovesResults');
testMovesResults.innerHTML = ""
testMovesElement.setAttribute("style", "display:none");
setTimeout(function test() {
testMoves(stats)
testMovesElement.setAttribute("style", "display:")
}, 100);
}
}
function setupFen() {
if (window.location.hostname !== "localhost1") {
const testMovesElement = document.getElementById('testMovesElem');
testMovesElement.setAttribute("style", "display:")
const fenLibraryElement = document.getElementById('fenLibrary');
fenLibraryElement.setAttribute("style", "display:")
}
fen = window.location.hash
if (!fen) {
fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
} else {
fen = fen.replace(/%20/g, ' ').substring(1)
}
fenUI = window.document.getElementById("fen")
if (fenUI) {
fenUI.value = fen
}
}
</script>
</head>
<body class="body">
<main></main>
<div>
<form onsubmit="handleSubmit(event)">
<input id="fen" class="full-width-input" value="" id="fen" />
<button onclick="window.location.href='/'; return false" type="button">New</button>
<button type="submit">FEN</button>
<button style="display:none" id="testMovesElem" onclick="testMovesStart(); return false" type="button">Test moves</button>
<a id="fenLibrary" style="display:none" href="https://www.chessprogramming.org/Perft_Results" target="_blank" class="body">FEN library</a>
Time: <span id="timeLastMove"></span>
<button onclick="undoLastMove(); return false" type="button">Undo</button>
</form>
<form id="computerForm" style="display: flex;padding:10px;">
<fieldset class="computer-switcher">
<legend>WHITE computer</legend>
<label>
<input type="radio" name="whitePower" value="ON" onchange="updateStatus('white', 'ON')">
ON
</label>
<label>
<input type="radio" name="whitePower" value="OFF" onchange="updateStatus('white', 'OFF')" checked>
OFF
</label>
</fieldset>
<fieldset class="computer-switcher">
<legend>BLACK computer</legend>
<label>
<input type="radio" name="blackPower" value="ON" onchange="updateStatus('black', 'ON')" checked>
ON
</label>
<label>
<input type="radio" name="blackPower" value="OFF" onchange="updateStatus('black', 'OFF')" >
OFF
</label>
</fieldset>
</form>
</div>
<div id="testMovesResults"></div>
</body>
</html>