-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchessboard.html
202 lines (185 loc) · 19.1 KB
/
chessboard.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<html><head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Chessboard stolen code</title>
<link rel="stylesheet" type="text/css" href="chessboard.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js" crossorigin="anonymous"></script>
<script src="https://unpkg.com/@chrisoakman/chessboardjs@1.0.0/dist/chessboard-1.0.0.min.js" integrity="sha384-8Vi8VHwn3vjQ9eUHUxex3JSN/NFqUg3QbPyX8kWyb93+8AC/pPWTzj+nHtbC5bxD" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chess.js/0.10.2/chess.js" integrity="sha384-s3XgLpvmHyscVpijnseAmye819Ee3yaGa8NxstkJVyA6nuDFjt59u1QvuEl/mecz" crossorigin="anonymous"></script>
<script src="engine.js"></script>
</head>
<body>
<!--- Begin Example HTML ------------------------------------------------------>
<div id="myBoard" style="width: 400px">
<div class="chessboard-63f37">
<div class="board-b72b1" style="width: 392px;">
<div class="row-5277c">
<div class="square-55d63 white-1e1d7 square-a8" style="width:49px;height:49px;" id="a8-de8e-79eb-017e-5aa8-611b-0126-a307-32f0" data-square="a8">
<div class="notation-322f9 numeric-fc462">8</div><img src="img/chesspieces/wikipedia/bR.png" alt="" class="piece-417db" data-piece="bR" style="width:49px;height:49px;"></div>
<div class="square-55d63 black-3c85d square-b8" style="width:49px;height:49px;" id="b8-30d7-7ab3-f8b1-9aa3-3518-63cb-be18-5841" data-square="b8"><img src="img/chesspieces/wikipedia/bN.png" alt="" class="piece-417db" data-piece="bN" style="width:49px;height:49px;"></div>
<div class="square-55d63 white-1e1d7 square-c8" style="width:49px;height:49px;" id="c8-543f-dea4-5c98-9e44-f0eb-5c52-cff7-77f2" data-square="c8"><img src="img/chesspieces/wikipedia/bB.png" alt="" class="piece-417db" data-piece="bB" style="width:49px;height:49px;"></div>
<div class="square-55d63 black-3c85d square-d8" style="width:49px;height:49px;" id="d8-e0ae-c5bb-0067-b865-ea09-623a-bb46-1a0f" data-square="d8"><img src="img/chesspieces/wikipedia/bQ.png" alt="" class="piece-417db" data-piece="bQ" style="width:49px;height:49px;"></div>
<div class="square-55d63 white-1e1d7 square-e8" style="width:49px;height:49px;" id="e8-dc32-e76a-cfa0-90f1-35e9-bd30-4db5-5f97" data-square="e8"><img src="img/chesspieces/wikipedia/bK.png" alt="" class="piece-417db" data-piece="bK" style="width:49px;height:49px;"></div>
<div class="square-55d63 black-3c85d square-f8" style="width:49px;height:49px;" id="f8-39e6-a979-953e-1202-3cfc-2829-8d65-4a4c" data-square="f8"><img src="img/chesspieces/wikipedia/bB.png" alt="" class="piece-417db" data-piece="bB" style="width:49px;height:49px;"></div>
<div class="square-55d63 white-1e1d7 square-g8" style="width:49px;height:49px;" id="g8-e565-b505-a299-79b0-18e9-39ab-d7d5-ce7a" data-square="g8"><img src="img/chesspieces/wikipedia/bN.png" alt="" class="piece-417db" data-piece="bN" style="width:49px;height:49px;"></div>
<div class="square-55d63 black-3c85d square-h8" style="width:49px;height:49px;" id="h8-711e-ff66-d17f-634b-90d5-a7e6-100e-c73b" data-square="h8"><img src="img/chesspieces/wikipedia/bR.png" alt="" class="piece-417db" data-piece="bR" style="width:49px;height:49px;"></div>
<div class="clearfix-7da63"></div>
</div>
<div class="row-5277c">
<div class="square-55d63 black-3c85d square-a7" style="width:49px;height:49px;" id="a7-51c1-7ca7-3607-c8ec-2535-efc7-8a82-e635" data-square="a7">
<div class="notation-322f9 numeric-fc462">7</div><img src="img/chesspieces/wikipedia/bP.png" alt="" class="piece-417db" data-piece="bP" style="width:49px;height:49px;"></div>
<div class="square-55d63 white-1e1d7 square-b7" style="width:49px;height:49px;" id="b7-c087-af51-e7d1-0bf4-73cb-68c2-1c08-4013" data-square="b7"><img src="img/chesspieces/wikipedia/bP.png" alt="" class="piece-417db" data-piece="bP" style="width:49px;height:49px;"></div>
<div class="square-55d63 black-3c85d square-c7" style="width:49px;height:49px;" id="c7-d9f8-9574-b387-8e61-d9f1-c6c2-3aee-9353" data-square="c7"><img src="img/chesspieces/wikipedia/bP.png" alt="" class="piece-417db" data-piece="bP" style="width:49px;height:49px;"></div>
<div class="square-55d63 white-1e1d7 square-d7" style="width:49px;height:49px;" id="d7-80d7-f3e7-41f9-5e62-4993-6ca2-ca06-dfbb" data-square="d7"><img src="img/chesspieces/wikipedia/bP.png" alt="" class="piece-417db" data-piece="bP" style="width:49px;height:49px;"></div>
<div class="square-55d63 black-3c85d square-e7" style="width:49px;height:49px;" id="e7-f51e-bbfb-d326-1e89-ddb0-31ab-fa08-710a" data-square="e7"><img src="img/chesspieces/wikipedia/bP.png" alt="" class="piece-417db" data-piece="bP" style="width:49px;height:49px;"></div>
<div class="square-55d63 white-1e1d7 square-f7" style="width:49px;height:49px;" id="f7-276f-99cb-e211-210d-6530-9bdf-2beb-5d07" data-square="f7"><img src="img/chesspieces/wikipedia/bP.png" alt="" class="piece-417db" data-piece="bP" style="width:49px;height:49px;"></div>
<div class="square-55d63 black-3c85d square-g7" style="width:49px;height:49px;" id="g7-f9d5-0d8f-dba9-3bf3-44b6-fad8-2677-9b37" data-square="g7"><img src="img/chesspieces/wikipedia/bP.png" alt="" class="piece-417db" data-piece="bP" style="width:49px;height:49px;"></div>
<div class="square-55d63 white-1e1d7 square-h7" style="width:49px;height:49px;" id="h7-de78-7c8e-d183-502f-3966-8fbb-7431-1a9f" data-square="h7"><img src="img/chesspieces/wikipedia/bP.png" alt="" class="piece-417db" data-piece="bP" style="width:49px;height:49px;"></div>
<div class="clearfix-7da63"></div>
</div>
<div class="row-5277c">
<div class="square-55d63 white-1e1d7 square-a6" style="width:49px;height:49px;" id="a6-9230-5e9b-7e0c-5675-2313-4f74-6265-1732" data-square="a6">
<div class="notation-322f9 numeric-fc462">6</div>
</div>
<div class="square-55d63 black-3c85d square-b6" style="width:49px;height:49px;" id="b6-1241-1f93-df08-9592-59dd-709c-e389-1214" data-square="b6"></div>
<div class="square-55d63 white-1e1d7 square-c6" style="width:49px;height:49px;" id="c6-0d7c-5a97-aaee-3a7b-a762-f487-e95a-3ea5" data-square="c6"></div>
<div class="square-55d63 black-3c85d square-d6" style="width:49px;height:49px;" id="d6-cfbc-1d36-34ca-adec-2e08-58f5-b1b8-22bb" data-square="d6"></div>
<div class="square-55d63 white-1e1d7 square-e6" style="width:49px;height:49px;" id="e6-0111-507e-ff03-5190-c02e-c903-d92a-27c0" data-square="e6"></div>
<div class="square-55d63 black-3c85d square-f6" style="width:49px;height:49px;" id="f6-d9d8-7b81-fe23-72e1-384f-45ba-c9d5-7083" data-square="f6"></div>
<div class="square-55d63 white-1e1d7 square-g6" style="width:49px;height:49px;" id="g6-6289-ba6a-e4b8-2d13-958c-725a-563c-77d8" data-square="g6"></div>
<div class="square-55d63 black-3c85d square-h6" style="width:49px;height:49px;" id="h6-067e-8e02-0584-22a7-5407-1b14-94c4-152d" data-square="h6"></div>
<div class="clearfix-7da63"></div>
</div>
<div class="row-5277c">
<div class="square-55d63 black-3c85d square-a5" style="width:49px;height:49px;" id="a5-8f08-1d20-64d1-a4f1-3438-d756-6a7a-6b4c" data-square="a5">
<div class="notation-322f9 numeric-fc462">5</div>
</div>
<div class="square-55d63 white-1e1d7 square-b5" style="width:49px;height:49px;" id="b5-b1b9-5b9c-66dc-cde4-7c1b-4c54-3293-cd64" data-square="b5"></div>
<div class="square-55d63 black-3c85d square-c5" style="width:49px;height:49px;" id="c5-425a-bc00-1598-3059-1a79-29fe-dec9-b78f" data-square="c5"></div>
<div class="square-55d63 white-1e1d7 square-d5" style="width:49px;height:49px;" id="d5-a447-d452-9aa8-b253-3ca1-ca38-c9e7-f536" data-square="d5"></div>
<div class="square-55d63 black-3c85d square-e5" style="width:49px;height:49px;" id="e5-d656-f891-4628-6cd3-2e4e-c207-d899-75f0" data-square="e5"></div>
<div class="square-55d63 white-1e1d7 square-f5" style="width:49px;height:49px;" id="f5-d20d-dc23-1d6e-7e3a-7017-4f58-fd45-bea4" data-square="f5"></div>
<div class="square-55d63 black-3c85d square-g5" style="width:49px;height:49px;" id="g5-c5bc-ccaa-97f0-e0d1-a19e-3105-1d36-3b50" data-square="g5"></div>
<div class="square-55d63 white-1e1d7 square-h5" style="width:49px;height:49px;" id="h5-91a4-e644-4acc-23dc-0cc2-b1fe-8ea0-b90a" data-square="h5"></div>
<div class="clearfix-7da63"></div>
</div>
<div class="row-5277c">
<div class="square-55d63 white-1e1d7 square-a4" style="width:49px;height:49px;" id="a4-bbb3-e35f-e061-090b-6067-030e-0b03-7d39" data-square="a4">
<div class="notation-322f9 numeric-fc462">4</div>
</div>
<div class="square-55d63 black-3c85d square-b4" style="width:49px;height:49px;" id="b4-686a-578f-af8f-2ece-9ea3-9319-d617-389c" data-square="b4"></div>
<div class="square-55d63 white-1e1d7 square-c4" style="width:49px;height:49px;" id="c4-7ccb-a473-ab06-d3e4-29d0-73ce-c63f-834c" data-square="c4"></div>
<div class="square-55d63 black-3c85d square-d4" style="width:49px;height:49px;" id="d4-bdd0-2a1e-a897-c704-5cd5-c427-3b69-c95e" data-square="d4"></div>
<div class="square-55d63 white-1e1d7 square-e4" style="width:49px;height:49px;" id="e4-1839-d00c-0c04-07ac-7a8e-b090-92c2-411d" data-square="e4"></div>
<div class="square-55d63 black-3c85d square-f4" style="width:49px;height:49px;" id="f4-dbb7-513e-9e97-c60e-7204-29de-43ef-8b1a" data-square="f4"></div>
<div class="square-55d63 white-1e1d7 square-g4" style="width:49px;height:49px;" id="g4-6ca4-94f1-9643-de68-40c5-7a61-13d2-ccfb" data-square="g4"></div>
<div class="square-55d63 black-3c85d square-h4" style="width:49px;height:49px;" id="h4-d22c-322d-ce0d-ad1e-190c-245f-71b9-f3a5" data-square="h4"></div>
<div class="clearfix-7da63"></div>
</div>
<div class="row-5277c">
<div class="square-55d63 black-3c85d square-a3" style="width:49px;height:49px;" id="a3-f782-27b4-f302-7007-7fc4-d77c-38f0-6c6a" data-square="a3">
<div class="notation-322f9 numeric-fc462">3</div>
</div>
<div class="square-55d63 white-1e1d7 square-b3" style="width:49px;height:49px;" id="b3-aeb8-3867-51c5-00d1-e080-957d-b625-3669" data-square="b3"></div>
<div class="square-55d63 black-3c85d square-c3" style="width:49px;height:49px;" id="c3-5b3c-3b32-ac06-2889-0208-f73b-1768-b345" data-square="c3"></div>
<div class="square-55d63 white-1e1d7 square-d3" style="width:49px;height:49px;" id="d3-5230-5362-d54c-5c29-621a-c28a-2b32-ef91" data-square="d3"></div>
<div class="square-55d63 black-3c85d square-e3" style="width:49px;height:49px;" id="e3-4c87-760f-f8e1-188f-0439-79e0-25d4-4fd0" data-square="e3"></div>
<div class="square-55d63 white-1e1d7 square-f3" style="width:49px;height:49px;" id="f3-3cf3-7dc2-69dc-fef6-f2a5-bd8e-d578-1796" data-square="f3"></div>
<div class="square-55d63 black-3c85d square-g3" style="width:49px;height:49px;" id="g3-f9bc-f20f-2a7e-4cee-99e2-33a9-d6b0-6bd1" data-square="g3"></div>
<div class="square-55d63 white-1e1d7 square-h3" style="width:49px;height:49px;" id="h3-e96d-5937-5e26-3063-450c-7fd1-76f0-7043" data-square="h3"></div>
<div class="clearfix-7da63"></div>
</div>
<div class="row-5277c">
<div class="square-55d63 white-1e1d7 square-a2" style="width:49px;height:49px;" id="a2-6f34-1d3c-e696-efc5-ed8a-bebb-355a-6eda" data-square="a2">
<div class="notation-322f9 numeric-fc462">2</div><img src="img/chesspieces/wikipedia/wP.png" alt="" class="piece-417db" data-piece="wP" style="width:49px;height:49px;"></div>
<div class="square-55d63 black-3c85d square-b2" style="width:49px;height:49px;" id="b2-f0ba-2759-a04f-61ab-c64c-77bc-7f76-0fe6" data-square="b2"><img src="img/chesspieces/wikipedia/wP.png" alt="" class="piece-417db" data-piece="wP" style="width:49px;height:49px;"></div>
<div class="square-55d63 white-1e1d7 square-c2" style="width:49px;height:49px;" id="c2-50ee-4e58-a0a8-3aa3-e8aa-af89-334f-18cd" data-square="c2"><img src="img/chesspieces/wikipedia/wP.png" alt="" class="piece-417db" data-piece="wP" style="width:49px;height:49px;"></div>
<div class="square-55d63 black-3c85d square-d2" style="width:49px;height:49px;" id="d2-6cb0-1fdc-3b7a-37fc-6755-38df-cf3a-8bce" data-square="d2"><img src="img/chesspieces/wikipedia/wP.png" alt="" class="piece-417db" data-piece="wP" style="width:49px;height:49px;"></div>
<div class="square-55d63 white-1e1d7 square-e2" style="width:49px;height:49px;" id="e2-6aeb-1d6e-9381-d7a5-07b5-498f-2478-89bb" data-square="e2"><img src="img/chesspieces/wikipedia/wP.png" alt="" class="piece-417db" data-piece="wP" style="width:49px;height:49px;"></div>
<div class="square-55d63 black-3c85d square-f2" style="width:49px;height:49px;" id="f2-d8a7-78de-cfca-2fe0-8eae-2a58-75d9-a03b" data-square="f2"><img src="img/chesspieces/wikipedia/wP.png" alt="" class="piece-417db" data-piece="wP" style="width:49px;height:49px;"></div>
<div class="square-55d63 white-1e1d7 square-g2" style="width:49px;height:49px;" id="g2-69d1-d38b-8ef4-63d2-f4fc-34b5-72cf-9aad" data-square="g2"><img src="img/chesspieces/wikipedia/wP.png" alt="" class="piece-417db" data-piece="wP" style="width:49px;height:49px;"></div>
<div class="square-55d63 black-3c85d square-h2" style="width:49px;height:49px;" id="h2-0a56-1b4e-5503-1e50-1d7f-e9fa-bf72-deff" data-square="h2"><img src="img/chesspieces/wikipedia/wP.png" alt="" class="piece-417db" data-piece="wP" style="width:49px;height:49px;"></div>
<div class="clearfix-7da63"></div>
</div>
<div class="row-5277c">
<div class="square-55d63 black-3c85d square-a1" style="width:49px;height:49px;" id="a1-6d5b-a6aa-9556-de96-9512-ee03-bc72-a334" data-square="a1">
<div class="notation-322f9 alpha-d2270">a</div>
<div class="notation-322f9 numeric-fc462">1</div><img src="img/chesspieces/wikipedia/wR.png" alt="" class="piece-417db" data-piece="wR" style="width:49px;height:49px;"></div>
<div class="square-55d63 white-1e1d7 square-b1" style="width:49px;height:49px;" id="b1-c5a4-456b-a248-e650-4213-7a50-4245-3880" data-square="b1">
<div class="notation-322f9 alpha-d2270">b</div><img src="img/chesspieces/wikipedia/wN.png" alt="" class="piece-417db" data-piece="wN" style="width:49px;height:49px;"></div>
<div class="square-55d63 black-3c85d square-c1" style="width:49px;height:49px;" id="c1-4953-bb30-74f3-b90e-73f2-5067-c027-1978" data-square="c1">
<div class="notation-322f9 alpha-d2270">c</div><img src="img/chesspieces/wikipedia/wB.png" alt="" class="piece-417db" data-piece="wB" style="width:49px;height:49px;"></div>
<div class="square-55d63 white-1e1d7 square-d1" style="width:49px;height:49px;" id="d1-b310-5fb8-c459-8ac2-c10f-4fc2-46f4-1d7e" data-square="d1">
<div class="notation-322f9 alpha-d2270">d</div><img src="img/chesspieces/wikipedia/wQ.png" alt="" class="piece-417db" data-piece="wQ" style="width:49px;height:49px;"></div>
<div class="square-55d63 black-3c85d square-e1" style="width:49px;height:49px;" id="e1-bdef-11f4-1a86-4a2f-292a-3cd0-2b86-2260" data-square="e1">
<div class="notation-322f9 alpha-d2270">e</div><img src="img/chesspieces/wikipedia/wK.png" alt="" class="piece-417db" data-piece="wK" style="width:49px;height:49px;"></div>
<div class="square-55d63 white-1e1d7 square-f1" style="width:49px;height:49px;" id="f1-c6d6-eb7f-3002-10e9-c967-35d4-306a-8d31" data-square="f1">
<div class="notation-322f9 alpha-d2270">f</div><img src="img/chesspieces/wikipedia/wB.png" alt="" class="piece-417db" data-piece="wB" style="width:49px;height:49px;"></div>
<div class="square-55d63 black-3c85d square-g1" style="width:49px;height:49px;" id="g1-8e0d-9944-fe6c-c7cb-acc3-ffa6-f21f-0fdb" data-square="g1">
<div class="notation-322f9 alpha-d2270">g</div><img src="img/chesspieces/wikipedia/wN.png" alt="" class="piece-417db" data-piece="wN" style="width:49px;height:49px;"></div>
<div class="square-55d63 white-1e1d7 square-h1" style="width:49px;height:49px;" id="h1-23f4-987e-6ece-c951-ca55-4d76-5bdf-1bfd" data-square="h1">
<div class="notation-322f9 alpha-d2270">h</div><img src="img/chesspieces/wikipedia/wR.png" alt="" class="piece-417db" data-piece="wR" style="width:49px;height:49px;"></div>
<div class="clearfix-7da63"></div>
</div>
</div>
</div>
</div>
<!--- End Example HTML -------------------------------------------------------->
<script>
// --- Begin Example JS --------------------------------------------------------
// NOTE: this example uses the chess.js library:
// https://github.com/jhlywa/chess.js
var board = null
var game = new Chess()
function onDragStart (source, piece, position, orientation) {
// do not pick up pieces if the game is over
if (game.game_over()) return false
// only pick up pieces for White
if (piece.search(/^b/) !== -1) return false
}
function makeRandomMove () {
var possibleMoves = game.moves()
// for (var move of possibleMoves){
// console.log("Move: " + move)
// }
// game over
if (possibleMoves.length === 0) return
// Instead of a random one let's try our engine
// var randomIdx = Math.floor(Math.random() * possibleMoves.length)
// console.log("Move: " + possibleMoves[randomIdx])
// game.move(possibleMoves[randomIdx])
var bestMove = makeBestMove(game)
game.move(bestMove)
board.position(game.fen())
}
function onDrop (source, target) {
// see if the move is legal
var move = game.move({
from: source,
to: target,
promotion: 'q' // NOTE: always promote to a queen for example simplicity
})
// illegal move
if (move === null) return 'snapback'
// make random legal move for black
window.setTimeout(makeRandomMove, 500)
//console.log(board.position())
// var result = evaluate(game);
// console.log(result)
}
// update the board position after the piece snap
// for castling, en passant, pawn promotion
function onSnapEnd () {
board.position(game.fen())
}
var config = {
draggable: true,
position: 'start',
onDragStart: onDragStart,
onDrop: onDrop,
onSnapEnd: onSnapEnd
}
board = Chessboard('myBoard', config)
// --- End Example JS ----------------------------------------------------------
</script>
</body></html>