-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhuman-vs-human.html
More file actions
53 lines (52 loc) · 1.75 KB
/
human-vs-human.html
File metadata and controls
53 lines (52 loc) · 1.75 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Local Chess Game</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/chessboard-js/1.0.0/chessboard-1.0.0.min.css">
<style>
body {
margin: 0;
min-height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background: #f0f0f0;
font-family: 'Courier Prime', monospace;
}
#board {
width: 400px;
margin: 20px;
}
</style>
</head>
<body>
<h1>Local Chess Game (Human vs Human)</h1>
<div id="board"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chess.js/0.10.3/chess.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chessboard-js/1.0.0/chessboard-1.0.0.min.js"></script>
<script>
const game = new Chess();
const board = Chessboard('board', {
position: 'start',
draggable: true,
onDrop: (source, target) => {
const move = game.move({
from: source,
to: target,
promotion: 'q'
});
if (move === null) return 'snapback';
board.position(game.fen());
if (game.isGameOver()) {
if (game.inCheckmate()) alert(`Checkmate! ${game.turn() === 'w' ? 'Black' : 'White'} wins!`);
else if (game.inDraw()) alert("It's a draw!");
}
},
pieceTheme: 'img/{piece}.png'
});
</script>
</body>
</html>