-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
127 lines (126 loc) · 5.4 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
<!doctype html>
<html>
<head>
<title>Neural-Net-Chess</title>
<link rel="stylesheet" type="text/css" href="static/chessboard.min.css">
<script src="static/jquery.min.js"></script>
<script src="static/chessboard.min.js"></script>
<link rel="icon" type="image/png" href="/static/img/favicon/ai.png"/>
</head>
<body style="font-size: 18px;">
<button onclick="selfplay()">Neural Net vs. itself</button><br />
<button onclick="newGame()">New Game</button><br />
<div id="board" style="width: 400px"></div>
<p></p>
<script type="text/javascript">
var board = ChessBoard('board', {
position: 'start',
draggable: true,
onDrop: onDrop
});
var files = { "a": 0, "b": 1, "c": 2, "d": 3, "e": 4, "f": 5, "g": 6, "h": 7 };
function get_square(sq) {
return 8 * (parseInt(sq.charAt(1)) - 1) + files[sq.charAt(0)];
}
function post() {
var element = document.getElementById("id01");
element.innerHTML = "Posting Winner";
element.style = "color:green;"
$.get('/post', function (r) {
var element = document.getElementById("id03")
element.innerHTML = r
newGame()
selfplay()
});
}
function onDrop(source, target, piece) {
if (source == target) return
var element = document.getElementById("id01");
element.innerHTML = "A.I.: currently searching mind-state.";
element.style = "color:blue;"
element.style = "background-color:cyan;"
var promotion = piece.toLowerCase().charAt(1) == 'p' && parseInt(target.charAt(1)) == 8;
var element = document.getElementById("id02");
element.innerHTML = "You Moved : " + source + target;
$.get('/move_coordinates', { 'from': get_square(source), 'to': get_square(target), 'sauce': source, 'targe': target, 'promotion': promotion }, function (r) {
if (r.includes("Game Over")) {
document.querySelector('p').innerText = 'Game Over';
post();
} else {
if (r.includes(":")) {
var move = r.split(":")[0];
var r1 = r.split(":")[1];
document.querySelector('p').innerText = '';
board.position(r1);
var element = document.getElementById("id01");
element.innerHTML = "Human turn:";
element.style = "color:black;";
var element = document.getElementById("id02");
element.innerHTML = "Computer Moved : " + move;
} else {
var element = document.getElementById("id01");
element.innerHTML = "Restart required";
element.style = "color:red;";
post();
}
}
});
}
function newGame() {
var element = document.getElementById("id01");
element.innerHTML = "Your turn: ";
element.style = "color:black;"
$.get('/newgame', function (r) {
document.querySelector('p').innerText = '';
board.position(r);
});
}
function eo(num) { return num % 2; } {
}
var i = 0
function selfplay(m) {
i = 1 + i
if (m == null) var m = ''
var element = document.getElementById("id01");
if (eo(i)) {
element.innerHTML = "White is thinking";
element.style = "color:darkmagenta;"
} else {
element.innerHTML = "Black is thinking";
element.style = "color:black;"
}
$.get('/selfplay', { 'm': m }, function (r) {
if (r.includes("game over")) {
document.querySelector('p').innerText = 'game over';
post();
} else {
if (r.includes(":")) {
var move = r.split(":")[0];
var r1 = r.split(":")[1];
document.querySelector('p').innerText = '';
board.position(r1);
var element = document.getElementById("id02");
element.innerHTML = "Last Move: " + move;
selfplay(move);
} else {
var element = document.getElementById("id01");
element.innerHTML = "All kinds of messed up: restart needed";
element.style = "color:red;";
}
}
});
}
function undo() {
var element = document.getElementById("id01");
element.innerHTML = "Udid move";
element.style = "color:red;"
$.get('/undo', function (r) {
document.querySelector('p').innerText = '';
board.position(r);
});
}
</script>
<h3 id="id01" style="color:black">Your turn: </h3>
<h3 id="id02" style="color:red">Last move:</h3>
</body>
</html>