Skip to content

Commit 453c298

Browse files
author
Jerome Simeon
committed
Just uses a single position field in the form ; add initial and empty position buttons
1 parent fba1129 commit 453c298

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

index.html

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,16 @@
2525
cols = "80" /></textarea><br/>
2626
</fieldset>
2727
<fieldset>
28-
<legend>current fen:</legend>
29-
<textarea id = "current"
30-
rows = "1"
31-
cols = "80" /></textarea><br/>
32-
</fieldset>
33-
</fieldset>
34-
<fieldset>
35-
<legend>new fen:</legend>
28+
<legend>position</legend>
3629
<textarea id = "fen"
3730
rows = "1"
3831
cols = "80" /></textarea>
3932
<button type="button"
40-
onclick="setNewFen()"><b>set</b></button>
33+
onclick="setNewFen()"><b>set</b></button><br/>
34+
<button type="button"
35+
onclick="initialBoard()"><b>initial</b></button>
36+
<button type="button"
37+
onclick="emptyBoard()"><b>empty</b></button>
4138
</fieldset>
4239
</div>
4340

@@ -59,6 +56,7 @@
5956
}
6057
})
6158
// Initialize FEN display
59+
let previousfen = ground.getFen()
6260
updateFen();
6361
// Get a pointer to the "real" console.
6462
let nodeConsole = require('console');
@@ -84,7 +82,7 @@
8482

8583
setInterval(() => {
8684
// refresh fen
87-
updateFen();
85+
refreshFen();
8886
konsole.log(getMask())
8987
}, 250)
9088

@@ -104,14 +102,31 @@
104102
document.getElementById("chessbot").addEventListener("keyup", function(e){
105103
if(e.keyCode == 13){sendBot(); clearBot();}
106104
});
105+
// Set up and maintain FEN position
107106
function setNewFen() {
108107
var newfen = document.getElementById("fen").value;
109108
ground.set({fen: newfen});
110109
updateFen();
111110
}
111+
function updateCurrentFen(fen) {
112+
previousfen = fen;
113+
}
112114
function updateFen() {
113-
var currentfen = ground.getFen();
114-
document.getElementById("current").value = currentfen;
115+
var newfen = ground.getFen();
116+
updateCurrentFen(newfen);
117+
document.getElementById("fen").value = newfen;
118+
}
119+
function refreshFen() {
120+
var currentfen = ground.getFen();
121+
if (!(currentfen == previousfen)) {
122+
updateFen();
123+
}
124+
}
125+
function initialBoard() {
126+
ground.set({fen: 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR'});
127+
}
128+
function emptyBoard() {
129+
ground.set({fen: '8/8/8/8/8/8/8/8/8'});
115130
}
116131
</script>
117132
</body>

0 commit comments

Comments
 (0)