-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
110 lines (100 loc) · 2.61 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
<!DOCTYPE html>
<html>
<head>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=DM+Mono:wght@300&display=swap" rel="stylesheet">
<style>
html {
font-family: 'DM Mono', monospace;
font-size: 25px}
#output1 {margin-left: 20%; margin-right: 20%;}
</style>
</head>
<body>
Both players have the same set of pieces. Third version: 2 rows of heavy pieces and row of pawns. Fourth: 4 rows of heavy pieces.<br>
<button onclick="FillBoard(1)">Heavy chess 3</button>
<button onclick="FillBoard(2)">Heavy chess 4</button>
<div id='output1'></div>
<br>
<div> To see this exact position in Lichess editor click the <a id='link1' href=''>link</a> </div>
</body>
<script>
var table = [];
var rows = [];
function p(x,y){document.getElementById(y).innerHTML += x;};
function getRandomInt(max) { return Math.floor(Math.random() * max); }
function shuffle(array) {
var array2 = array;
array2.sort(() => Math.random() - 0.5);
return array2;
}
function shuf(orig){ return shuffle(orig.split('')).join(''); };
function createTable() {
for (let i=0; i<8; i++){
table[i]=[];
}
for (let i=0; i<8; i++){
for (let j=0; j<8; j++){
table[i][j]='_';
}
}
}
function createRows(){
rows[0] = shuf('NNBBRRQK');
rows[1] = shuf('NNBBRRQQ');
rows[6] = shuf('nnbbrrqq');
rows[7] = shuf('nnbbrrqk');
for(let i=2; i<4; i++){ rows[i]=shuf(rows[i-1]);}
for(let i=5; i>3; i--){ rows[i]=shuf(rows[i+1]);}
}
function FillBoard(type){
createTable();
createRows();
document.getElementById('output1').innerHTML = '';
if(type == 1){
for (let i=0; i<8; i++){ //i itertes horisontally
table[0][i] = rows[7][i];
table[1][i] = rows[6][i];
table[2][i] = 'p';
table[5][i] = 'P';
table[6][i] = rows[1][i];
table[7][i] = rows[0][i];
}
}else if(type == 2){
for (let i=0; i<8; i++){
for (let j=0; j<8; j++){
table[7-i][j] = rows[i].split('')[j];
}
}
}
for (const row of table){
p(row+'<br>','output1')
}
createFEN();
}
// creating FEN for URL
function createFEN(){
z = '%2f'
fen = ''
num = 0
for (const row of table){
//add fen of row from notebook
for (var i=0; i<8;i++){
if (row[i] != '_'){
fen+=row[i]
} else {
if (i==0 || row[i-1]!='_') {var acc = 1}
while(row[i+1]=='_'){
acc++;
i++
}
fen +=acc
}
} fen+=z;
}
url = 'https://lichess.org/editor?fen=' + fen + '+w+-+-+0+1';
document.getElementById('link1').href = url;
}
</script>
</html>