-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
161 lines (143 loc) · 6.78 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
<!doctype html>
<html lang="en">
<head>
<title>Perturb-o-tron</title>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="description" content="analysis stockfish">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<link rel="stylesheet" href="assets/chessground.css" async>
<link rel="stylesheet" href="assets/theme.css" async>
<link rel="stylesheet" href="assets/examples.css">
<script src="dist/main.js"></script>
</head>
<body>
<h4>Perturb-<a href="https://github.com/tailuge">o-tron</a></h4>
<div class="all">
<div class="cellleft">
<section class="blue merida">
<div id="chessground-examples"></div>
</section>
<br/>
<div class="editButtons">
<input type="text" class="fen" id="fen" name="fen" value="8/8/4k3/8/8/8/4PK2/8 w - - 0 2" onkeydown="onPressEnter(event,fenInputToBoard)" />
<button type="button" class="addWhite" onClick="analysisBoard.placePieceMode('p','w')">+♟</button>
<button type="button" class="addWhite" onClick="analysisBoard.placePieceMode('n','w')">+♞</button>
<button type="button" class="addWhite" onClick="analysisBoard.placePieceMode('b','w')">+♝</button>
<button type="button" class="addWhite" onClick="analysisBoard.placePieceMode('r','w')">+♜</button>
<button type="button" class="addWhite" onClick="analysisBoard.placePieceMode('q','w')">+♛</button>
<button type="button" class="addBlack" onClick="analysisBoard.placePieceMode('p','b')">+♟</button>
<button type="button" class="addBlack" onClick="analysisBoard.placePieceMode('n','b')">+♞</button>
<button type="button" class="addBlack" onClick="analysisBoard.placePieceMode('b','b')">+♝</button>
<button type="button" class="addBlack" onClick="analysisBoard.placePieceMode('r','b')">+♜</button>
<button type="button" class="addBlack" onClick="analysisBoard.placePieceMode('q','b')">+♛</button>
</div>
</div>
<div class="cellright">
<div class="explorerContainer" id="explorer"> </div>
<!-- <button onclick="lichessEditor()">Explore on Lichess</button> -->
<br/> Stockfish search depth : <input type="text" name="depth" id="depth" value="17" style="width: 18px;" onkeydown="onPressEnter(event,perturb)"/>
<br/> Side to play : <input type="radio" name="colour" id="colour" value="white" checked onclick="switchColourToPlay();"> White <input type="radio" name="colour" id="colourOther" value="black" onclick="switchColourToPlay();"> Black
<br/> Perturb piece on : <input type="text" id="perturb" name="perturb" value="b8" style="width: 18px;" readonly/> <button onclick="analyse()">Select and Perturb</button>
<br/>
<br/>
<br/>
<br/>
<br/> examples:
<br/>
<br/>
<a href="./index.html?fen=8%2F5K2%2F8%2F8%2F4pk2%2F8%2F8%2FR7%20w%20-%20-%200%202&perturb=f7">JV-21</a>,
<a href="./index.html?fen=7K%2F6R1%2F1k6%2Fp7%2F8%2F8%2F8%2F8%20w%20-%20-%200%202&perturb=g7">JV-22</a>,
<a href="./index.html?fen=7R%2F8%2F2K5%2F8%2F1pk5%2F8%2F8%2F8%20w%20-%20-%200%202&perturb=c6">JV-23</a>,
<a href="./index.html?fen=8%2F8%2F4k3%2F8%2F8%2F8%2F4PK2%2F8%20w%20-%20-%200%202&perturb=e6">Opp-1</a>,
<a href="./index.html?fen=8%2F8%2F4k3%2F8%2F4K3%2F4P3%2F8%2F8%20w%20-%20-%200%202&perturb=e6">Opp-2</a>,
<a href="./index.html?fen=4k3%2F8%2F8%2F1p5p%2F1P5P%2F8%2F4K3%2F8%20w%20-%20-%200%202&perturb=e2">Opp-3</a>,
<a href="./index.html?fen=8%2F8%2F8%2F8%2F3k3P%2F8%2F8%2F2K5%20w%20-%20-%200%202&perturb=d4">RoSq-1</a>,
<a href="./index.html?fen=8%2F8%2F8%2F8%2FP3k3%2FK7%2F8%2F8%20w%20-%20-%200%202&perturb=e4">!RoSq-2</a>,
<a href="./index.html?fen=7K%2F8%2Fk1P5%2F7p%2F8%2F8%2F8%2F8%20w%20-%20-%200%202&perturb=h8">Reti</a>,
<a href="./index.html?fen=8%2F7K%2F5k2%2F7P%2F8%2F8%2F8%2F8%20w%20-%20-%200%202&perturb=f6">Shoulder</a>,
<a href="./index.html?fen=3k4%2F3P4%2F4K3%2F8%2F8%2F8%2F8%2F8%20w%20-%20-%200%202&perturb=e6">Zug</a>
</div>
<div class="status" id="status">Ready</div>
</div>
</body>
<script defer>
/* global bundle, WebAssembly, history */
var fen = elt('fen').value;
var chessground = bundle.Chessground(elt('chessground-examples'));
var analysisBoard = new bundle.AnalysisBoard(loadStockfish(), chessground);
chessground.set(analysisBoard.config(fen))
var params = bundle.parse(window.location.href);
if (params.fen) {
elt('perturb').value = params.perturb;
showFen(params.fen);
onSelected(params.perturb);
}
function analyse() {
setStatus("Select piece to perturb");
analysisBoard.selectMode(onSelected);
}
function perturb() {
onSelected(elt('perturb').value);
}
function onSelected(square) {
setStatus("Perturbing " + square);
var fen = chessground.getFen() + elt('fen').value.replace(/[^ ]*/, '');
elt('fen').value = fen;
elt('perturb').value = square;
analysisBoard.depth(elt('depth').value);
analysisBoard.perturb(fen, square);
analysisBoard.updateExplorerView();
updateUrlWithState();
}
function lichessEditor() {
window.open("https://lichess.org/editor/" + chessground.getFen(), '_blank');
}
function onPressEnter(event, action) {
(event.keyCode == 13) && action();
}
function fenInputToBoard() {
elt('explorer').innerHTML = ' ';
showFen(bundle.Util.fullFen(elt('fen').value));
}
function showFen(fen) {
elt('fen').value = fen;
elt('colour').checked = fen.includes('w');
elt('colourOther').checked = !fen.includes('w');
analysisBoard.showFen(fen);
}
function showFenAndPv(square) {
if (square !== "") {
analysisBoard.showFenAndPv(square);
elt('perturb').value = square;
elt('fen').value = bundle.Util.fullFen(analysisBoard.fenForTarget(square));
updateUrlWithState();
}
}
function switchColourToPlay() {
var colour = elt('colour').checked ? 'w' : 'b';
elt('fen').value = elt('fen').value.replace(/[wb]/, colour);
fenInputToBoard();
}
function setStatus(text) {
elt('status').innerHTML = text;
}
function elt(e) {
return document.getElementById(e);
}
function loadStockfish() {
var wasmSupported = typeof WebAssembly === 'object' && WebAssembly.validate(Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00));
setStatus("wasmSupported:" + wasmSupported);
return new Worker(wasmSupported ? 'vendor/stockfish.wasm.js' : 'vendor/stockfish.js');
}
function updateUrlWithState() {
if (history.pushState) {
var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + "?" +
bundle.build({ fen: elt('fen').value, perturb: elt('perturb').value });
window.history.pushState({
path: newurl
}, '', newurl);
}
}
</script>
</html>