-
Notifications
You must be signed in to change notification settings - Fork 1
/
randomVSrandom.html
163 lines (115 loc) · 7.1 KB
/
randomVSrandom.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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<!--
Attributions, credit and copyright
Copyright (C) 2012 André jr Steenveld all rights reserved
Licensed under the MIT public license for the full license see the LICENSE file
Libaries and other sources used:
- Dojo toolkit under the new BSD license http://bugs.dojotoolkit.org/browser/dojo/trunk/LICENSE
- ES5 shim under https://github.com/kriskowal/es5-shim/blob/master/LICENSE
-->
<head>
<title>Random vs. Random</title>
<link rel="stylesheet" type="text/css" href="./style/style.css"></link>
<link rel="stylesheet" type="text/css" href="./script/dijit/themes/tundra/tundra.css"></link>
</head>
<body class="tundra">
<div>
<p id="board-container"></p>
<p id="button-container"></p>
</div>
<script type="text/javascript">
dojoConfig = {
async: true,
parseOnLoad: false,
packages: [
{ name: "lib", location: "../lib" },
{ name: "chess", location: "../chess" }
],
trace: {
// these are listed so it's simple to turn them on/off while debugging loading
"loader-inject":0,
"loader-define":0,
"loader-exec-module":0,
"loader-run-factory":0,
"loader-finish-exec":0,
"loader-define-module":0
}
};
</script>
<script type="text/javascript" src="./script/lib/es5.js"></script>
<script type="text/javascript" src="./script/dojo/dojo.js"></script>
<script type="text/javascript">
var board = null,
game = null,
bPlayer = null,
wPlayer = null;
var chess_timer = null;
require([
"chess", "lib",
"dojo", "dojo/dom-construct",
"chess/Game", "chess/ai/Random",
"chess/Renderer",
"dojo/query",
"dijit/form/Button",
"dojo/on"
],
function( chess, lib, dojo, dom, Game, Random, Renderer, $, Button, connect ){
board = new chess.board.Board( );
// White pieces in starting position
new chess.pieces.Pawn({ color: "white", board: board, field: board.fields.a2 }); new chess.pieces.Rook({ color: "white", board: board, field: board.fields.a1 });
new chess.pieces.Pawn({ color: "white", board: board, field: board.fields.b2 }); new chess.pieces.Knight({ color: "white", board: board, field: board.fields.b1 });
new chess.pieces.Pawn({ color: "white", board: board, field: board.fields.c2 }); new chess.pieces.Bishop({ color: "white", board: board, field: board.fields.c1 });
new chess.pieces.Pawn({ color: "white", board: board, field: board.fields.d2 }); new chess.pieces.Queen({ color: "white", board: board, field: board.fields.d1 });
new chess.pieces.Pawn({ color: "white", board: board, field: board.fields.e2 }); new chess.pieces.King({ color: "white", board: board, field: board.fields.e1 });
new chess.pieces.Pawn({ color: "white", board: board, field: board.fields.f2 }); new chess.pieces.Bishop({ color: "white", board: board, field: board.fields.f1 });
new chess.pieces.Pawn({ color: "white", board: board, field: board.fields.g2 }); new chess.pieces.Knight({ color: "white", board: board, field: board.fields.g1 });
new chess.pieces.Pawn({ color: "white", board: board, field: board.fields.h2 }); new chess.pieces.Rook({ color: "white", board: board, field: board.fields.h1 });
// Black pieces in stating position
new chess.pieces.Pawn({ color: "black", board: board, field: board.fields.a7 }); new chess.pieces.Rook({ color: "black", board: board, field: board.fields.a8 });
new chess.pieces.Pawn({ color: "black", board: board, field: board.fields.b7 }); new chess.pieces.Knight({ color: "black", board: board, field: board.fields.b8 });
new chess.pieces.Pawn({ color: "black", board: board, field: board.fields.c7 }); new chess.pieces.Bishop({ color: "black", board: board, field: board.fields.c8 });
new chess.pieces.Pawn({ color: "black", board: board, field: board.fields.d7 }); new chess.pieces.Queen({ color: "black", board: board, field: board.fields.d8 });
new chess.pieces.Pawn({ color: "black", board: board, field: board.fields.e7 }); new chess.pieces.King({ color: "black", board: board, field: board.fields.e8 });
new chess.pieces.Pawn({ color: "black", board: board, field: board.fields.f7 }); new chess.pieces.Bishop({ color: "black", board: board, field: board.fields.f8 });
new chess.pieces.Pawn({ color: "black", board: board, field: board.fields.g7 }); new chess.pieces.Knight({ color: "black", board: board, field: board.fields.g8 });
new chess.pieces.Pawn({ color: "black", board: board, field: board.fields.h7 }); new chess.pieces.Rook({ color: "black", board: board, field: board.fields.h8 });
game = new chess.Game({ board: board });
// Because we want to do some debugging we will attach ourselfs to the game object
// and log all the events.
var placed = game.on( "Placed", function( ){ console.log( "Game#onPlaced ( " + chess_timer( ) + "ms )::", arguments[ 0 ] ); } ),
moved = game.on( "Moved", function( ){ console.log( "Game#onMoved ( " + chess_timer( ) + "ms )::", arguments[ 0 ] ); } ),
check = game.on( "Check", function( ){ console.log( "Game#onCheck ( " + chess_timer( ) + "ms )::", arguments[ 0 ] ); } ),
staleMate = game.on( "StaleMate", function( ){ console.log( "Game#onStaleMate ( " + chess_timer( ) + "ms )::", arguments[ 0 ] ); } ),
checkMate = game.on( "CheckMate", function( ){ console.log( "Game#onCheckMate ( " + chess_timer( ) + "ms )::", arguments[ 0 ] ); } ),
surrender = game.on( "Surrender", function( ){ console.log( "Game#onSurrender ( " + chess_timer( ) + "ms )::", arguments[ 0 ] ); } ),
start = game.on( "Start", function( ){ console.log( "Game#onStart ( " + chess_timer( ) + "ms )::", arguments[ 0 ] ); } ),
draw = game.on( "Draw", function( ){ console.log( "Game#onDraw ( " + chess_timer( ) + "ms )::", arguments[ 0 ] ); } ),
end = game.on( "End", function( ){ console.log( "Game#onEnd ( " + chess_timer( ) + "ms )::", arguments[ 0 ] ); } ),
playerJoin = game.on( "PlayerJoin", function( ){ console.log( "Game#onPlayerJoin ( " + chess_timer( ) + "ms )::", arguments[ 0 ] ); } ),
playerLeave = game.on( "PlayerLeave", function( ){ console.log( "Game#onPlayerLeaver ( " + chess_timer( ) + "ms )::", arguments[ 0 ] ); } );
game.on( "Moved", function( ){
dojo.attr( "board-container", { innerHTML: Renderer.render( board ) });
});
dojo.ready( function( ){
dojo.attr( "board-container", { innerHTML: Renderer.render( board ) });
chess_timer = ( function( ){
var start = new Date( ).getTime( );
return function( ){
return ( new Date( ) ).getTime( ) - start;
}
} )( );
// The players need the button to be properly intialized... Buh.. not neat but it works.
bPlayer = new Random({ color: "black", game: game });
wPlayer = new Random({ color: "white", game: game });
var button = new Button({
label: "Start game",
onClick: game.start.bind( game )
});
button.placeAt( "button-container" );
button.startup( );
});
});
</script>
</body>
</html>