Add custom piece colours and White/Black standard avatars.
Players can keep default White/Black skins or pick preferred/alternative colours; conflicts resolve once when a game starts and skins persist for replays. Account settings can disable custom colours locally.
@@ -13,6 +13,7 @@ php_tests:
13
13
- find web -name '*.php' -not -path '*/artifacts/*' -print0 | xargs -0 -n1 php -l
14
14
- php -r 'foreach (["pdo_sqlite", "curl", "mbstring", "openssl"] as $extension) { if (!extension_loaded($extension)) { fwrite(STDERR, "Missing extension " . $extension); exit(1); } }'
15
15
- php web/tests/chess.php
16
- php web/tests/colors.php
16
17
- php web/tests/feedback.php
17
18
- php web/tests/push.php
18
19
- python3 web/tests/startup.py
@@ -13,6 +13,7 @@ php_tests:13
- find web -name '*.php' -not -path '*/artifacts/*' -print0 | xargs -0 -n1 php -l13
- find web -name '*.php' -not -path '*/artifacts/*' -print0 | xargs -0 -n1 php -l14
- php -r 'foreach (["pdo_sqlite", "curl", "mbstring", "openssl"] as $extension) { if (!extension_loaded($extension)) { fwrite(STDERR, "Missing extension " . $extension); exit(1); } }'14
- php -r 'foreach (["pdo_sqlite", "curl", "mbstring", "openssl"] as $extension) { if (!extension_loaded($extension)) { fwrite(STDERR, "Missing extension " . $extension); exit(1); } }'15
- php web/tests/chess.php15
- php web/tests/chess.php16
- php web/tests/colors.php16
- php web/tests/feedback.php17
- php web/tests/feedback.php17
- php web/tests/push.php18
- php web/tests/push.php18
- python3 web/tests/startup.py19
- python3 web/tests/startup.py@@ -80,7 +80,7 @@ The integration tests exercise rating updates, rematches, duplicate results, con
80
80
81
81
## Avatars
82
82
83
Click your avatar at the bottom of the friends sidebar to open the piece picker. The local collection contains 91 selected avatars: 67 fairy pieces and 24 colored standard pieces. Removed files are excluded from the catalog; PNG and SVG versions of the same piece appear as one choice. The picker has color/family filters and an option to choose randomly. Accounts without an avatar receive a random piece automatically. Selection is saved in SQLite and appears in friend lists, opponent tile headers and your data export. The `user_avatars` table is created automatically, preserving existing accounts and game data.
83
Click your avatar at the bottom of the friends sidebar to open the piece picker. The local collection contains 103 selected avatars: 67 fairy pieces and 36 colored standard pieces (including White and Black). Removed files are excluded from the catalog; PNG and SVG versions of the same piece appear as one choice. The picker has color/family filters and an option to choose randomly. Accounts without an avatar receive a random piece automatically. Selection is saved in SQLite and appears in friend lists, opponent tile headers and your data export. Click your name under the avatar to choose default or custom piece colours (White/Black/Red/Blue/Green/Yellow); resolved skins are stored per game for live play and replays. Account settings can disable custom colours locally (default on). The `user_avatars` table is created automatically, preserving existing accounts and game data.
84
84
85
85
Avatars use locally stored PNG previews from Wikimedia Commons; available original SVGs are included alongside them. Author, original file and license links are recorded in [avatar credits](assets/avatars/CREDITS.md) and `assets/avatars/catalog.json`. There are no runtime requests to Wikimedia.
86
86
@@ -80,7 +80,7 @@ The integration tests exercise rating updates, rematches, duplicate results, con80
80
81
## Avatars81
## Avatars82
82
83
Click your avatar at the bottom of the friends sidebar to open the piece picker. The local collection contains 91 selected avatars: 67 fairy pieces and 24 colored standard pieces. Removed files are excluded from the catalog; PNG and SVG versions of the same piece appear as one choice. The picker has color/family filters and an option to choose randomly. Accounts without an avatar receive a random piece automatically. Selection is saved in SQLite and appears in friend lists, opponent tile headers and your data export. The `user_avatars` table is created automatically, preserving existing accounts and game data.83
Click your avatar at the bottom of the friends sidebar to open the piece picker. The local collection contains 103 selected avatars: 67 fairy pieces and 36 colored standard pieces (including White and Black). Removed files are excluded from the catalog; PNG and SVG versions of the same piece appear as one choice. The picker has color/family filters and an option to choose randomly. Accounts without an avatar receive a random piece automatically. Selection is saved in SQLite and appears in friend lists, opponent tile headers and your data export. Click your name under the avatar to choose default or custom piece colours (White/Black/Red/Blue/Green/Yellow); resolved skins are stored per game for live play and replays. Account settings can disable custom colours locally (default on). The `user_avatars` table is created automatically, preserving existing accounts and game data.84
84
85
Avatars use locally stored PNG previews from Wikimedia Commons; available original SVGs are included alongside them. Author, original file and license links are recorded in [avatar credits](assets/avatars/CREDITS.md) and `assets/avatars/catalog.json`. There are no runtime requests to Wikimedia.85
Avatars use locally stored PNG previews from Wikimedia Commons; available original SVGs are included alongside them. Author, original file and license links are recorded in [avatar credits](assets/avatars/CREDITS.md) and `assets/avatars/catalog.json`. There are no runtime requests to Wikimedia.86
86
@@ -6,9 +6,11 @@ try {
6
6
session_write_close();
7
7
$token=$_GET['token']??'';
8
8
if (!is_string($token) || !preg_match('/^[a-f0-9]{48}$/D',$token)) fail('Saved game not found.',404);
9
$r=query('SELECT r.a,r.b,r.winner,r.reason,r.ended,p.white,p.moves FROM replay_links l JOIN replays p ON p.result_id=l.result_id JOIN results r ON r.id=p.result_id WHERE l.token=?',[$token])->fetch();
9
$r=query('SELECT r.a,r.b,r.winner,r.reason,r.ended,p.white,p.moves,p.piece_skin_white,p.piece_skin_black FROM replay_links l JOIN replays p ON p.result_id=l.result_id JOIN results r ON r.id=p.result_id WHERE l.token=?',[$token])->fetch();
10
10
if (!$r) fail('Saved game not found.',404);
11
jsonOut(replayPlayers($r)+['shared'=>true,'shareToken'=>$token,'color'=>'w','ended'=>(int)$r['ended'],'reason'=>$r['reason'],'outcome'=>$r['winner']===null?'Draw':($r['winner']===$r['white']?'White won':'Black won'),'positions'=>replayPositions($r['moves'])]);
11
$skinWhite=in_array($r['piece_skin_white']??'',PIECE_COLORS,true)?$r['piece_skin_white']:'White';
12
$skinBlack=in_array($r['piece_skin_black']??'',PIECE_COLORS,true)?$r['piece_skin_black']:'Black';
13
jsonOut(replayPlayers($r)+['shared'=>true,'shareToken'=>$token,'color'=>'w','ended'=>(int)$r['ended'],'reason'=>$r['reason'],'outcome'=>$r['winner']===null?'Draw':($r['winner']===$r['white']?'White won':'Black won'),'positions'=>replayPositions($r['moves']),'pieceSkinWhite'=>$skinWhite,'pieceSkinBlack'=>$skinBlack,'displayColor'=>$skinWhite,'opponentDisplayColor'=>$skinBlack]);
12
14
}
13
15
$u=user();
14
16
if (!localDev() && time()-($_SESSION['validated']??0)>60) {
@@ -33,7 +35,12 @@ try {
33
35
if ($action==='replay') {
34
36
$item+=replayPlayers($r);
35
37
$item['shareToken']=replayLink((int)$r['id']);
36
$item['positions']=replayPositions(query('SELECT moves FROM replays WHERE result_id=?',[$r['id']])->fetchColumn());
38
$replayRow=query('SELECT moves,piece_skin_white,piece_skin_black FROM replays WHERE result_id=?',[$r['id']])->fetch();
39
$item['positions']=replayPositions($replayRow['moves']);
40
$item['pieceSkinWhite']=in_array($replayRow['piece_skin_white']??'',PIECE_COLORS,true)?$replayRow['piece_skin_white']:'White';
41
$item['pieceSkinBlack']=in_array($replayRow['piece_skin_black']??'',PIECE_COLORS,true)?$replayRow['piece_skin_black']:'Black';
42
$item['displayColor']=$item['color']==='w'?$item['pieceSkinWhite']:$item['pieceSkinBlack'];
43
$item['opponentDisplayColor']=$item['color']==='w'?$item['pieceSkinBlack']:$item['pieceSkinWhite'];
37
44
jsonOut($item);
38
45
}
39
46
$items[]=$item;
@@ -132,6 +139,12 @@ try {
132
139
if (!is_string($avatar)||!in_array($avatar,array_column(avatarCatalog(),'id'),true)) throw new DomainException('Choose an avatar from the available pieces.');
133
140
query('INSERT INTO user_avatars(user_id,avatar) VALUES(?,?) ON CONFLICT(user_id) DO UPDATE SET avatar=excluded.avatar',[$u,$avatar]);
134
141
}
142
} elseif ($action==='set_piece_colors') {
143
$mode=$in['colorMode']??'';
144
$preferred=$in['preferredColor']??'';
145
$alternative=$in['alternativeColor']??'';
146
if (!is_string($mode)||!is_string($preferred)||!is_string($alternative)) throw new DomainException('Invalid colour preference.');
147
savePieceColorPrefs($u,$mode,$preferred,$alternative);
135
148
} elseif ($action==='create_link') {
136
149
$kind=$in['kind']??''; if (!in_array($kind,['friend','match'],true)) throw new DomainException('Invalid invitation type.');
137
150
$token=bin2hex(random_bytes(24));
@@ -165,14 +178,22 @@ try {
165
178
} elseif (in_array($action,['accept','reject'],true)) {
166
179
if ($g['status']!=='pending' || $g['b']!==$u) throw new DomainException('This invitation is no longer available.');
167
180
if ($action==='reject') query('DELETE FROM games WHERE id=?',[$g['id']]);
168
else query("UPDATE games SET status='active',white=?,state=?,version=version+1 WHERE id=?",[random_int(0,1)?$g['a']:$g['b'],json_encode(Chess::initial()),$g['id']]);
181
else {
182
$white=random_int(0,1)?$g['a']:$g['b'];
183
query("UPDATE games SET status='active',white=?,state=?,version=version+1 WHERE id=?",[$white,json_encode(Chess::initial()),$g['id']]);
184
assignGamePieceSkins((int)$g['id'],$white,$white===$g['a']?$g['b']:$g['a']);
185
}
169
186
} elseif ($action==='exit' || $action==='rematch') {
170
187
if ($g['status']!=='ended') throw new DomainException('The game has not ended.');
171
188
if ($action==='exit') query("UPDATE games SET exit_$side=1,rematch_$side=0,version=version+1 WHERE id=?",[$g['id']]);
172
189
else {
173
190
if ($g['exit_'.$opSide]) throw new DomainException('Your opponent has left this game.');
174
191
if ($g['rematch_'.$side]) throw new DomainException('Your rematch request is already waiting.');
175
if ($g['rematch_'.$opSide]) query("UPDATE games SET status='active',white=?,state=?,winner=NULL,reason=NULL,rematch_a=0,rematch_b=0,draw_offer=NULL,version=version+1 WHERE id=?",[$g['white']===$g['a']?$g['b']:$g['a'],json_encode(Chess::initial()),$g['id']]);
192
if ($g['rematch_'.$opSide]) {
193
$white=$g['white']===$g['a']?$g['b']:$g['a'];
194
query("UPDATE games SET status='active',white=?,state=?,winner=NULL,reason=NULL,rematch_a=0,rematch_b=0,draw_offer=NULL,piece_skin_white=NULL,piece_skin_black=NULL,version=version+1 WHERE id=?",[$white,json_encode(Chess::initial()),$g['id']]);
195
assignGamePieceSkins((int)$g['id'],$white,$white===$g['a']?$g['b']:$g['a']);
196
}
176
197
else query("UPDATE games SET rematch_$side=1,version=version+1 WHERE id=?",[$g['id']]);
177
198
}
178
199
} else {
@@ -6,9 +6,11 @@ try {6
session_write_close();6
session_write_close();7
$token=$_GET['token']??'';7
$token=$_GET['token']??'';8
if (!is_string($token) || !preg_match('/^[a-f0-9]{48}$/D',$token)) fail('Saved game not found.',404);8
if (!is_string($token) || !preg_match('/^[a-f0-9]{48}$/D',$token)) fail('Saved game not found.',404);9
$r=query('SELECT r.a,r.b,r.winner,r.reason,r.ended,p.white,p.moves FROM replay_links l JOIN replays p ON p.result_id=l.result_id JOIN results r ON r.id=p.result_id WHERE l.token=?',[$token])->fetch();9
$r=query('SELECT r.a,r.b,r.winner,r.reason,r.ended,p.white,p.moves,p.piece_skin_white,p.piece_skin_black FROM replay_links l JOIN replays p ON p.result_id=l.result_id JOIN results r ON r.id=p.result_id WHERE l.token=?',[$token])->fetch();10
if (!$r) fail('Saved game not found.',404);10
if (!$r) fail('Saved game not found.',404);11
jsonOut(replayPlayers($r)+['shared'=>true,'shareToken'=>$token,'color'=>'w','ended'=>(int)$r['ended'],'reason'=>$r['reason'],'outcome'=>$r['winner']===null?'Draw':($r['winner']===$r['white']?'White won':'Black won'),'positions'=>replayPositions($r['moves'])]);11
$skinWhite=in_array($r['piece_skin_white']??'',PIECE_COLORS,true)?$r['piece_skin_white']:'White';12
$skinBlack=in_array($r['piece_skin_black']??'',PIECE_COLORS,true)?$r['piece_skin_black']:'Black';13
jsonOut(replayPlayers($r)+['shared'=>true,'shareToken'=>$token,'color'=>'w','ended'=>(int)$r['ended'],'reason'=>$r['reason'],'outcome'=>$r['winner']===null?'Draw':($r['winner']===$r['white']?'White won':'Black won'),'positions'=>replayPositions($r['moves']),'pieceSkinWhite'=>$skinWhite,'pieceSkinBlack'=>$skinBlack,'displayColor'=>$skinWhite,'opponentDisplayColor'=>$skinBlack]);12
}14
}13
$u=user();15
$u=user();14
if (!localDev() && time()-($_SESSION['validated']??0)>60) {16
if (!localDev() && time()-($_SESSION['validated']??0)>60) {@@ -33,7 +35,12 @@ try {33
if ($action==='replay') {35
if ($action==='replay') {34
$item+=replayPlayers($r);36
$item+=replayPlayers($r);35
$item['shareToken']=replayLink((int)$r['id']);37
$item['shareToken']=replayLink((int)$r['id']);36
$item['positions']=replayPositions(query('SELECT moves FROM replays WHERE result_id=?',[$r['id']])->fetchColumn());38
$replayRow=query('SELECT moves,piece_skin_white,piece_skin_black FROM replays WHERE result_id=?',[$r['id']])->fetch();39
$item['positions']=replayPositions($replayRow['moves']);40
$item['pieceSkinWhite']=in_array($replayRow['piece_skin_white']??'',PIECE_COLORS,true)?$replayRow['piece_skin_white']:'White';41
$item['pieceSkinBlack']=in_array($replayRow['piece_skin_black']??'',PIECE_COLORS,true)?$replayRow['piece_skin_black']:'Black';42
$item['displayColor']=$item['color']==='w'?$item['pieceSkinWhite']:$item['pieceSkinBlack'];43
$item['opponentDisplayColor']=$item['color']==='w'?$item['pieceSkinBlack']:$item['pieceSkinWhite'];37
jsonOut($item);44
jsonOut($item);38
}45
}39
$items[]=$item;46
$items[]=$item;@@ -132,6 +139,12 @@ try {132
if (!is_string($avatar)||!in_array($avatar,array_column(avatarCatalog(),'id'),true)) throw new DomainException('Choose an avatar from the available pieces.');139
if (!is_string($avatar)||!in_array($avatar,array_column(avatarCatalog(),'id'),true)) throw new DomainException('Choose an avatar from the available pieces.');133
query('INSERT INTO user_avatars(user_id,avatar) VALUES(?,?) ON CONFLICT(user_id) DO UPDATE SET avatar=excluded.avatar',[$u,$avatar]);140
query('INSERT INTO user_avatars(user_id,avatar) VALUES(?,?) ON CONFLICT(user_id) DO UPDATE SET avatar=excluded.avatar',[$u,$avatar]);134
}141
}142
} elseif ($action==='set_piece_colors') {143
$mode=$in['colorMode']??'';144
$preferred=$in['preferredColor']??'';145
$alternative=$in['alternativeColor']??'';146
if (!is_string($mode)||!is_string($preferred)||!is_string($alternative)) throw new DomainException('Invalid colour preference.');147
savePieceColorPrefs($u,$mode,$preferred,$alternative);135
} elseif ($action==='create_link') {148
} elseif ($action==='create_link') {136
$kind=$in['kind']??''; if (!in_array($kind,['friend','match'],true)) throw new DomainException('Invalid invitation type.');149
$kind=$in['kind']??''; if (!in_array($kind,['friend','match'],true)) throw new DomainException('Invalid invitation type.');137
$token=bin2hex(random_bytes(24));150
$token=bin2hex(random_bytes(24));@@ -165,14 +178,22 @@ try {165
} elseif (in_array($action,['accept','reject'],true)) {178
} elseif (in_array($action,['accept','reject'],true)) {166
if ($g['status']!=='pending' || $g['b']!==$u) throw new DomainException('This invitation is no longer available.');179
if ($g['status']!=='pending' || $g['b']!==$u) throw new DomainException('This invitation is no longer available.');167
if ($action==='reject') query('DELETE FROM games WHERE id=?',[$g['id']]);180
if ($action==='reject') query('DELETE FROM games WHERE id=?',[$g['id']]);168
else query("UPDATE games SET status='active',white=?,state=?,version=version+1 WHERE id=?",[random_int(0,1)?$g['a']:$g['b'],json_encode(Chess::initial()),$g['id']]);181
else {182
$white=random_int(0,1)?$g['a']:$g['b'];183
query("UPDATE games SET status='active',white=?,state=?,version=version+1 WHERE id=?",[$white,json_encode(Chess::initial()),$g['id']]);184
assignGamePieceSkins((int)$g['id'],$white,$white===$g['a']?$g['b']:$g['a']);185
}169
} elseif ($action==='exit' || $action==='rematch') {186
} elseif ($action==='exit' || $action==='rematch') {170
if ($g['status']!=='ended') throw new DomainException('The game has not ended.');187
if ($g['status']!=='ended') throw new DomainException('The game has not ended.');171
if ($action==='exit') query("UPDATE games SET exit_$side=1,rematch_$side=0,version=version+1 WHERE id=?",[$g['id']]);188
if ($action==='exit') query("UPDATE games SET exit_$side=1,rematch_$side=0,version=version+1 WHERE id=?",[$g['id']]);172
else {189
else {173
if ($g['exit_'.$opSide]) throw new DomainException('Your opponent has left this game.');190
if ($g['exit_'.$opSide]) throw new DomainException('Your opponent has left this game.');174
if ($g['rematch_'.$side]) throw new DomainException('Your rematch request is already waiting.');191
if ($g['rematch_'.$side]) throw new DomainException('Your rematch request is already waiting.');175
if ($g['rematch_'.$opSide]) query("UPDATE games SET status='active',white=?,state=?,winner=NULL,reason=NULL,rematch_a=0,rematch_b=0,draw_offer=NULL,version=version+1 WHERE id=?",[$g['white']===$g['a']?$g['b']:$g['a'],json_encode(Chess::initial()),$g['id']]);192
if ($g['rematch_'.$opSide]) {193
$white=$g['white']===$g['a']?$g['b']:$g['a'];194
query("UPDATE games SET status='active',white=?,state=?,winner=NULL,reason=NULL,rematch_a=0,rematch_b=0,draw_offer=NULL,piece_skin_white=NULL,piece_skin_black=NULL,version=version+1 WHERE id=?",[$white,json_encode(Chess::initial()),$g['id']]);195
assignGamePieceSkins((int)$g['id'],$white,$white===$g['a']?$g['b']:$g['a']);196
}176
else query("UPDATE games SET rematch_$side=1,version=version+1 WHERE id=?",[$g['id']]);197
else query("UPDATE games SET rematch_$side=1,version=version+1 WHERE id=?",[$g['id']]);177
}198
}178
} else {199
} else {@@ -299,6 +299,31 @@ main {
299
299
border-color: #28382e
300
300
}
301
301
302
.color-disc.white {
303
background: #fff;
304
border-color: #8d978b
305
}
306
307
.color-disc.red {
308
background: #c62828;
309
border-color: #8e1b1b
310
}
311
312
.color-disc.blue {
313
background: #1565c0;
314
border-color: #0d47a1
315
}
316
317
.color-disc.green {
318
background: #2e7d32;
319
border-color: #1b5e20
320
}
321
322
.color-disc.yellow {
323
background: #f9a825;
324
border-color: #f57f17
325
}
326
302
327
.board-wrap {
303
328
padding: 15px;
304
329
position: relative
@@ -1074,6 +1099,107 @@ dialog input {
1074
1099
object-fit: contain
1075
1100
}
1076
1101
1102
1103
#account-summary .account-name-button {
1104
border: 0;
1105
background: transparent;
1106
padding: 0;
1107
text-align: left;
1108
font: inherit;
1109
color: inherit;
1110
cursor: pointer;
1111
min-width: 0
1112
}
1113
1114
#account-summary .account-name-button:hover span {
1115
text-decoration: underline
1116
}
1117
1118
#account-summary .account-name-button span {
1119
display: block;
1120
overflow: hidden;
1121
text-overflow: ellipsis;
1122
white-space: nowrap
1123
}
1124
1125
.settings-check {
1126
display: flex;
1127
align-items: center;
1128
gap: 8px;
1129
margin: 12px 0 4px;
1130
font-size: 13px;
1131
cursor: pointer
1132
}
1133
1134
.color-mode-options {
1135
display: grid;
1136
gap: 10px;
1137
margin: 16px 0
1138
}
1139
1140
.color-mode-option {
1141
display: flex;
1142
gap: 10px;
1143
align-items: flex-start;
1144
padding: 12px;
1145
border: 1px solid var(--line);
1146
border-radius: 12px;
1147
cursor: pointer
1148
}
1149
1150
.color-mode-option strong {
1151
display: block
1152
}
1153
1154
.color-mode-option small {
1155
display: block;
1156
color: var(--muted);
1157
margin-top: 2px
1158
}
1159
1160
.custom-color-pickers {
1161
display: grid;
1162
grid-template-columns: 1fr 1fr;
1163
gap: 12px;
1164
margin-bottom: 16px
1165
}
1166
1167
.custom-color-pickers[hidden] {
1168
display: none
1169
}
1170
1171
.color-king-choice {
1172
display: grid;
1173
justify-items: center;
1174
gap: 4px;
1175
padding: 12px 8px;
1176
border: 1px solid var(--line);
1177
border-radius: 12px;
1178
background: #f7f8f2;
1179
cursor: pointer;
1180
font: inherit;
1181
color: inherit
1182
}
1183
1184
.color-king-choice img {
1185
width: 64px;
1186
height: 64px;
1187
object-fit: contain
1188
}
1189
1190
.color-king-choice span {
1191
font-size: 11px;
1192
color: var(--muted)
1193
}
1194
1195
.color-king-choice:hover {
1196
border-color: #8d978b
1197
}
1198
1199
.replay-players span[title] {
1200
cursor: help
1201
}
1202
1077
1203
#avatar-button {
1078
1204
padding: 0;
1079
1205
color: inherit;
@@ -299,6 +299,31 @@ main {299
border-color: #28382e299
border-color: #28382e300
}300
}301
301
302
.color-disc.white {303
background: #fff;304
border-color: #8d978b305
}306
307
.color-disc.red {308
background: #c62828;309
border-color: #8e1b1b310
}311
312
.color-disc.blue {313
background: #1565c0;314
border-color: #0d47a1315
}316
317
.color-disc.green {318
background: #2e7d32;319
border-color: #1b5e20320
}321
322
.color-disc.yellow {323
background: #f9a825;324
border-color: #f57f17325
}326
302
.board-wrap {327
.board-wrap {303
padding: 15px;328
padding: 15px;304
position: relative329
position: relative@@ -1074,6 +1099,107 @@ dialog input {1074
object-fit: contain1099
object-fit: contain1075
}1100
}1076
1101
1102
1103
#account-summary .account-name-button {1104
border: 0;1105
background: transparent;1106
padding: 0;1107
text-align: left;1108
font: inherit;1109
color: inherit;1110
cursor: pointer;1111
min-width: 01112
}1113
1114
#account-summary .account-name-button:hover span {1115
text-decoration: underline1116
}1117
1118
#account-summary .account-name-button span {1119
display: block;1120
overflow: hidden;1121
text-overflow: ellipsis;1122
white-space: nowrap1123
}1124
1125
.settings-check {1126
display: flex;1127
align-items: center;1128
gap: 8px;1129
margin: 12px 0 4px;1130
font-size: 13px;1131
cursor: pointer1132
}1133
1134
.color-mode-options {1135
display: grid;1136
gap: 10px;1137
margin: 16px 01138
}1139
1140
.color-mode-option {1141
display: flex;1142
gap: 10px;1143
align-items: flex-start;1144
padding: 12px;1145
border: 1px solid var(--line);1146
border-radius: 12px;1147
cursor: pointer1148
}1149
1150
.color-mode-option strong {1151
display: block1152
}1153
1154
.color-mode-option small {1155
display: block;1156
color: var(--muted);1157
margin-top: 2px1158
}1159
1160
.custom-color-pickers {1161
display: grid;1162
grid-template-columns: 1fr 1fr;1163
gap: 12px;1164
margin-bottom: 16px1165
}1166
1167
.custom-color-pickers[hidden] {1168
display: none1169
}1170
1171
.color-king-choice {1172
display: grid;1173
justify-items: center;1174
gap: 4px;1175
padding: 12px 8px;1176
border: 1px solid var(--line);1177
border-radius: 12px;1178
background: #f7f8f2;1179
cursor: pointer;1180
font: inherit;1181
color: inherit1182
}1183
1184
.color-king-choice img {1185
width: 64px;1186
height: 64px;1187
object-fit: contain1188
}1189
1190
.color-king-choice span {1191
font-size: 11px;1192
color: var(--muted)1193
}1194
1195
.color-king-choice:hover {1196
border-color: #8d978b1197
}1198
1199
.replay-players span[title] {1200
cursor: help1201
}1202
1077
#avatar-button {1203
#avatar-button {1078
padding: 0;1204
padding: 0;1079
color: inherit;1205
color: inherit;@@ -3,7 +3,61 @@ const $ = (s, root = document) => root.querySelector(s);
3
3
const esc = s => String(s ?? '').replace(/[&<>"']/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
4
4
const names = { p: 'Pawn', r: 'Rook', n: 'Knight', b: 'Bishop', q: 'Queen', k: 'King' };
5
5
const materialValues = { p: 1, n: 3, b: 3, r: 5, q: 9, k: 0 };
6
const pieceUrl = p => `assets/pieces/${p.toLowerCase()}${p === p.toUpperCase() ? 'l' : 'd'}t.svg`;
6
const PIECE_COLOR_ORDER = ['White', 'Black', 'Red', 'Blue', 'Green', 'Yellow'];
7
const CUSTOM_PIECE_SKINS = new Set(['Red', 'Blue', 'Green', 'Yellow']);
8
const pieceFileNames = { k: 'king', q: 'queen', r: 'rook', b: 'bishop', n: 'knight', p: 'pawn' };
9
const DISABLE_CUSTOM_COLOURS_KEY = 'microchess-disable-custom-colours';
10
function customColoursDisabled ()
11
{
12
try { return localStorage.getItem(DISABLE_CUSTOM_COLOURS_KEY) !== '0'; } catch { return true; }
13
}
14
function setCustomColoursDisabled (disabled)
15
{
16
try { localStorage.setItem(DISABLE_CUSTOM_COLOURS_KEY, disabled ? '1' : '0'); } catch {}
17
}
18
const classicPieceUrl = p => `assets/pieces/${p.toLowerCase()}${p === p.toUpperCase() ? 'l' : 'd'}t.svg`;
19
const pieceUrl = (p, skin) =>
20
{
21
if (!skin || customColoursDisabled() || !CUSTOM_PIECE_SKINS.has(skin)) return classicPieceUrl(p);
22
return `assets/avatars/${skin.toLowerCase()}-${pieceFileNames[p.toLowerCase()]}.png`;
23
};
24
function skinForPiece (g, p)
25
{
26
if (!g || p === '.') return null;
27
const whiteSkin = g.pieceSkinWhite || 'White';
28
const blackSkin = g.pieceSkinBlack || 'Black';
29
return p === p.toUpperCase() ? whiteSkin : blackSkin;
30
}
31
function displayColorFor (g)
32
{
33
if (!g) return 'White';
34
if (customColoursDisabled()) return g.color === 'w' ? 'White' : 'Black';
35
return g.displayColor || (g.color === 'w' ? (g.pieceSkinWhite || 'White') : (g.pieceSkinBlack || 'Black'));
36
}
37
function rulesColorLabel (g) { return g.color === 'w' ? 'White' : 'Black'; }
38
function colorTagMarkup (g)
39
{
40
const display = displayColorFor(g);
41
const rules = rulesColorLabel(g);
42
const tip = !customColoursDisabled() && display !== rules ? `Playing as ${display} (${rules})` : `Playing as ${display}`;
43
const disc = display.toLowerCase();
44
return `<span class="color-tag" title="${esc(tip)}"><span class="color-disc ${esc(disc)}"></span>${esc(display)}</span>`;
45
}
46
function kingAvatarUrl (color)
47
{
48
return `assets/avatars/${color.toLowerCase()}-king.png`;
49
}
50
function nextColorSkipping (current, skip)
51
{
52
let i = PIECE_COLOR_ORDER.indexOf(current);
53
if (i < 0) i = 0;
54
for (let n = 0; n < PIECE_COLOR_ORDER.length; n++)
55
{
56
i = (i + 1) % PIECE_COLOR_ORDER.length;
57
if (PIECE_COLOR_ORDER[i] !== skip) return PIECE_COLOR_ORDER[i];
58
}
59
return current;
60
}
7
61
const initials = name => esc(name.slice(0, 2).toUpperCase());
8
62
const avatarUrl = id => `assets/avatars/${encodeURIComponent(id)}.png`;
9
63
function avatarMarkup (name, id, editable = false)
@@ -33,6 +87,42 @@ function renderAvatarChoices ()
33
87
$('#avatar-option-count').textContent = `${options.length} pieces`;
34
88
document.querySelectorAll('[data-avatar-group]').forEach(b => b.setAttribute('aria-pressed', String(b.dataset.avatarGroup === avatarGroup)));
35
89
}
90
91
function openColorPreferences ()
92
{
93
if (!state) return;
94
const pref = {
95
mode: state.user.colorMode === 'custom' ? 'custom' : 'default',
96
preferred: state.user.preferredColor || 'White',
97
alternative: state.user.alternativeColor || 'Black'
98
};
99
if (pref.preferred === pref.alternative) pref.alternative = nextColorSkipping(pref.alternative, pref.preferred);
100
const paint = () =>
101
{
102
showModal(`<span class="eyebrow">YOUR SIDE</span><h2 id="modal-title">Piece colours</h2><p>Choose how your pieces look in new games. Opponents may use a different colour when both prefer the same one.</p><div class="color-mode-options" role="radiogroup" aria-label="Colour mode"><label class="color-mode-option"><input type="radio" name="color-mode" id="color-mode-default" value="default" ${pref.mode !== 'custom' ? 'checked' : ''}> <span><strong>Default Colours</strong><small>Play as White or Black by the rules side, as usual.</small></span></label><label class="color-mode-option"><input type="radio" name="color-mode" id="color-mode-custom" value="custom" ${pref.mode === 'custom' ? 'checked' : ''}> <span><strong>Custom Colour</strong><small>Pick a preferred colour and an alternative if both players clash.</small></span></label></div><div id="custom-color-pickers" class="custom-color-pickers"${pref.mode === 'custom' ? '' : ' hidden'}><button type="button" class="color-king-choice" data-color-role="preferred" aria-label="Preferred colour ${esc(pref.preferred)}"><img src="${kingAvatarUrl(pref.preferred)}" alt=""><span>Preferred</span><strong>${esc(pref.preferred)}</strong></button><button type="button" class="color-king-choice" data-color-role="alternative" aria-label="Alternative colour ${esc(pref.alternative)}"><img src="${kingAvatarUrl(pref.alternative)}" alt=""><span>Alternative</span><strong>${esc(pref.alternative)}</strong></button></div><div class="actions"><button class="primary" id="save-color-prefs">Save</button><button class="secondary" data-modal-action="close">Cancel</button></div>`);
103
$('#color-mode-default').onchange = () => { pref.mode = 'default'; paint(); };
104
$('#color-mode-custom').onchange = () => { pref.mode = 'custom'; paint(); };
105
document.querySelectorAll('[data-color-role]').forEach(btn =>
106
{
107
btn.onclick = () =>
108
{
109
if (btn.dataset.colorRole === 'preferred') pref.preferred = nextColorSkipping(pref.preferred, pref.alternative);
110
else pref.alternative = nextColorSkipping(pref.alternative, pref.preferred);
111
paint();
112
};
113
});
114
$('#save-color-prefs').onclick = async () =>
115
{
116
await action({ action: 'set_piece_colors', colorMode: pref.mode, preferredColor: pref.preferred, alternativeColor: pref.alternative }, () =>
117
{
118
closeModal();
119
toast('Colour preference saved.');
120
});
121
};
122
};
123
paint();
124
}
125
36
126
let state, selected = null, promotion = null, busy = false, drag = null, lastRender = '', toastTimer, inviteShown = false;
37
127
const moveHolds = new Map();
38
128
const moveFeedback = new Map();
@@ -178,7 +268,7 @@ function card (g)
178
268
else if (g.status === 'pending') content = `<div class="pending-content"><span class="big-icon">♘</span><h3>${g.incoming ? 'A little challenge?' : 'Challenge sent.'}</h3><p>${g.incoming ? `${esc(g.opponent)} invited you to play.<br>Your board is waiting.` : `Waiting for ${esc(g.opponent)}<br>to accept your challenge.`}</p>${g.incoming ? `<div class="actions"><button class="primary" data-game-action="accept">Accept</button><button class="secondary" data-game-action="reject">Reject</button></div>` : '<span class="inline-note"></span>'}</div>`;
179
269
else if (g.status === 'ended') content = `<div class="ended-board">${board(g)}<div class="end-content"><div class="end-status"><h3>${g.outcome === 'win' ? 'You won!' : g.outcome === 'loss' ? 'You lost' : 'A game well matched.'}</h3><small>${esc(g.reason)}</small>${g.opponentRematch && g.canRematch ? `<small>${esc(g.opponent)} wants a rematch.</small>` : ''}</div><div class="actions">${g.canRematch ? `<button class="primary" data-game-action="rematch" ${g.rematch ? 'disabled' : ''}>${g.rematch ? 'Requested' : 'Rematch'}</button>` : ''}<button class="secondary" data-game-action="exit">Exit</button></div></div></div>`;
180
270
else content = board(g) + `<div class="card-footer"><span class="${g.yourTurn ? 'turn-label' : ''}">${g.check ? 'Check · ' : ''}${g.yourTurn ? 'Your move' : 'Waiting for a move'}</span>${g.yourTurn ? `<button class="text-button" data-game-action="options" aria-label="Game options">${g.drawOffer === 'opponent' ? 'Draw offered · ' : ''}•••</button>` : `<span>Move ${Math.floor(g.state.ply / 2) + 1}</span>`}</div>`;
181
return `<article class="game-card ${!g.yourTurn && g.status === 'active' ? 'waiting' : ''}" data-game="${g.id}" aria-label="Game with ${esc(g.opponent)}"><div class="card-header">${avatarMarkup(g.opponent, g.opponentAvatar)}<div class="opponent-info"><strong><button class="opponent-name" data-opponent="${esc(g.opponentId)}">${esc(g.opponent)}</button> <small class="rating" aria-label="${g.opponentRating} Elo">${g.opponentRating}</small></strong>${g.status !== 'pending' ? materialBar(g) : ''}</div>${g.status !== 'pending' ? `<span class="color-tag"><span class="color-disc ${g.color === 'b' ? 'black' : ''}"></span>${g.color === 'w' ? 'White' : 'Black'}</span>` : ''}${g.inactiveDays >= 7 ? '<button class="stop-inactive" data-game-action="stop-confirm" aria-label="Stop inactive game" title="Stop inactive game">×</button>' : ''}</div>${content}</article>`;
271
return `<article class="game-card ${!g.yourTurn && g.status === 'active' ? 'waiting' : ''}" data-game="${g.id}" aria-label="Game with ${esc(g.opponent)}"><div class="card-header">${avatarMarkup(g.opponent, g.opponentAvatar)}<div class="opponent-info"><strong><button class="opponent-name" data-opponent="${esc(g.opponentId)}">${esc(g.opponent)}</button> <small class="rating" aria-label="${g.opponentRating} Elo">${g.opponentRating}</small></strong>${g.status !== 'pending' ? materialBar(g) : ''}</div>${g.status !== 'pending' ? colorTagMarkup(g) : ''}${g.inactiveDays >= 7 ? '<button class="stop-inactive" data-game-action="stop-confirm" aria-label="Stop inactive game" title="Stop inactive game">×</button>' : ''}</div>${content}</article>`;
182
272
}
183
273
function materialBar (g)
184
274
{
@@ -230,10 +320,10 @@ function board (g)
230
320
const last = g.state.last && (i === g.state.last.from || i === g.state.last.to);
231
321
const checked = g.check && p.toLowerCase() === 'k' && (p === p.toUpperCase() ? 'w' : 'b') === g.state.turn;
232
322
const label = `${square}${p !== '.' ? ' ' + (p === p.toUpperCase() ? 'white ' : 'black ') + names[p.toLowerCase()] : ''}${legal.includes(i) ? ', legal destination' : ''}`;
233
html += `<button class="square ${(i % 4 + Math.floor(i / 4)) % 2 === 0 ? 'dark' : ''} ${active === i ? 'selected' : ''} ${legal.includes(i) ? 'legal' : ''} ${p !== '.' ? 'occupied' : ''} ${last ? 'last' : ''} ${checked ? 'checked' : ''}" data-square="${i}" aria-label="${label}" ${g.yourTurn ? '' : 'disabled'} ${active === i ? 'aria-pressed="true"' : ''}>${p !== '.' ? `<img src="${pieceUrl(p)}" alt="" draggable="false">` : ''}${view % 4 === 0 ? `<span class="coordinate rank">${5 - Math.floor(i / 4)}</span>` : ''}${view >= 16 ? `<span class="coordinate">${String.fromCharCode(97 + i % 4)}</span>` : ''}</button>`;
323
html += `<button class="square ${(i % 4 + Math.floor(i / 4)) % 2 === 0 ? 'dark' : ''} ${active === i ? 'selected' : ''} ${legal.includes(i) ? 'legal' : ''} ${p !== '.' ? 'occupied' : ''} ${last ? 'last' : ''} ${checked ? 'checked' : ''}" data-square="${i}" aria-label="${label}" ${g.yourTurn ? '' : 'disabled'} ${active === i ? 'aria-pressed="true"' : ''}>${p !== '.' ? `<img src="${pieceUrl(p, skinForPiece(g, p))}" alt="" draggable="false">` : ''}${view % 4 === 0 ? `<span class="coordinate rank">${5 - Math.floor(i / 4)}</span>` : ''}${view >= 16 ? `<span class="coordinate">${String.fromCharCode(97 + i % 4)}</span>` : ''}</button>`;
234
324
});
235
325
html += '</div>';
236
if (promotion?.game === g.id) html += `<div class="promotion" role="group" aria-label="Choose promotion"><span class="eyebrow">A NEW POSSIBILITY</span><h3>Promote your pawn</h3><p>Choose the piece for your next chapter.</p><div class="promotion-options">${['q', 'r', 'b', 'n'].map(p => `<button data-promotion="${p}"><img src="${pieceUrl(g.color === 'w' ? p.toUpperCase() : p)}" alt="">${names[p]}</button>`).join('')}</div><button class="text-button" data-cancel-promotion>Cancel</button></div>`;
326
if (promotion?.game === g.id) html += `<div class="promotion" role="group" aria-label="Choose promotion"><span class="eyebrow">A NEW POSSIBILITY</span><h3>Promote your pawn</h3><p>Choose the piece for your next chapter.</p><div class="promotion-options">${['q', 'r', 'b', 'n'].map(p => `<button data-promotion="${p}"><img src="${pieceUrl(g.color === 'w' ? p.toUpperCase() : p, displayColorFor(g))}" alt="">${names[p]}</button>`).join('')}</div><button class="text-button" data-cancel-promotion>Cancel</button></div>`;
237
327
return html + '</div>';
238
328
}
239
329
function renderFriends ()
@@ -243,7 +333,7 @@ function renderFriends ()
243
333
const incoming = state.friendRequests.filter(r => r.incoming);
244
334
$('#friend-requests').innerHTML = incoming.length ? '<div class="friends-label">PENDING REQUESTS</div>' + incoming.map(r => `<div class="friend-request">${avatarMarkup(r.name, r.avatar)}<div><strong>${esc(r.name)}</strong><div class="actions"><button class="primary" data-request-action="accept_friend_request" data-request-user="${esc(r.id)}">Accept</button><button class="secondary" data-request-action="reject_friend_request" data-request-user="${esc(r.id)}">Reject</button></div></div></div>`).join('') : '';
245
335
$('#friend-count').textContent = state.friends.length + incoming.length;
246
$('#account-summary').innerHTML = `${avatarMarkup(state.user.name, state.user.avatar, true)}<span>${esc(state.user.name)}<small>${state.user.rating} Elo</small></span><button id="history-button" class="text-button" aria-label="Game history" title="Game history">⌛</button>`;
336
$('#account-summary').innerHTML = `${avatarMarkup(state.user.name, state.user.avatar, true)}<button type="button" id="color-pref-button" class="account-name-button" title="Piece colours"><span>${esc(state.user.name)}</span><small>${state.user.rating} Elo</small></button><button id="history-button" class="text-button" aria-label="Game history" title="Game history">⌛</button>`;
247
337
}
248
338
function showRivalry (id)
249
339
{
@@ -302,7 +392,7 @@ function renderMatchmaking ()
302
392
async function createLink (kind) { await action({ action: 'create_link', kind }, r => { showModal(`<span class="eyebrow">${kind === 'friend' ? 'GOOD COMPANY' : 'GAME ON'}</span><h2>${kind === 'friend' ? 'Invite a friend.' : 'Send a little challenge.'}</h2><p>Share this link. ${kind === 'friend' ? 'You’ll become friends when the other person clicks accept.' : 'The first person to accept starts a game with you.'} It expires in one month.</p><input aria-label="Invitation link" id="share-url" readonly value="${esc(r.url)}"><div class="actions"><button class="primary" data-modal-action="copy">Copy link ↗</button></div>${kind === 'match' ? '<div id="matchmaking-actions" class="settings-actions"></div>' : ''}`); renderMatchmaking(); }); }
303
393
if ($('#match-link')) $('#match-link').onclick = () => createLink('match');
304
394
if ($('#friend-link')) $('#friend-link').onclick = () => createLink('friend');
305
if ($('#settings-button')) $('#settings-button').onclick = () => { if (!state) return; showModal(`<h2>Your account</h2><p>Signed in as ${esc(state.user.name)}.</p><p>${state.user.rating} Elo</p><div id="notification-settings"></div><div class="settings-actions"><button class="secondary" data-install-app>Add to home screen</button><p id="install-help" hidden></p>${state.local ? `<button class="secondary" data-modal-action="switch">Switch to ${state.user.name === 'test_user_1' ? 'test_user_2' : 'test_user_1'}</button>` : ''}<a class="button secondary" href="api.php?action=export" download>Export my data (JSON)</a><button class="secondary" data-modal-action="logout">Sign out</button></div>`); window.microchessPwa?.settings(); };
395
if ($('#settings-button')) $('#settings-button').onclick = () => { if (!state) return; showModal(`<h2>Your account</h2><p>Signed in as ${esc(state.user.name)}.</p><p>${state.user.rating} Elo</p><label class="settings-check"><input type="checkbox" id="disable-custom-colours" ${customColoursDisabled() ? 'checked' : ''}> Disable custom colours</label><div id="notification-settings"></div><div class="settings-actions"><button class="secondary" data-install-app>Add to home screen</button><p id="install-help" hidden></p>${state.local ? `<button class="secondary" data-modal-action="switch">Switch to ${state.user.name === 'test_user_1' ? 'test_user_2' : 'test_user_1'}</button>` : ''}<a class="button secondary" href="api.php?action=export" download>Export my data (JSON)</a><button class="secondary" data-modal-action="logout">Sign out</button></div>`); $('#disable-custom-colours').onchange = e => { setCustomColoursDisabled(e.target.checked); renderGames(); }; window.microchessPwa?.settings(); };
306
396
if ($('#rules-button')) $('#rules-button').onclick = () => showModal(`<span class="eyebrow">MICROCHESS</span><h2>Small board. Real chess.</h2><p>The usual rules of chess, on a 4 × 5 board.</p><ul class="rules-list"><li>Each side starts with a king, rook, bishop, knight and one pawn. White moves first.</li><li>Pawns move one square forward, capture diagonally and never move two squares. There is no castling or en passant.</li><li>Reach the last rank to promote to a queen, rook, bishop or knight.</li><li>Protect your king. Checkmate wins; stalemate and dead positions draw.</li><li>Claim a draw after three repetitions or 50 moves by each side without a pawn move or capture. You may also claim with an intended move, via the game menu. Five repetitions or 75 moves draw automatically.</li><li>Click a piece to see legal destinations, then click a dot. Or drag it to a destination.</li><li>The bar below your opponent’s name compares remaining material: White on the left, Black on the right. Pawn 1, knight/bishop 3, rook 5, queen 9; kings are not counted.</li><li>After your move, a blue pulse marks a clear estimated gain; red marks a likely material loss or mating threat. This quick tactical check can miss deeper ideas. Quiet or uncertain moves get no pulse.</li></ul><p class="inline-note">Pieces by Cburnett, from <a href="https://commons.wikimedia.org/wiki/Category:SVG_chess_pieces" target="_blank" rel="noreferrer">Wikimedia Commons</a>, <a href="https://creativecommons.org/licenses/by-sa/3.0/" target="_blank" rel="noreferrer">CC BY-SA 3.0</a>. Unmodified SVGs.</p>`);
307
397
document.addEventListener('click', e =>
308
398
{
@@ -312,6 +402,7 @@ document.addEventListener('click', e =>
312
402
if (el.dataset.matchmaking) action({ action: el.dataset.matchmaking }, () => { if (modal.open) closeModal(); });
313
403
if (el.id === 'history-button') showHistory();
314
404
if (el.id === 'avatar-button') chooseAvatar();
405
if (el.id === 'color-pref-button') openColorPreferences();
315
406
if (el.dataset.createLink) createLink(el.dataset.createLink);
316
407
if (el.hasAttribute('data-square') && g) { if (suppressClick) { suppressClick = false; return; } chooseSquare(g, Number(el.dataset.square)); }
317
408
if (el.dataset.gameAction && g) { if (el.dataset.gameAction === 'stop-confirm') { showModal(`<h2 id="modal-title">Stop this game?</h2><p>This game has been inactive for ${g.inactiveDays} days. Would you like to stop it?</p><div class="actions"><button class="danger" data-stop-game="${g.id}" data-version="${g.version}">Stop game</button><button class="secondary" data-modal-action="close">Cancel</button></div>`); } else if (el.dataset.gameAction === 'options') options(g); else action({ action: el.dataset.gameAction, game: g.id, version: g.version }); }
@@ -356,7 +447,7 @@ document.addEventListener('pointerdown', e =>
356
447
document.addEventListener('pointermove', e =>
357
448
{
358
449
if (!drag || e.pointerId !== drag.id) return;
359
if (!drag.moving && Math.hypot(e.clientX - drag.x, e.clientY - drag.y) > 7) { drag.moving = true; const g = state.games.find(g => g.id === drag.game); selected = { game: g.id, from: drag.from, version: g.version }; renderGames(); const img = document.createElement('img'); img.className = 'drag-ghost'; img.src = pieceUrl(drag.p); document.body.append(img); }
450
if (!drag.moving && Math.hypot(e.clientX - drag.x, e.clientY - drag.y) > 7) { drag.moving = true; const g = state.games.find(g => g.id === drag.game); selected = { game: g.id, from: drag.from, version: g.version }; renderGames(); const img = document.createElement('img'); img.className = 'drag-ghost'; img.src = pieceUrl(drag.p, skinForPiece(state?.games?.find(x => x.id === drag.game), drag.p)); document.body.append(img); }
360
451
if (drag.moving) { e.preventDefault(); const img = $('.drag-ghost'); img.style.left = e.clientX + 'px'; img.style.top = e.clientY + 'px'; }
361
452
}, { passive: false });
362
453
document.addEventListener('pointerup', e =>
@@ -418,7 +509,9 @@ function renderReplay ()
418
509
{
419
510
if (!replay || !$('#replay-card')) return;
420
511
const g = { ...replay, id: 'replay', replay: true, status: 'replay', yourTurn: false, legal: [], check: false, state: replay.positions[replay.index] };
421
$('#replay-card').innerHTML = `<article class="game-card" data-game="replay"><div class="card-header replay-players" id="modal-title"><span><img src="${pieceUrl('K')}" alt="White">${esc(replay.whiteName)}</span><span aria-hidden="true">–</span><span><img src="${pieceUrl('k')}" alt="Black">${esc(replay.blackName)}</span></div>${board(g)}</article>`;
512
const whiteTip = !customColoursDisabled() && (replay.pieceSkinWhite || 'White') !== 'White' ? `Playing as ${replay.pieceSkinWhite} (White)` : 'Playing as White';
513
const blackTip = !customColoursDisabled() && (replay.pieceSkinBlack || 'Black') !== 'Black' ? `Playing as ${replay.pieceSkinBlack} (Black)` : 'Playing as Black';
514
$('#replay-card').innerHTML = `<article class="game-card" data-game="replay"><div class="card-header replay-players" id="modal-title"><span title="${esc(whiteTip)}"><img src="${pieceUrl('K', replay.pieceSkinWhite || 'White')}" alt="${esc(replay.pieceSkinWhite || 'White')}">${esc(replay.whiteName)}</span><span aria-hidden="true">–</span><span title="${esc(blackTip)}"><img src="${pieceUrl('k', replay.pieceSkinBlack || 'Black')}" alt="${esc(replay.pieceSkinBlack || 'Black')}">${esc(replay.blackName)}</span></div>${board(g)}</article>`;
422
515
$('#replay-progress').textContent = `${replay.index} / ${replay.positions.length - 1} · ${replay.shared ? replay.outcome : replay.outcome === 'win' ? 'Won' : replay.outcome === 'loss' ? 'Lost' : 'Draw'} · ${replay.reason}`;
423
516
const last = replay.positions.length - 1;
424
517
$('[data-replay-control="play"]').textContent = replayTimer ? '⏸' : '▶';
@@ -3,7 +3,61 @@ const $ = (s, root = document) => root.querySelector(s);3
const esc = s => String(s ?? '').replace(/[&<>"']/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));3
const esc = s => String(s ?? '').replace(/[&<>"']/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));4
const names = { p: 'Pawn', r: 'Rook', n: 'Knight', b: 'Bishop', q: 'Queen', k: 'King' };4
const names = { p: 'Pawn', r: 'Rook', n: 'Knight', b: 'Bishop', q: 'Queen', k: 'King' };5
const materialValues = { p: 1, n: 3, b: 3, r: 5, q: 9, k: 0 };5
const materialValues = { p: 1, n: 3, b: 3, r: 5, q: 9, k: 0 };6
const pieceUrl = p => `assets/pieces/${p.toLowerCase()}${p === p.toUpperCase() ? 'l' : 'd'}t.svg`;6
const PIECE_COLOR_ORDER = ['White', 'Black', 'Red', 'Blue', 'Green', 'Yellow'];7
const CUSTOM_PIECE_SKINS = new Set(['Red', 'Blue', 'Green', 'Yellow']);8
const pieceFileNames = { k: 'king', q: 'queen', r: 'rook', b: 'bishop', n: 'knight', p: 'pawn' };9
const DISABLE_CUSTOM_COLOURS_KEY = 'microchess-disable-custom-colours';10
function customColoursDisabled ()11
{12
try { return localStorage.getItem(DISABLE_CUSTOM_COLOURS_KEY) !== '0'; } catch { return true; }13
}14
function setCustomColoursDisabled (disabled)15
{16
try { localStorage.setItem(DISABLE_CUSTOM_COLOURS_KEY, disabled ? '1' : '0'); } catch {}17
}18
const classicPieceUrl = p => `assets/pieces/${p.toLowerCase()}${p === p.toUpperCase() ? 'l' : 'd'}t.svg`;19
const pieceUrl = (p, skin) =>20
{21
if (!skin || customColoursDisabled() || !CUSTOM_PIECE_SKINS.has(skin)) return classicPieceUrl(p);22
return `assets/avatars/${skin.toLowerCase()}-${pieceFileNames[p.toLowerCase()]}.png`;23
};24
function skinForPiece (g, p)25
{26
if (!g || p === '.') return null;27
const whiteSkin = g.pieceSkinWhite || 'White';28
const blackSkin = g.pieceSkinBlack || 'Black';29
return p === p.toUpperCase() ? whiteSkin : blackSkin;30
}31
function displayColorFor (g)32
{33
if (!g) return 'White';34
if (customColoursDisabled()) return g.color === 'w' ? 'White' : 'Black';35
return g.displayColor || (g.color === 'w' ? (g.pieceSkinWhite || 'White') : (g.pieceSkinBlack || 'Black'));36
}37
function rulesColorLabel (g) { return g.color === 'w' ? 'White' : 'Black'; }38
function colorTagMarkup (g)39
{40
const display = displayColorFor(g);41
const rules = rulesColorLabel(g);42
const tip = !customColoursDisabled() && display !== rules ? `Playing as ${display} (${rules})` : `Playing as ${display}`;43
const disc = display.toLowerCase();44
return `<span class="color-tag" title="${esc(tip)}"><span class="color-disc ${esc(disc)}"></span>${esc(display)}</span>`;45
}46
function kingAvatarUrl (color)47
{48
return `assets/avatars/${color.toLowerCase()}-king.png`;49
}50
function nextColorSkipping (current, skip)51
{52
let i = PIECE_COLOR_ORDER.indexOf(current);53
if (i < 0) i = 0;54
for (let n = 0; n < PIECE_COLOR_ORDER.length; n++)55
{56
i = (i + 1) % PIECE_COLOR_ORDER.length;57
if (PIECE_COLOR_ORDER[i] !== skip) return PIECE_COLOR_ORDER[i];58
}59
return current;60
}7
const initials = name => esc(name.slice(0, 2).toUpperCase());61
const initials = name => esc(name.slice(0, 2).toUpperCase());8
const avatarUrl = id => `assets/avatars/${encodeURIComponent(id)}.png`;62
const avatarUrl = id => `assets/avatars/${encodeURIComponent(id)}.png`;9
function avatarMarkup (name, id, editable = false)63
function avatarMarkup (name, id, editable = false)@@ -33,6 +87,42 @@ function renderAvatarChoices ()33
$('#avatar-option-count').textContent = `${options.length} pieces`;87
$('#avatar-option-count').textContent = `${options.length} pieces`;34
document.querySelectorAll('[data-avatar-group]').forEach(b => b.setAttribute('aria-pressed', String(b.dataset.avatarGroup === avatarGroup)));88
document.querySelectorAll('[data-avatar-group]').forEach(b => b.setAttribute('aria-pressed', String(b.dataset.avatarGroup === avatarGroup)));35
}89
}90
91
function openColorPreferences ()92
{93
if (!state) return;94
const pref = {95
mode: state.user.colorMode === 'custom' ? 'custom' : 'default',96
preferred: state.user.preferredColor || 'White',97
alternative: state.user.alternativeColor || 'Black'98
};99
if (pref.preferred === pref.alternative) pref.alternative = nextColorSkipping(pref.alternative, pref.preferred);100
const paint = () =>101
{102
showModal(`<span class="eyebrow">YOUR SIDE</span><h2 id="modal-title">Piece colours</h2><p>Choose how your pieces look in new games. Opponents may use a different colour when both prefer the same one.</p><div class="color-mode-options" role="radiogroup" aria-label="Colour mode"><label class="color-mode-option"><input type="radio" name="color-mode" id="color-mode-default" value="default" ${pref.mode !== 'custom' ? 'checked' : ''}> <span><strong>Default Colours</strong><small>Play as White or Black by the rules side, as usual.</small></span></label><label class="color-mode-option"><input type="radio" name="color-mode" id="color-mode-custom" value="custom" ${pref.mode === 'custom' ? 'checked' : ''}> <span><strong>Custom Colour</strong><small>Pick a preferred colour and an alternative if both players clash.</small></span></label></div><div id="custom-color-pickers" class="custom-color-pickers"${pref.mode === 'custom' ? '' : ' hidden'}><button type="button" class="color-king-choice" data-color-role="preferred" aria-label="Preferred colour ${esc(pref.preferred)}"><img src="${kingAvatarUrl(pref.preferred)}" alt=""><span>Preferred</span><strong>${esc(pref.preferred)}</strong></button><button type="button" class="color-king-choice" data-color-role="alternative" aria-label="Alternative colour ${esc(pref.alternative)}"><img src="${kingAvatarUrl(pref.alternative)}" alt=""><span>Alternative</span><strong>${esc(pref.alternative)}</strong></button></div><div class="actions"><button class="primary" id="save-color-prefs">Save</button><button class="secondary" data-modal-action="close">Cancel</button></div>`);103
$('#color-mode-default').onchange = () => { pref.mode = 'default'; paint(); };104
$('#color-mode-custom').onchange = () => { pref.mode = 'custom'; paint(); };105
document.querySelectorAll('[data-color-role]').forEach(btn =>106
{107
btn.onclick = () =>108
{109
if (btn.dataset.colorRole === 'preferred') pref.preferred = nextColorSkipping(pref.preferred, pref.alternative);110
else pref.alternative = nextColorSkipping(pref.alternative, pref.preferred);111
paint();112
};113
});114
$('#save-color-prefs').onclick = async () =>115
{116
await action({ action: 'set_piece_colors', colorMode: pref.mode, preferredColor: pref.preferred, alternativeColor: pref.alternative }, () =>117
{118
closeModal();119
toast('Colour preference saved.');120
});121
};122
};123
paint();124
}125
36
let state, selected = null, promotion = null, busy = false, drag = null, lastRender = '', toastTimer, inviteShown = false;126
let state, selected = null, promotion = null, busy = false, drag = null, lastRender = '', toastTimer, inviteShown = false;37
const moveHolds = new Map();127
const moveHolds = new Map();38
const moveFeedback = new Map();128
const moveFeedback = new Map();@@ -178,7 +268,7 @@ function card (g)178
else if (g.status === 'pending') content = `<div class="pending-content"><span class="big-icon">♘</span><h3>${g.incoming ? 'A little challenge?' : 'Challenge sent.'}</h3><p>${g.incoming ? `${esc(g.opponent)} invited you to play.<br>Your board is waiting.` : `Waiting for ${esc(g.opponent)}<br>to accept your challenge.`}</p>${g.incoming ? `<div class="actions"><button class="primary" data-game-action="accept">Accept</button><button class="secondary" data-game-action="reject">Reject</button></div>` : '<span class="inline-note"></span>'}</div>`;268
else if (g.status === 'pending') content = `<div class="pending-content"><span class="big-icon">♘</span><h3>${g.incoming ? 'A little challenge?' : 'Challenge sent.'}</h3><p>${g.incoming ? `${esc(g.opponent)} invited you to play.<br>Your board is waiting.` : `Waiting for ${esc(g.opponent)}<br>to accept your challenge.`}</p>${g.incoming ? `<div class="actions"><button class="primary" data-game-action="accept">Accept</button><button class="secondary" data-game-action="reject">Reject</button></div>` : '<span class="inline-note"></span>'}</div>`;179
else if (g.status === 'ended') content = `<div class="ended-board">${board(g)}<div class="end-content"><div class="end-status"><h3>${g.outcome === 'win' ? 'You won!' : g.outcome === 'loss' ? 'You lost' : 'A game well matched.'}</h3><small>${esc(g.reason)}</small>${g.opponentRematch && g.canRematch ? `<small>${esc(g.opponent)} wants a rematch.</small>` : ''}</div><div class="actions">${g.canRematch ? `<button class="primary" data-game-action="rematch" ${g.rematch ? 'disabled' : ''}>${g.rematch ? 'Requested' : 'Rematch'}</button>` : ''}<button class="secondary" data-game-action="exit">Exit</button></div></div></div>`;269
else if (g.status === 'ended') content = `<div class="ended-board">${board(g)}<div class="end-content"><div class="end-status"><h3>${g.outcome === 'win' ? 'You won!' : g.outcome === 'loss' ? 'You lost' : 'A game well matched.'}</h3><small>${esc(g.reason)}</small>${g.opponentRematch && g.canRematch ? `<small>${esc(g.opponent)} wants a rematch.</small>` : ''}</div><div class="actions">${g.canRematch ? `<button class="primary" data-game-action="rematch" ${g.rematch ? 'disabled' : ''}>${g.rematch ? 'Requested' : 'Rematch'}</button>` : ''}<button class="secondary" data-game-action="exit">Exit</button></div></div></div>`;180
else content = board(g) + `<div class="card-footer"><span class="${g.yourTurn ? 'turn-label' : ''}">${g.check ? 'Check · ' : ''}${g.yourTurn ? 'Your move' : 'Waiting for a move'}</span>${g.yourTurn ? `<button class="text-button" data-game-action="options" aria-label="Game options">${g.drawOffer === 'opponent' ? 'Draw offered · ' : ''}•••</button>` : `<span>Move ${Math.floor(g.state.ply / 2) + 1}</span>`}</div>`;270
else content = board(g) + `<div class="card-footer"><span class="${g.yourTurn ? 'turn-label' : ''}">${g.check ? 'Check · ' : ''}${g.yourTurn ? 'Your move' : 'Waiting for a move'}</span>${g.yourTurn ? `<button class="text-button" data-game-action="options" aria-label="Game options">${g.drawOffer === 'opponent' ? 'Draw offered · ' : ''}•••</button>` : `<span>Move ${Math.floor(g.state.ply / 2) + 1}</span>`}</div>`;181
return `<article class="game-card ${!g.yourTurn && g.status === 'active' ? 'waiting' : ''}" data-game="${g.id}" aria-label="Game with ${esc(g.opponent)}"><div class="card-header">${avatarMarkup(g.opponent, g.opponentAvatar)}<div class="opponent-info"><strong><button class="opponent-name" data-opponent="${esc(g.opponentId)}">${esc(g.opponent)}</button> <small class="rating" aria-label="${g.opponentRating} Elo">${g.opponentRating}</small></strong>${g.status !== 'pending' ? materialBar(g) : ''}</div>${g.status !== 'pending' ? `<span class="color-tag"><span class="color-disc ${g.color === 'b' ? 'black' : ''}"></span>${g.color === 'w' ? 'White' : 'Black'}</span>` : ''}${g.inactiveDays >= 7 ? '<button class="stop-inactive" data-game-action="stop-confirm" aria-label="Stop inactive game" title="Stop inactive game">×</button>' : ''}</div>${content}</article>`;271
return `<article class="game-card ${!g.yourTurn && g.status === 'active' ? 'waiting' : ''}" data-game="${g.id}" aria-label="Game with ${esc(g.opponent)}"><div class="card-header">${avatarMarkup(g.opponent, g.opponentAvatar)}<div class="opponent-info"><strong><button class="opponent-name" data-opponent="${esc(g.opponentId)}">${esc(g.opponent)}</button> <small class="rating" aria-label="${g.opponentRating} Elo">${g.opponentRating}</small></strong>${g.status !== 'pending' ? materialBar(g) : ''}</div>${g.status !== 'pending' ? colorTagMarkup(g) : ''}${g.inactiveDays >= 7 ? '<button class="stop-inactive" data-game-action="stop-confirm" aria-label="Stop inactive game" title="Stop inactive game">×</button>' : ''}</div>${content}</article>`;182
}272
}183
function materialBar (g)273
function materialBar (g)184
{274
{@@ -230,10 +320,10 @@ function board (g)230
const last = g.state.last && (i === g.state.last.from || i === g.state.last.to);320
const last = g.state.last && (i === g.state.last.from || i === g.state.last.to);231
const checked = g.check && p.toLowerCase() === 'k' && (p === p.toUpperCase() ? 'w' : 'b') === g.state.turn;321
const checked = g.check && p.toLowerCase() === 'k' && (p === p.toUpperCase() ? 'w' : 'b') === g.state.turn;232
const label = `${square}${p !== '.' ? ' ' + (p === p.toUpperCase() ? 'white ' : 'black ') + names[p.toLowerCase()] : ''}${legal.includes(i) ? ', legal destination' : ''}`;322
const label = `${square}${p !== '.' ? ' ' + (p === p.toUpperCase() ? 'white ' : 'black ') + names[p.toLowerCase()] : ''}${legal.includes(i) ? ', legal destination' : ''}`;233
html += `<button class="square ${(i % 4 + Math.floor(i / 4)) % 2 === 0 ? 'dark' : ''} ${active === i ? 'selected' : ''} ${legal.includes(i) ? 'legal' : ''} ${p !== '.' ? 'occupied' : ''} ${last ? 'last' : ''} ${checked ? 'checked' : ''}" data-square="${i}" aria-label="${label}" ${g.yourTurn ? '' : 'disabled'} ${active === i ? 'aria-pressed="true"' : ''}>${p !== '.' ? `<img src="${pieceUrl(p)}" alt="" draggable="false">` : ''}${view % 4 === 0 ? `<span class="coordinate rank">${5 - Math.floor(i / 4)}</span>` : ''}${view >= 16 ? `<span class="coordinate">${String.fromCharCode(97 + i % 4)}</span>` : ''}</button>`;323
html += `<button class="square ${(i % 4 + Math.floor(i / 4)) % 2 === 0 ? 'dark' : ''} ${active === i ? 'selected' : ''} ${legal.includes(i) ? 'legal' : ''} ${p !== '.' ? 'occupied' : ''} ${last ? 'last' : ''} ${checked ? 'checked' : ''}" data-square="${i}" aria-label="${label}" ${g.yourTurn ? '' : 'disabled'} ${active === i ? 'aria-pressed="true"' : ''}>${p !== '.' ? `<img src="${pieceUrl(p, skinForPiece(g, p))}" alt="" draggable="false">` : ''}${view % 4 === 0 ? `<span class="coordinate rank">${5 - Math.floor(i / 4)}</span>` : ''}${view >= 16 ? `<span class="coordinate">${String.fromCharCode(97 + i % 4)}</span>` : ''}</button>`;234
});324
});235
html += '</div>';325
html += '</div>';236
if (promotion?.game === g.id) html += `<div class="promotion" role="group" aria-label="Choose promotion"><span class="eyebrow">A NEW POSSIBILITY</span><h3>Promote your pawn</h3><p>Choose the piece for your next chapter.</p><div class="promotion-options">${['q', 'r', 'b', 'n'].map(p => `<button data-promotion="${p}"><img src="${pieceUrl(g.color === 'w' ? p.toUpperCase() : p)}" alt="">${names[p]}</button>`).join('')}</div><button class="text-button" data-cancel-promotion>Cancel</button></div>`;326
if (promotion?.game === g.id) html += `<div class="promotion" role="group" aria-label="Choose promotion"><span class="eyebrow">A NEW POSSIBILITY</span><h3>Promote your pawn</h3><p>Choose the piece for your next chapter.</p><div class="promotion-options">${['q', 'r', 'b', 'n'].map(p => `<button data-promotion="${p}"><img src="${pieceUrl(g.color === 'w' ? p.toUpperCase() : p, displayColorFor(g))}" alt="">${names[p]}</button>`).join('')}</div><button class="text-button" data-cancel-promotion>Cancel</button></div>`;237
return html + '</div>';327
return html + '</div>';238
}328
}239
function renderFriends ()329
function renderFriends ()@@ -243,7 +333,7 @@ function renderFriends ()243
const incoming = state.friendRequests.filter(r => r.incoming);333
const incoming = state.friendRequests.filter(r => r.incoming);244
$('#friend-requests').innerHTML = incoming.length ? '<div class="friends-label">PENDING REQUESTS</div>' + incoming.map(r => `<div class="friend-request">${avatarMarkup(r.name, r.avatar)}<div><strong>${esc(r.name)}</strong><div class="actions"><button class="primary" data-request-action="accept_friend_request" data-request-user="${esc(r.id)}">Accept</button><button class="secondary" data-request-action="reject_friend_request" data-request-user="${esc(r.id)}">Reject</button></div></div></div>`).join('') : '';334
$('#friend-requests').innerHTML = incoming.length ? '<div class="friends-label">PENDING REQUESTS</div>' + incoming.map(r => `<div class="friend-request">${avatarMarkup(r.name, r.avatar)}<div><strong>${esc(r.name)}</strong><div class="actions"><button class="primary" data-request-action="accept_friend_request" data-request-user="${esc(r.id)}">Accept</button><button class="secondary" data-request-action="reject_friend_request" data-request-user="${esc(r.id)}">Reject</button></div></div></div>`).join('') : '';245
$('#friend-count').textContent = state.friends.length + incoming.length;335
$('#friend-count').textContent = state.friends.length + incoming.length;246
$('#account-summary').innerHTML = `${avatarMarkup(state.user.name, state.user.avatar, true)}<span>${esc(state.user.name)}<small>${state.user.rating} Elo</small></span><button id="history-button" class="text-button" aria-label="Game history" title="Game history">⌛</button>`;336
$('#account-summary').innerHTML = `${avatarMarkup(state.user.name, state.user.avatar, true)}<button type="button" id="color-pref-button" class="account-name-button" title="Piece colours"><span>${esc(state.user.name)}</span><small>${state.user.rating} Elo</small></button><button id="history-button" class="text-button" aria-label="Game history" title="Game history">⌛</button>`;247
}337
}248
function showRivalry (id)338
function showRivalry (id)249
{339
{@@ -302,7 +392,7 @@ function renderMatchmaking ()302
async function createLink (kind) { await action({ action: 'create_link', kind }, r => { showModal(`<span class="eyebrow">${kind === 'friend' ? 'GOOD COMPANY' : 'GAME ON'}</span><h2>${kind === 'friend' ? 'Invite a friend.' : 'Send a little challenge.'}</h2><p>Share this link. ${kind === 'friend' ? 'You’ll become friends when the other person clicks accept.' : 'The first person to accept starts a game with you.'} It expires in one month.</p><input aria-label="Invitation link" id="share-url" readonly value="${esc(r.url)}"><div class="actions"><button class="primary" data-modal-action="copy">Copy link ↗</button></div>${kind === 'match' ? '<div id="matchmaking-actions" class="settings-actions"></div>' : ''}`); renderMatchmaking(); }); }392
async function createLink (kind) { await action({ action: 'create_link', kind }, r => { showModal(`<span class="eyebrow">${kind === 'friend' ? 'GOOD COMPANY' : 'GAME ON'}</span><h2>${kind === 'friend' ? 'Invite a friend.' : 'Send a little challenge.'}</h2><p>Share this link. ${kind === 'friend' ? 'You’ll become friends when the other person clicks accept.' : 'The first person to accept starts a game with you.'} It expires in one month.</p><input aria-label="Invitation link" id="share-url" readonly value="${esc(r.url)}"><div class="actions"><button class="primary" data-modal-action="copy">Copy link ↗</button></div>${kind === 'match' ? '<div id="matchmaking-actions" class="settings-actions"></div>' : ''}`); renderMatchmaking(); }); }303
if ($('#match-link')) $('#match-link').onclick = () => createLink('match');393
if ($('#match-link')) $('#match-link').onclick = () => createLink('match');304
if ($('#friend-link')) $('#friend-link').onclick = () => createLink('friend');394
if ($('#friend-link')) $('#friend-link').onclick = () => createLink('friend');305
if ($('#settings-button')) $('#settings-button').onclick = () => { if (!state) return; showModal(`<h2>Your account</h2><p>Signed in as ${esc(state.user.name)}.</p><p>${state.user.rating} Elo</p><div id="notification-settings"></div><div class="settings-actions"><button class="secondary" data-install-app>Add to home screen</button><p id="install-help" hidden></p>${state.local ? `<button class="secondary" data-modal-action="switch">Switch to ${state.user.name === 'test_user_1' ? 'test_user_2' : 'test_user_1'}</button>` : ''}<a class="button secondary" href="api.php?action=export" download>Export my data (JSON)</a><button class="secondary" data-modal-action="logout">Sign out</button></div>`); window.microchessPwa?.settings(); };395
if ($('#settings-button')) $('#settings-button').onclick = () => { if (!state) return; showModal(`<h2>Your account</h2><p>Signed in as ${esc(state.user.name)}.</p><p>${state.user.rating} Elo</p><label class="settings-check"><input type="checkbox" id="disable-custom-colours" ${customColoursDisabled() ? 'checked' : ''}> Disable custom colours</label><div id="notification-settings"></div><div class="settings-actions"><button class="secondary" data-install-app>Add to home screen</button><p id="install-help" hidden></p>${state.local ? `<button class="secondary" data-modal-action="switch">Switch to ${state.user.name === 'test_user_1' ? 'test_user_2' : 'test_user_1'}</button>` : ''}<a class="button secondary" href="api.php?action=export" download>Export my data (JSON)</a><button class="secondary" data-modal-action="logout">Sign out</button></div>`); $('#disable-custom-colours').onchange = e => { setCustomColoursDisabled(e.target.checked); renderGames(); }; window.microchessPwa?.settings(); };306
if ($('#rules-button')) $('#rules-button').onclick = () => showModal(`<span class="eyebrow">MICROCHESS</span><h2>Small board. Real chess.</h2><p>The usual rules of chess, on a 4 × 5 board.</p><ul class="rules-list"><li>Each side starts with a king, rook, bishop, knight and one pawn. White moves first.</li><li>Pawns move one square forward, capture diagonally and never move two squares. There is no castling or en passant.</li><li>Reach the last rank to promote to a queen, rook, bishop or knight.</li><li>Protect your king. Checkmate wins; stalemate and dead positions draw.</li><li>Claim a draw after three repetitions or 50 moves by each side without a pawn move or capture. You may also claim with an intended move, via the game menu. Five repetitions or 75 moves draw automatically.</li><li>Click a piece to see legal destinations, then click a dot. Or drag it to a destination.</li><li>The bar below your opponent’s name compares remaining material: White on the left, Black on the right. Pawn 1, knight/bishop 3, rook 5, queen 9; kings are not counted.</li><li>After your move, a blue pulse marks a clear estimated gain; red marks a likely material loss or mating threat. This quick tactical check can miss deeper ideas. Quiet or uncertain moves get no pulse.</li></ul><p class="inline-note">Pieces by Cburnett, from <a href="https://commons.wikimedia.org/wiki/Category:SVG_chess_pieces" target="_blank" rel="noreferrer">Wikimedia Commons</a>, <a href="https://creativecommons.org/licenses/by-sa/3.0/" target="_blank" rel="noreferrer">CC BY-SA 3.0</a>. Unmodified SVGs.</p>`);396
if ($('#rules-button')) $('#rules-button').onclick = () => showModal(`<span class="eyebrow">MICROCHESS</span><h2>Small board. Real chess.</h2><p>The usual rules of chess, on a 4 × 5 board.</p><ul class="rules-list"><li>Each side starts with a king, rook, bishop, knight and one pawn. White moves first.</li><li>Pawns move one square forward, capture diagonally and never move two squares. There is no castling or en passant.</li><li>Reach the last rank to promote to a queen, rook, bishop or knight.</li><li>Protect your king. Checkmate wins; stalemate and dead positions draw.</li><li>Claim a draw after three repetitions or 50 moves by each side without a pawn move or capture. You may also claim with an intended move, via the game menu. Five repetitions or 75 moves draw automatically.</li><li>Click a piece to see legal destinations, then click a dot. Or drag it to a destination.</li><li>The bar below your opponent’s name compares remaining material: White on the left, Black on the right. Pawn 1, knight/bishop 3, rook 5, queen 9; kings are not counted.</li><li>After your move, a blue pulse marks a clear estimated gain; red marks a likely material loss or mating threat. This quick tactical check can miss deeper ideas. Quiet or uncertain moves get no pulse.</li></ul><p class="inline-note">Pieces by Cburnett, from <a href="https://commons.wikimedia.org/wiki/Category:SVG_chess_pieces" target="_blank" rel="noreferrer">Wikimedia Commons</a>, <a href="https://creativecommons.org/licenses/by-sa/3.0/" target="_blank" rel="noreferrer">CC BY-SA 3.0</a>. Unmodified SVGs.</p>`);307
document.addEventListener('click', e =>397
document.addEventListener('click', e =>308
{398
{@@ -312,6 +402,7 @@ document.addEventListener('click', e =>312
if (el.dataset.matchmaking) action({ action: el.dataset.matchmaking }, () => { if (modal.open) closeModal(); });402
if (el.dataset.matchmaking) action({ action: el.dataset.matchmaking }, () => { if (modal.open) closeModal(); });313
if (el.id === 'history-button') showHistory();403
if (el.id === 'history-button') showHistory();314
if (el.id === 'avatar-button') chooseAvatar();404
if (el.id === 'avatar-button') chooseAvatar();405
if (el.id === 'color-pref-button') openColorPreferences();315
if (el.dataset.createLink) createLink(el.dataset.createLink);406
if (el.dataset.createLink) createLink(el.dataset.createLink);316
if (el.hasAttribute('data-square') && g) { if (suppressClick) { suppressClick = false; return; } chooseSquare(g, Number(el.dataset.square)); }407
if (el.hasAttribute('data-square') && g) { if (suppressClick) { suppressClick = false; return; } chooseSquare(g, Number(el.dataset.square)); }317
if (el.dataset.gameAction && g) { if (el.dataset.gameAction === 'stop-confirm') { showModal(`<h2 id="modal-title">Stop this game?</h2><p>This game has been inactive for ${g.inactiveDays} days. Would you like to stop it?</p><div class="actions"><button class="danger" data-stop-game="${g.id}" data-version="${g.version}">Stop game</button><button class="secondary" data-modal-action="close">Cancel</button></div>`); } else if (el.dataset.gameAction === 'options') options(g); else action({ action: el.dataset.gameAction, game: g.id, version: g.version }); }408
if (el.dataset.gameAction && g) { if (el.dataset.gameAction === 'stop-confirm') { showModal(`<h2 id="modal-title">Stop this game?</h2><p>This game has been inactive for ${g.inactiveDays} days. Would you like to stop it?</p><div class="actions"><button class="danger" data-stop-game="${g.id}" data-version="${g.version}">Stop game</button><button class="secondary" data-modal-action="close">Cancel</button></div>`); } else if (el.dataset.gameAction === 'options') options(g); else action({ action: el.dataset.gameAction, game: g.id, version: g.version }); }@@ -356,7 +447,7 @@ document.addEventListener('pointerdown', e =>356
document.addEventListener('pointermove', e =>447
document.addEventListener('pointermove', e =>357
{448
{358
if (!drag || e.pointerId !== drag.id) return;449
if (!drag || e.pointerId !== drag.id) return;359
if (!drag.moving && Math.hypot(e.clientX - drag.x, e.clientY - drag.y) > 7) { drag.moving = true; const g = state.games.find(g => g.id === drag.game); selected = { game: g.id, from: drag.from, version: g.version }; renderGames(); const img = document.createElement('img'); img.className = 'drag-ghost'; img.src = pieceUrl(drag.p); document.body.append(img); }450
if (!drag.moving && Math.hypot(e.clientX - drag.x, e.clientY - drag.y) > 7) { drag.moving = true; const g = state.games.find(g => g.id === drag.game); selected = { game: g.id, from: drag.from, version: g.version }; renderGames(); const img = document.createElement('img'); img.className = 'drag-ghost'; img.src = pieceUrl(drag.p, skinForPiece(state?.games?.find(x => x.id === drag.game), drag.p)); document.body.append(img); }360
if (drag.moving) { e.preventDefault(); const img = $('.drag-ghost'); img.style.left = e.clientX + 'px'; img.style.top = e.clientY + 'px'; }451
if (drag.moving) { e.preventDefault(); const img = $('.drag-ghost'); img.style.left = e.clientX + 'px'; img.style.top = e.clientY + 'px'; }361
}, { passive: false });452
}, { passive: false });362
document.addEventListener('pointerup', e =>453
document.addEventListener('pointerup', e =>@@ -418,7 +509,9 @@ function renderReplay ()418
{509
{419
if (!replay || !$('#replay-card')) return;510
if (!replay || !$('#replay-card')) return;420
const g = { ...replay, id: 'replay', replay: true, status: 'replay', yourTurn: false, legal: [], check: false, state: replay.positions[replay.index] };511
const g = { ...replay, id: 'replay', replay: true, status: 'replay', yourTurn: false, legal: [], check: false, state: replay.positions[replay.index] };421
$('#replay-card').innerHTML = `<article class="game-card" data-game="replay"><div class="card-header replay-players" id="modal-title"><span><img src="${pieceUrl('K')}" alt="White">${esc(replay.whiteName)}</span><span aria-hidden="true">–</span><span><img src="${pieceUrl('k')}" alt="Black">${esc(replay.blackName)}</span></div>${board(g)}</article>`;512
const whiteTip = !customColoursDisabled() && (replay.pieceSkinWhite || 'White') !== 'White' ? `Playing as ${replay.pieceSkinWhite} (White)` : 'Playing as White';513
const blackTip = !customColoursDisabled() && (replay.pieceSkinBlack || 'Black') !== 'Black' ? `Playing as ${replay.pieceSkinBlack} (Black)` : 'Playing as Black';514
$('#replay-card').innerHTML = `<article class="game-card" data-game="replay"><div class="card-header replay-players" id="modal-title"><span title="${esc(whiteTip)}"><img src="${pieceUrl('K', replay.pieceSkinWhite || 'White')}" alt="${esc(replay.pieceSkinWhite || 'White')}">${esc(replay.whiteName)}</span><span aria-hidden="true">–</span><span title="${esc(blackTip)}"><img src="${pieceUrl('k', replay.pieceSkinBlack || 'Black')}" alt="${esc(replay.pieceSkinBlack || 'Black')}">${esc(replay.blackName)}</span></div>${board(g)}</article>`;422
$('#replay-progress').textContent = `${replay.index} / ${replay.positions.length - 1} · ${replay.shared ? replay.outcome : replay.outcome === 'win' ? 'Won' : replay.outcome === 'loss' ? 'Lost' : 'Draw'} · ${replay.reason}`;515
$('#replay-progress').textContent = `${replay.index} / ${replay.positions.length - 1} · ${replay.shared ? replay.outcome : replay.outcome === 'win' ? 'Won' : replay.outcome === 'loss' ? 'Lost' : 'Draw'} · ${replay.reason}`;423
const last = replay.positions.length - 1;516
const last = replay.positions.length - 1;424
$('[data-replay-control="play"]').textContent = replayTimer ? '⏸' : '▶';517
$('[data-replay-control="play"]').textContent = replayTimer ? '⏸' : '▶';@@ -1,9 +1,45 @@
1
1
# Avatar piece credits
2
2
3
Selected pieces from [Fairy](https://commons.wikimedia.org/wiki/Category:SVG_chess_pieces/Fairy) and [Colored](https://commons.wikimedia.org/wiki/Category:SVG_chess_pieces/Colored), checked September 10, 2026. The avatar catalog contains only the retained files, with one selectable entry per piece regardless of PNG/SVG format.
3
Selected pieces from [Fairy](https://commons.wikimedia.org/wiki/Category:SVG_chess_pieces/Fairy) and [Colored](https://commons.wikimedia.org/wiki/Category:SVG_chess_pieces/Colored), checked September 10, 2026. The avatar catalog contains 103 selected avatars (36 standard including White and Black, 67 fairy), with one selectable entry per piece regardless of PNG/SVG format. White/Black standard pieces are local PNG renders of the Cburnett board SVGs.
4
4
5
5
PNG previews are unmodified Wikimedia renders or 120-pixel renders of unchanged original SVGs using librsvg. Available original SVG files are included alongside them. Retained avatars keep their existing IDs.
6
6
7
- [Black bishop](https://commons.wikimedia.org/wiki/File:Chess_bdt45.svg) — Original work by C. Burnett (2006)
8
9
(https://en.wikipedia.org/wiki/User:Cburnett). [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0). Local file: `black-bishop.png`. PNG rendered locally from the board SVG with librsvg.
10
- [Black king](https://commons.wikimedia.org/wiki/File:Chess_kdt45.svg) — Original work by C. Burnett (2006)
11
12
(https://en.wikipedia.org/wiki/User:Cburnett). [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0). Local file: `black-king.png`. PNG rendered locally from the board SVG with librsvg.
13
- [Black knight](https://commons.wikimedia.org/wiki/File:Chess_ndt45.svg) — Original work by C. Burnett (2006)
14
15
(https://en.wikipedia.org/wiki/User:Cburnett). [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0). Local file: `black-knight.png`. PNG rendered locally from the board SVG with librsvg.
16
- [Black pawn](https://commons.wikimedia.org/wiki/File:Chess_pdt45.svg) — Original work by C. Burnett (2006)
17
18
(https://en.wikipedia.org/wiki/User:Cburnett). [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0). Local file: `black-pawn.png`. PNG rendered locally from the board SVG with librsvg.
19
- [Black queen](https://commons.wikimedia.org/wiki/File:Chess_qdt45.svg) — Original work by C. Burnett (2006)
20
21
(https://en.wikipedia.org/wiki/User:Cburnett). [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0). Local file: `black-queen.png`. PNG rendered locally from the board SVG with librsvg.
22
- [Black rook](https://commons.wikimedia.org/wiki/File:Chess_rdt45.svg) — Original work by C. Burnett (2006)
23
24
(https://en.wikipedia.org/wiki/User:Cburnett). [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0). Local file: `black-rook.png`. PNG rendered locally from the board SVG with librsvg.
25
- [White bishop](https://commons.wikimedia.org/wiki/File:Chess_blt45.svg) — Original work by C. Burnett (2006)
26
27
(https://en.wikipedia.org/wiki/User:Cburnett). [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0). Local file: `white-bishop.png`. PNG rendered locally from the board SVG with librsvg.
28
- [White king](https://commons.wikimedia.org/wiki/File:Chess_klt45.svg) — Original work by C. Burnett (2006)
29
30
(https://en.wikipedia.org/wiki/User:Cburnett). [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0). Local file: `white-king.png`. PNG rendered locally from the board SVG with librsvg.
31
- [White knight](https://commons.wikimedia.org/wiki/File:Chess_nlt45.svg) — Original work by C. Burnett (2006)
32
33
(https://en.wikipedia.org/wiki/User:Cburnett). [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0). Local file: `white-knight.png`. PNG rendered locally from the board SVG with librsvg.
34
- [White pawn](https://commons.wikimedia.org/wiki/File:Chess_plt45.svg) — Original work by C. Burnett (2006)
35
36
(https://en.wikipedia.org/wiki/User:Cburnett). [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0). Local file: `white-pawn.png`. PNG rendered locally from the board SVG with librsvg.
37
- [White queen](https://commons.wikimedia.org/wiki/File:Chess_qlt45.svg) — Original work by C. Burnett (2006)
38
39
(https://en.wikipedia.org/wiki/User:Cburnett). [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0). Local file: `white-queen.png`. PNG rendered locally from the board SVG with librsvg.
40
- [White rook](https://commons.wikimedia.org/wiki/File:Chess_rlt45.svg) — Original work by C. Burnett (2006)
41
42
(https://en.wikipedia.org/wiki/User:Cburnett). [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0). Local file: `white-rook.png`. PNG rendered locally from the board SVG with librsvg.
7
43
- [Blue bishop](https://commons.wikimedia.org/wiki/File:Blue_bishop.svg) — Original work by C. Burnett (2006)
8
44
9
45
(https://en.wikipedia.org/wiki/User:Cburnett). [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0). Local file: `blue-bishop.png`.
@@ -1,9 +1,45 @@1
# Avatar piece credits1
# Avatar piece credits2
2
3
Selected pieces from [Fairy](https://commons.wikimedia.org/wiki/Category:SVG_chess_pieces/Fairy) and [Colored](https://commons.wikimedia.org/wiki/Category:SVG_chess_pieces/Colored), checked September 10, 2026. The avatar catalog contains only the retained files, with one selectable entry per piece regardless of PNG/SVG format.3
Selected pieces from [Fairy](https://commons.wikimedia.org/wiki/Category:SVG_chess_pieces/Fairy) and [Colored](https://commons.wikimedia.org/wiki/Category:SVG_chess_pieces/Colored), checked September 10, 2026. The avatar catalog contains 103 selected avatars (36 standard including White and Black, 67 fairy), with one selectable entry per piece regardless of PNG/SVG format. White/Black standard pieces are local PNG renders of the Cburnett board SVGs.4
4
5
PNG previews are unmodified Wikimedia renders or 120-pixel renders of unchanged original SVGs using librsvg. Available original SVG files are included alongside them. Retained avatars keep their existing IDs.5
PNG previews are unmodified Wikimedia renders or 120-pixel renders of unchanged original SVGs using librsvg. Available original SVG files are included alongside them. Retained avatars keep their existing IDs.6
6
7
- [Black bishop](https://commons.wikimedia.org/wiki/File:Chess_bdt45.svg) — Original work by C. Burnett (2006)8
9
(https://en.wikipedia.org/wiki/User:Cburnett). [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0). Local file: `black-bishop.png`. PNG rendered locally from the board SVG with librsvg.10
- [Black king](https://commons.wikimedia.org/wiki/File:Chess_kdt45.svg) — Original work by C. Burnett (2006)11
12
(https://en.wikipedia.org/wiki/User:Cburnett). [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0). Local file: `black-king.png`. PNG rendered locally from the board SVG with librsvg.13
- [Black knight](https://commons.wikimedia.org/wiki/File:Chess_ndt45.svg) — Original work by C. Burnett (2006)14
15
(https://en.wikipedia.org/wiki/User:Cburnett). [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0). Local file: `black-knight.png`. PNG rendered locally from the board SVG with librsvg.16
- [Black pawn](https://commons.wikimedia.org/wiki/File:Chess_pdt45.svg) — Original work by C. Burnett (2006)17
18
(https://en.wikipedia.org/wiki/User:Cburnett). [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0). Local file: `black-pawn.png`. PNG rendered locally from the board SVG with librsvg.19
- [Black queen](https://commons.wikimedia.org/wiki/File:Chess_qdt45.svg) — Original work by C. Burnett (2006)20
21
(https://en.wikipedia.org/wiki/User:Cburnett). [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0). Local file: `black-queen.png`. PNG rendered locally from the board SVG with librsvg.22
- [Black rook](https://commons.wikimedia.org/wiki/File:Chess_rdt45.svg) — Original work by C. Burnett (2006)23
24
(https://en.wikipedia.org/wiki/User:Cburnett). [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0). Local file: `black-rook.png`. PNG rendered locally from the board SVG with librsvg.25
- [White bishop](https://commons.wikimedia.org/wiki/File:Chess_blt45.svg) — Original work by C. Burnett (2006)26
27
(https://en.wikipedia.org/wiki/User:Cburnett). [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0). Local file: `white-bishop.png`. PNG rendered locally from the board SVG with librsvg.28
- [White king](https://commons.wikimedia.org/wiki/File:Chess_klt45.svg) — Original work by C. Burnett (2006)29
30
(https://en.wikipedia.org/wiki/User:Cburnett). [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0). Local file: `white-king.png`. PNG rendered locally from the board SVG with librsvg.31
- [White knight](https://commons.wikimedia.org/wiki/File:Chess_nlt45.svg) — Original work by C. Burnett (2006)32
33
(https://en.wikipedia.org/wiki/User:Cburnett). [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0). Local file: `white-knight.png`. PNG rendered locally from the board SVG with librsvg.34
- [White pawn](https://commons.wikimedia.org/wiki/File:Chess_plt45.svg) — Original work by C. Burnett (2006)35
36
(https://en.wikipedia.org/wiki/User:Cburnett). [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0). Local file: `white-pawn.png`. PNG rendered locally from the board SVG with librsvg.37
- [White queen](https://commons.wikimedia.org/wiki/File:Chess_qlt45.svg) — Original work by C. Burnett (2006)38
39
(https://en.wikipedia.org/wiki/User:Cburnett). [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0). Local file: `white-queen.png`. PNG rendered locally from the board SVG with librsvg.40
- [White rook](https://commons.wikimedia.org/wiki/File:Chess_rlt45.svg) — Original work by C. Burnett (2006)41
42
(https://en.wikipedia.org/wiki/User:Cburnett). [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0). Local file: `white-rook.png`. PNG rendered locally from the board SVG with librsvg.7
- [Blue bishop](https://commons.wikimedia.org/wiki/File:Blue_bishop.svg) — Original work by C. Burnett (2006)43
- [Blue bishop](https://commons.wikimedia.org/wiki/File:Blue_bishop.svg) — Original work by C. Burnett (2006)8
44
9
(https://en.wikipedia.org/wiki/User:Cburnett). [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0). Local file: `blue-bishop.png`.45
(https://en.wikipedia.org/wiki/User:Cburnett). [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0). Local file: `blue-bishop.png`.The contents of this binary file are not shown.
@@ -0,0 +1,12 @@
1
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
3
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="45" height="45">
4
<g style="opacity:1; fill:none; fill-rule:evenodd; fill-opacity:1; stroke:#000000; stroke-width:1.5; stroke-linecap:round; stroke-linejoin:round; stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;" transform="translate(0,0.6)">
5
<g style="fill:#000000; stroke:#000000; stroke-linecap:butt;">
6
<path d="M 9,36 C 12.39,35.03 19.11,36.43 22.5,34 C 25.89,36.43 32.61,35.03 36,36 C 36,36 37.65,36.54 39,38 C 38.32,38.97 37.35,38.99 36,38.5 C 32.61,37.53 25.89,38.96 22.5,37.5 C 19.11,38.96 12.39,37.53 9,38.5 C 7.65,38.99 6.68,38.97 6,38 C 7.35,36.54 9,36 9,36 z"/>
7
<path d="M 15,32 C 17.5,34.5 27.5,34.5 30,32 C 30.5,30.5 30,30 30,30 C 30,27.5 27.5,26 27.5,26 C 33,24.5 33.5,14.5 22.5,10.5 C 11.5,14.5 12,24.5 17.5,26 C 17.5,26 15,27.5 15,30 C 15,30 14.5,30.5 15,32 z"/>
8
<path d="M 25 8 A 2.5 2.5 0 1 1 20,8 A 2.5 2.5 0 1 1 25 8 z"/>
9
</g>
10
<path d="M 17.5,26 L 27.5,26 M 15,30 L 30,30 M 22.5,15.5 L 22.5,20.5 M 20,18 L 25,18" style="fill:none; stroke:#ffffff; stroke-linejoin:miter;"/>
11
</g>
12
</svg>
@@ -0,0 +1,12 @@1
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
3
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="45" height="45">
4
<g style="opacity:1; fill:none; fill-rule:evenodd; fill-opacity:1; stroke:#000000; stroke-width:1.5; stroke-linecap:round; stroke-linejoin:round; stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;" transform="translate(0,0.6)">
5
<g style="fill:#000000; stroke:#000000; stroke-linecap:butt;">
6
<path d="M 9,36 C 12.39,35.03 19.11,36.43 22.5,34 C 25.89,36.43 32.61,35.03 36,36 C 36,36 37.65,36.54 39,38 C 38.32,38.97 37.35,38.99 36,38.5 C 32.61,37.53 25.89,38.96 22.5,37.5 C 19.11,38.96 12.39,37.53 9,38.5 C 7.65,38.99 6.68,38.97 6,38 C 7.35,36.54 9,36 9,36 z"/>
7
<path d="M 15,32 C 17.5,34.5 27.5,34.5 30,32 C 30.5,30.5 30,30 30,30 C 30,27.5 27.5,26 27.5,26 C 33,24.5 33.5,14.5 22.5,10.5 C 11.5,14.5 12,24.5 17.5,26 C 17.5,26 15,27.5 15,30 C 15,30 14.5,30.5 15,32 z"/>
8
<path d="M 25 8 A 2.5 2.5 0 1 1 20,8 A 2.5 2.5 0 1 1 25 8 z"/>
9
</g>
10
<path d="M 17.5,26 L 27.5,26 M 15,30 L 30,30 M 22.5,15.5 L 22.5,20.5 M 20,18 L 25,18" style="fill:none; stroke:#ffffff; stroke-linejoin:miter;"/>
11
</g>
12
</svg>
The contents of this binary file are not shown.
@@ -0,0 +1,12 @@
1
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
3
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="45" height="45">
4
<g style="fill:none; fill-opacity:1; fill-rule:evenodd; stroke:#000000; stroke-width:1.5; stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;">
5
<path d="M 22.5,11.63 L 22.5,6" style="fill:none; stroke:#000000; stroke-linejoin:miter;" id="path6570"/>
6
<path d="M 22.5,25 C 22.5,25 27,17.5 25.5,14.5 C 25.5,14.5 24.5,12 22.5,12 C 20.5,12 19.5,14.5 19.5,14.5 C 18,17.5 22.5,25 22.5,25" style="fill:#000000;fill-opacity:1; stroke-linecap:butt; stroke-linejoin:miter;"/>
7
<path d="M 12.5,37 C 18,40.5 27,40.5 32.5,37 L 32.5,30 C 32.5,30 41.5,25.5 38.5,19.5 C 34.5,13 25,16 22.5,23.5 L 22.5,27 L 22.5,23.5 C 20,16 10.5,13 6.5,19.5 C 3.5,25.5 12.5,30 12.5,30 L 12.5,37" style="fill:#000000; stroke:#000000;"/>
8
<path d="M 20,8 L 25,8" style="fill:none; stroke:#000000; stroke-linejoin:miter;"/>
9
<path d="M 32,29.5 C 32,29.5 40.5,25.5 38.03,19.85 C 34.15,14 25,18 22.5,24.5 L 22.5,26.6 L 22.5,24.5 C 20,18 10.85,14 6.97,19.85 C 4.5,25.5 13,29.5 13,29.5" style="fill:none; stroke:#ffffff;"/>
10
<path d="M 12.5,30 C 18,27 27,27 32.5,30 M 12.5,33.5 C 18,30.5 27,30.5 32.5,33.5 M 12.5,37 C 18,34 27,34 32.5,37" style="fill:none; stroke:#ffffff;"/>
11
</g>
12
</svg>
@@ -0,0 +1,12 @@1
<?xml version="1.0" encoding="UTF-8" standalone="no"?>2
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">3
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="45" height="45">4
<g style="fill:none; fill-opacity:1; fill-rule:evenodd; stroke:#000000; stroke-width:1.5; stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;">5
<path d="M 22.5,11.63 L 22.5,6" style="fill:none; stroke:#000000; stroke-linejoin:miter;" id="path6570"/>6
<path d="M 22.5,25 C 22.5,25 27,17.5 25.5,14.5 C 25.5,14.5 24.5,12 22.5,12 C 20.5,12 19.5,14.5 19.5,14.5 C 18,17.5 22.5,25 22.5,25" style="fill:#000000;fill-opacity:1; stroke-linecap:butt; stroke-linejoin:miter;"/>7
<path d="M 12.5,37 C 18,40.5 27,40.5 32.5,37 L 32.5,30 C 32.5,30 41.5,25.5 38.5,19.5 C 34.5,13 25,16 22.5,23.5 L 22.5,27 L 22.5,23.5 C 20,16 10.5,13 6.5,19.5 C 3.5,25.5 12.5,30 12.5,30 L 12.5,37" style="fill:#000000; stroke:#000000;"/>8
<path d="M 20,8 L 25,8" style="fill:none; stroke:#000000; stroke-linejoin:miter;"/>9
<path d="M 32,29.5 C 32,29.5 40.5,25.5 38.03,19.85 C 34.15,14 25,18 22.5,24.5 L 22.5,26.6 L 22.5,24.5 C 20,18 10.85,14 6.97,19.85 C 4.5,25.5 13,29.5 13,29.5" style="fill:none; stroke:#ffffff;"/>10
<path d="M 12.5,30 C 18,27 27,27 32.5,30 M 12.5,33.5 C 18,30.5 27,30.5 32.5,33.5 M 12.5,37 C 18,34 27,34 32.5,37" style="fill:none; stroke:#ffffff;"/>11
</g>12
</svg>The contents of this binary file are not shown.
@@ -0,0 +1,22 @@
1
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
3
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="45" height="45">
4
<g style="opacity:1; fill:none; fill-opacity:1; fill-rule:evenodd; stroke:#000000; stroke-width:1.5; stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;" transform="translate(0,0.3)">
5
<path
6
d="M 22,10 C 32.5,11 38.5,18 38,39 L 15,39 C 15,30 25,32.5 23,18"
7
style="fill:#000000; stroke:#000000;" />
8
<path
9
d="M 24,18 C 24.38,20.91 18.45,25.37 16,27 C 13,29 13.18,31.34 11,31 C 9.958,30.06 12.41,27.96 11,28 C 10,28 11.19,29.23 10,30 C 9,30 5.997,31 6,26 C 6,24 12,14 12,14 C 12,14 13.89,12.1 14,10.5 C 13.27,9.506 13.5,8.5 13.5,7.5 C 14.5,6.5 16.5,10 16.5,10 L 18.5,10 C 18.5,10 19.28,8.008 21,7 C 22,7 22,10 22,10"
10
style="fill:#000000; stroke:#000000;" />
11
<path
12
d="M 9.5 25.5 A 0.5 0.5 0 1 1 8.5,25.5 A 0.5 0.5 0 1 1 9.5 25.5 z"
13
style="fill:#ffffff; stroke:#ffffff;" />
14
<path
15
d="M 15 15.5 A 0.5 1.5 0 1 1 14,15.5 A 0.5 1.5 0 1 1 15 15.5 z"
16
transform="matrix(0.866,0.5,-0.5,0.866,9.693,-5.173)"
17
style="fill:#ffffff; stroke:#ffffff;" />
18
<path
19
d="M 24.55,10.4 L 24.1,11.85 L 24.6,12 C 27.75,13 30.25,14.49 32.5,18.75 C 34.75,23.01 35.75,29.06 35.25,39 L 35.2,39.5 L 37.45,39.5 L 37.5,39 C 38,28.94 36.62,22.15 34.25,17.66 C 31.88,13.17 28.46,11.02 25.06,10.5 L 24.55,10.4 z "
20
style="fill:#ffffff; stroke:none;" />
21
</g>
22
</svg>
@@ -0,0 +1,22 @@1
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
3
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="45" height="45">
4
<g style="opacity:1; fill:none; fill-opacity:1; fill-rule:evenodd; stroke:#000000; stroke-width:1.5; stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;" transform="translate(0,0.3)">
5
<path
6
d="M 22,10 C 32.5,11 38.5,18 38,39 L 15,39 C 15,30 25,32.5 23,18"
7
style="fill:#000000; stroke:#000000;" />
8
<path
9
d="M 24,18 C 24.38,20.91 18.45,25.37 16,27 C 13,29 13.18,31.34 11,31 C 9.958,30.06 12.41,27.96 11,28 C 10,28 11.19,29.23 10,30 C 9,30 5.997,31 6,26 C 6,24 12,14 12,14 C 12,14 13.89,12.1 14,10.5 C 13.27,9.506 13.5,8.5 13.5,7.5 C 14.5,6.5 16.5,10 16.5,10 L 18.5,10 C 18.5,10 19.28,8.008 21,7 C 22,7 22,10 22,10"
10
style="fill:#000000; stroke:#000000;" />
11
<path
12
d="M 9.5 25.5 A 0.5 0.5 0 1 1 8.5,25.5 A 0.5 0.5 0 1 1 9.5 25.5 z"
13
style="fill:#ffffff; stroke:#ffffff;" />
14
<path
15
d="M 15 15.5 A 0.5 1.5 0 1 1 14,15.5 A 0.5 1.5 0 1 1 15 15.5 z"
16
transform="matrix(0.866,0.5,-0.5,0.866,9.693,-5.173)"
17
style="fill:#ffffff; stroke:#ffffff;" />
18
<path
19
d="M 24.55,10.4 L 24.1,11.85 L 24.6,12 C 27.75,13 30.25,14.49 32.5,18.75 C 34.75,23.01 35.75,29.06 35.25,39 L 35.2,39.5 L 37.45,39.5 L 37.5,39 C 38,28.94 36.62,22.15 34.25,17.66 C 31.88,13.17 28.46,11.02 25.06,10.5 L 24.55,10.4 z "
20
style="fill:#ffffff; stroke:none;" />
21
</g>
22
</svg>
The contents of this binary file are not shown.
@@ -0,0 +1,5 @@
1
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
3
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="45" height="45">
4
<path d="m 22.5,9 c -2.21,0 -4,1.79 -4,4 0,0.89 0.29,1.71 0.78,2.38 C 17.33,16.5 16,18.59 16,21 c 0,2.03 0.94,3.84 2.41,5.03 C 15.41,27.09 11,31.58 11,39.5 H 34 C 34,31.58 29.59,27.09 26.59,26.03 28.06,24.84 29,23.03 29,21 29,18.59 27.67,16.5 25.72,15.38 26.21,14.71 26.5,13.89 26.5,13 c 0,-2.21 -1.79,-4 -4,-4 z" style="opacity:1; fill:#000000; fill-opacity:1; fill-rule:nonzero; stroke:#000000; stroke-width:1.5; stroke-linecap:round; stroke-linejoin:miter; stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;"/>
5
</svg>
@@ -0,0 +1,5 @@1
<?xml version="1.0" encoding="UTF-8" standalone="no"?>2
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">3
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="45" height="45">4
<path d="m 22.5,9 c -2.21,0 -4,1.79 -4,4 0,0.89 0.29,1.71 0.78,2.38 C 17.33,16.5 16,18.59 16,21 c 0,2.03 0.94,3.84 2.41,5.03 C 15.41,27.09 11,31.58 11,39.5 H 34 C 34,31.58 29.59,27.09 26.59,26.03 28.06,24.84 29,23.03 29,21 29,18.59 27.67,16.5 25.72,15.38 26.21,14.71 26.5,13.89 26.5,13 c 0,-2.21 -1.79,-4 -4,-4 z" style="opacity:1; fill:#000000; fill-opacity:1; fill-rule:nonzero; stroke:#000000; stroke-width:1.5; stroke-linecap:round; stroke-linejoin:miter; stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;"/>5
</svg>The contents of this binary file are not shown.
@@ -0,0 +1,27 @@
1
<?xml version="1.0" encoding="utf-8" standalone="no"?>
2
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
3
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
4
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="45"
5
height="45">
6
<g style="fill:#000000;stroke:#000000;stroke-width:1.5; stroke-linecap:round;stroke-linejoin:round">
7
8
<path d="M 9,26 C 17.5,24.5 30,24.5 36,26 L 38.5,13.5 L 31,25 L 30.7,10.9 L 25.5,24.5 L 22.5,10 L 19.5,24.5 L 14.3,10.9 L 14,25 L 6.5,13.5 L 9,26 z"
9
style="stroke-linecap:butt;fill:#000000" />
10
<path d="m 9,26 c 0,2 1.5,2 2.5,4 1,1.5 1,1 0.5,3.5 -1.5,1 -1,2.5 -1,2.5 -1.5,1.5 0,2.5 0,2.5 6.5,1 16.5,1 23,0 0,0 1.5,-1 0,-2.5 0,0 0.5,-1.5 -1,-2.5 -0.5,-2.5 -0.5,-2 0.5,-3.5 1,-2 2.5,-2 2.5,-4 -8.5,-1.5 -18.5,-1.5 -27,0 z" />
11
<path d="M 11.5,30 C 15,29 30,29 33.5,30" />
12
<path d="m 12,33.5 c 6,-1 15,-1 21,0" />
13
<circle cx="6" cy="12" r="2" />
14
<circle cx="14" cy="9" r="2" />
15
<circle cx="22.5" cy="8" r="2" />
16
<circle cx="31" cy="9" r="2" />
17
<circle cx="39" cy="12" r="2" />
18
<path d="M 11,38.5 A 35,35 1 0 0 34,38.5"
19
style="fill:none; stroke:#000000;stroke-linecap:butt;" />
20
<g style="fill:none; stroke:#ffffff;">
21
<path d="M 11,29 A 35,35 1 0 1 34,29" />
22
<path d="M 12.5,31.5 L 32.5,31.5" />
23
<path d="M 11.5,34.5 A 35,35 1 0 0 33.5,34.5" />
24
<path d="M 10.5,37.5 A 35,35 1 0 0 34.5,37.5" />
25
</g>
26
</g>
27
</svg>
@@ -0,0 +1,27 @@1
<?xml version="1.0" encoding="utf-8" standalone="no"?>2
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"3
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">4
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="45"5
height="45">6
<g style="fill:#000000;stroke:#000000;stroke-width:1.5; stroke-linecap:round;stroke-linejoin:round">7
8
<path d="M 9,26 C 17.5,24.5 30,24.5 36,26 L 38.5,13.5 L 31,25 L 30.7,10.9 L 25.5,24.5 L 22.5,10 L 19.5,24.5 L 14.3,10.9 L 14,25 L 6.5,13.5 L 9,26 z"9
style="stroke-linecap:butt;fill:#000000" />10
<path d="m 9,26 c 0,2 1.5,2 2.5,4 1,1.5 1,1 0.5,3.5 -1.5,1 -1,2.5 -1,2.5 -1.5,1.5 0,2.5 0,2.5 6.5,1 16.5,1 23,0 0,0 1.5,-1 0,-2.5 0,0 0.5,-1.5 -1,-2.5 -0.5,-2.5 -0.5,-2 0.5,-3.5 1,-2 2.5,-2 2.5,-4 -8.5,-1.5 -18.5,-1.5 -27,0 z" />11
<path d="M 11.5,30 C 15,29 30,29 33.5,30" />12
<path d="m 12,33.5 c 6,-1 15,-1 21,0" />13
<circle cx="6" cy="12" r="2" />14
<circle cx="14" cy="9" r="2" />15
<circle cx="22.5" cy="8" r="2" />16
<circle cx="31" cy="9" r="2" />17
<circle cx="39" cy="12" r="2" />18
<path d="M 11,38.5 A 35,35 1 0 0 34,38.5"19
style="fill:none; stroke:#000000;stroke-linecap:butt;" />20
<g style="fill:none; stroke:#ffffff;">21
<path d="M 11,29 A 35,35 1 0 1 34,29" />22
<path d="M 12.5,31.5 L 32.5,31.5" />23
<path d="M 11.5,34.5 A 35,35 1 0 0 33.5,34.5" />24
<path d="M 10.5,37.5 A 35,35 1 0 0 34.5,37.5" />25
</g>26
</g>27
</svg>The contents of this binary file are not shown.
@@ -0,0 +1,39 @@
1
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
3
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="45" height="45">
4
<g style="opacity:1; fill:#000000; fill-opacity:1; fill-rule:evenodd; stroke:#000000; stroke-width:1.5; stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;" transform="translate(0,0.3)">
5
<path
6
d="M 9,39 L 36,39 L 36,36 L 9,36 L 9,39 z "
7
style="stroke-linecap:butt;" />
8
<path
9
d="M 12.5,32 L 14,29.5 L 31,29.5 L 32.5,32 L 12.5,32 z "
10
style="stroke-linecap:butt;" />
11
<path
12
d="M 12,36 L 12,32 L 33,32 L 33,36 L 12,36 z "
13
style="stroke-linecap:butt;" />
14
<path
15
d="M 14,29.5 L 14,16.5 L 31,16.5 L 31,29.5 L 14,29.5 z "
16
style="stroke-linecap:butt;stroke-linejoin:miter;" />
17
<path
18
d="M 14,16.5 L 11,14 L 34,14 L 31,16.5 L 14,16.5 z "
19
style="stroke-linecap:butt;" />
20
<path
21
d="M 11,14 L 11,9 L 15,9 L 15,11 L 20,11 L 20,9 L 25,9 L 25,11 L 30,11 L 30,9 L 34,9 L 34,14 L 11,14 z "
22
style="stroke-linecap:butt;" />
23
<path
24
d="M 12,35.5 L 33,35.5 L 33,35.5"
25
style="fill:none; stroke:#ffffff; stroke-width:1; stroke-linejoin:miter;" />
26
<path
27
d="M 13,31.5 L 32,31.5"
28
style="fill:none; stroke:#ffffff; stroke-width:1; stroke-linejoin:miter;" />
29
<path
30
d="M 14,29.5 L 31,29.5"
31
style="fill:none; stroke:#ffffff; stroke-width:1; stroke-linejoin:miter;" />
32
<path
33
d="M 14,16.5 L 31,16.5"
34
style="fill:none; stroke:#ffffff; stroke-width:1; stroke-linejoin:miter;" />
35
<path
36
d="M 11,14 L 34,14"
37
style="fill:none; stroke:#ffffff; stroke-width:1; stroke-linejoin:miter;" />
38
</g>
39
</svg>
@@ -0,0 +1,39 @@1
<?xml version="1.0" encoding="UTF-8" standalone="no"?>2
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">3
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="45" height="45">4
<g style="opacity:1; fill:#000000; fill-opacity:1; fill-rule:evenodd; stroke:#000000; stroke-width:1.5; stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;" transform="translate(0,0.3)">5
<path6
d="M 9,39 L 36,39 L 36,36 L 9,36 L 9,39 z "7
style="stroke-linecap:butt;" />8
<path9
d="M 12.5,32 L 14,29.5 L 31,29.5 L 32.5,32 L 12.5,32 z "10
style="stroke-linecap:butt;" />11
<path12
d="M 12,36 L 12,32 L 33,32 L 33,36 L 12,36 z "13
style="stroke-linecap:butt;" />14
<path15
d="M 14,29.5 L 14,16.5 L 31,16.5 L 31,29.5 L 14,29.5 z "16
style="stroke-linecap:butt;stroke-linejoin:miter;" />17
<path18
d="M 14,16.5 L 11,14 L 34,14 L 31,16.5 L 14,16.5 z "19
style="stroke-linecap:butt;" />20
<path21
d="M 11,14 L 11,9 L 15,9 L 15,11 L 20,11 L 20,9 L 25,9 L 25,11 L 30,11 L 30,9 L 34,9 L 34,14 L 11,14 z "22
style="stroke-linecap:butt;" />23
<path24
d="M 12,35.5 L 33,35.5 L 33,35.5"25
style="fill:none; stroke:#ffffff; stroke-width:1; stroke-linejoin:miter;" />26
<path27
d="M 13,31.5 L 32,31.5"28
style="fill:none; stroke:#ffffff; stroke-width:1; stroke-linejoin:miter;" />29
<path30
d="M 14,29.5 L 31,29.5"31
style="fill:none; stroke:#ffffff; stroke-width:1; stroke-linejoin:miter;" />32
<path33
d="M 14,16.5 L 31,16.5"34
style="fill:none; stroke:#ffffff; stroke-width:1; stroke-linejoin:miter;" />35
<path36
d="M 11,14 L 34,14"37
style="fill:none; stroke:#ffffff; stroke-width:1; stroke-linejoin:miter;" />38
</g>39
</svg>@@ -1,4 +1,70 @@
1
1
[
2
{
3
"id": "black-bishop",
4
"name": "Black bishop",
5
"group": "standard",
6
"color": "Black",
7
"file": "black-bishop.png",
8
"source": "https://commons.wikimedia.org/wiki/File:Chess_bdt45.svg",
9
"author": "Original work by C. Burnett (2006)\n\n(https://en.wikipedia.org/wiki/User:Cburnett)",
10
"license": "CC BY-SA 3.0",
11
"licenseUrl": "https://creativecommons.org/licenses/by-sa/3.0"
12
},
13
{
14
"id": "black-king",
15
"name": "Black king",
16
"group": "standard",
17
"color": "Black",
18
"file": "black-king.png",
19
"source": "https://commons.wikimedia.org/wiki/File:Chess_kdt45.svg",
20
"author": "Original work by C. Burnett (2006)\n\n(https://en.wikipedia.org/wiki/User:Cburnett)",
21
"license": "CC BY-SA 3.0",
22
"licenseUrl": "https://creativecommons.org/licenses/by-sa/3.0"
23
},
24
{
25
"id": "black-knight",
26
"name": "Black knight",
27
"group": "standard",
28
"color": "Black",
29
"file": "black-knight.png",
30
"source": "https://commons.wikimedia.org/wiki/File:Chess_ndt45.svg",
31
"author": "Original work by C. Burnett (2006)\n\n(https://en.wikipedia.org/wiki/User:Cburnett)",
32
"license": "CC BY-SA 3.0",
33
"licenseUrl": "https://creativecommons.org/licenses/by-sa/3.0"
34
},
35
{
36
"id": "black-pawn",
37
"name": "Black pawn",
38
"group": "standard",
39
"color": "Black",
40
"file": "black-pawn.png",
41
"source": "https://commons.wikimedia.org/wiki/File:Chess_pdt45.svg",
42
"author": "Original work by C. Burnett (2006)\n\n(https://en.wikipedia.org/wiki/User:Cburnett)",
43
"license": "CC BY-SA 3.0",
44
"licenseUrl": "https://creativecommons.org/licenses/by-sa/3.0"
45
},
46
{
47
"id": "black-queen",
48
"name": "Black queen",
49
"group": "standard",
50
"color": "Black",
51
"file": "black-queen.png",
52
"source": "https://commons.wikimedia.org/wiki/File:Chess_qdt45.svg",
53
"author": "Original work by C. Burnett (2006)\n\n(https://en.wikipedia.org/wiki/User:Cburnett)",
54
"license": "CC BY-SA 3.0",
55
"licenseUrl": "https://creativecommons.org/licenses/by-sa/3.0"
56
},
57
{
58
"id": "black-rook",
59
"name": "Black rook",
60
"group": "standard",
61
"color": "Black",
62
"file": "black-rook.png",
63
"source": "https://commons.wikimedia.org/wiki/File:Chess_rdt45.svg",
64
"author": "Original work by C. Burnett (2006)\n\n(https://en.wikipedia.org/wiki/User:Cburnett)",
65
"license": "CC BY-SA 3.0",
66
"licenseUrl": "https://creativecommons.org/licenses/by-sa/3.0"
67
},
2
68
{
3
69
"id": "blue-bishop",
4
70
"name": "Blue bishop",
@@ -197,6 +263,72 @@
197
263
"license": "CC BY-SA 3.0",
198
264
"licenseUrl": "https://creativecommons.org/licenses/by-sa/3.0"
199
265
},
266
{
267
"id": "white-bishop",
268
"name": "White bishop",
269
"group": "standard",
270
"color": "White",
271
"file": "white-bishop.png",
272
"source": "https://commons.wikimedia.org/wiki/File:Chess_blt45.svg",
273
"author": "Original work by C. Burnett (2006)\n\n(https://en.wikipedia.org/wiki/User:Cburnett)",
274
"license": "CC BY-SA 3.0",
275
"licenseUrl": "https://creativecommons.org/licenses/by-sa/3.0"
276
},
277
{
278
"id": "white-king",
279
"name": "White king",
280
"group": "standard",
281
"color": "White",
282
"file": "white-king.png",
283
"source": "https://commons.wikimedia.org/wiki/File:Chess_klt45.svg",
284
"author": "Original work by C. Burnett (2006)\n\n(https://en.wikipedia.org/wiki/User:Cburnett)",
285
"license": "CC BY-SA 3.0",
286
"licenseUrl": "https://creativecommons.org/licenses/by-sa/3.0"
287
},
288
{
289
"id": "white-knight",
290
"name": "White knight",
291
"group": "standard",
292
"color": "White",
293
"file": "white-knight.png",
294
"source": "https://commons.wikimedia.org/wiki/File:Chess_nlt45.svg",
295
"author": "Original work by C. Burnett (2006)\n\n(https://en.wikipedia.org/wiki/User:Cburnett)",
296
"license": "CC BY-SA 3.0",
297
"licenseUrl": "https://creativecommons.org/licenses/by-sa/3.0"
298
},
299
{
300
"id": "white-pawn",
301
"name": "White pawn",
302
"group": "standard",
303
"color": "White",
304
"file": "white-pawn.png",
305
"source": "https://commons.wikimedia.org/wiki/File:Chess_plt45.svg",
306
"author": "Original work by C. Burnett (2006)\n\n(https://en.wikipedia.org/wiki/User:Cburnett)",
307
"license": "CC BY-SA 3.0",
308
"licenseUrl": "https://creativecommons.org/licenses/by-sa/3.0"
309
},
310
{
311
"id": "white-queen",
312
"name": "White queen",
313
"group": "standard",
314
"color": "White",
315
"file": "white-queen.png",
316
"source": "https://commons.wikimedia.org/wiki/File:Chess_qlt45.svg",
317
"author": "Original work by C. Burnett (2006)\n\n(https://en.wikipedia.org/wiki/User:Cburnett)",
318
"license": "CC BY-SA 3.0",
319
"licenseUrl": "https://creativecommons.org/licenses/by-sa/3.0"
320
},
321
{
322
"id": "white-rook",
323
"name": "White rook",
324
"group": "standard",
325
"color": "White",
326
"file": "white-rook.png",
327
"source": "https://commons.wikimedia.org/wiki/File:Chess_rlt45.svg",
328
"author": "Original work by C. Burnett (2006)\n\n(https://en.wikipedia.org/wiki/User:Cburnett)",
329
"license": "CC BY-SA 3.0",
330
"licenseUrl": "https://creativecommons.org/licenses/by-sa/3.0"
331
},
200
332
{
201
333
"id": "yellow-bishop",
202
334
"name": "Yellow bishop",
@@ -1,4 +1,70 @@1
[1
[2
{3
"id": "black-bishop",4
"name": "Black bishop",5
"group": "standard",6
"color": "Black",7
"file": "black-bishop.png",8
"source": "https://commons.wikimedia.org/wiki/File:Chess_bdt45.svg",9
"author": "Original work by C. Burnett (2006)\n\n(https://en.wikipedia.org/wiki/User:Cburnett)",10
"license": "CC BY-SA 3.0",11
"licenseUrl": "https://creativecommons.org/licenses/by-sa/3.0"12
},13
{14
"id": "black-king",15
"name": "Black king",16
"group": "standard",17
"color": "Black",18
"file": "black-king.png",19
"source": "https://commons.wikimedia.org/wiki/File:Chess_kdt45.svg",20
"author": "Original work by C. Burnett (2006)\n\n(https://en.wikipedia.org/wiki/User:Cburnett)",21
"license": "CC BY-SA 3.0",22
"licenseUrl": "https://creativecommons.org/licenses/by-sa/3.0"23
},24
{25
"id": "black-knight",26
"name": "Black knight",27
"group": "standard",28
"color": "Black",29
"file": "black-knight.png",30
"source": "https://commons.wikimedia.org/wiki/File:Chess_ndt45.svg",31
"author": "Original work by C. Burnett (2006)\n\n(https://en.wikipedia.org/wiki/User:Cburnett)",32
"license": "CC BY-SA 3.0",33
"licenseUrl": "https://creativecommons.org/licenses/by-sa/3.0"34
},35
{36
"id": "black-pawn",37
"name": "Black pawn",38
"group": "standard",39
"color": "Black",40
"file": "black-pawn.png",41
"source": "https://commons.wikimedia.org/wiki/File:Chess_pdt45.svg",42
"author": "Original work by C. Burnett (2006)\n\n(https://en.wikipedia.org/wiki/User:Cburnett)",43
"license": "CC BY-SA 3.0",44
"licenseUrl": "https://creativecommons.org/licenses/by-sa/3.0"45
},46
{47
"id": "black-queen",48
"name": "Black queen",49
"group": "standard",50
"color": "Black",51
"file": "black-queen.png",52
"source": "https://commons.wikimedia.org/wiki/File:Chess_qdt45.svg",53
"author": "Original work by C. Burnett (2006)\n\n(https://en.wikipedia.org/wiki/User:Cburnett)",54
"license": "CC BY-SA 3.0",55
"licenseUrl": "https://creativecommons.org/licenses/by-sa/3.0"56
},57
{58
"id": "black-rook",59
"name": "Black rook",60
"group": "standard",61
"color": "Black",62
"file": "black-rook.png",63
"source": "https://commons.wikimedia.org/wiki/File:Chess_rdt45.svg",64
"author": "Original work by C. Burnett (2006)\n\n(https://en.wikipedia.org/wiki/User:Cburnett)",65
"license": "CC BY-SA 3.0",66
"licenseUrl": "https://creativecommons.org/licenses/by-sa/3.0"67
},2
{68
{3
"id": "blue-bishop",69
"id": "blue-bishop",4
"name": "Blue bishop",70
"name": "Blue bishop",@@ -197,6 +263,72 @@197
"license": "CC BY-SA 3.0",263
"license": "CC BY-SA 3.0",198
"licenseUrl": "https://creativecommons.org/licenses/by-sa/3.0"264
"licenseUrl": "https://creativecommons.org/licenses/by-sa/3.0"199
},265
},266
{267
"id": "white-bishop",268
"name": "White bishop",269
"group": "standard",270
"color": "White",271
"file": "white-bishop.png",272
"source": "https://commons.wikimedia.org/wiki/File:Chess_blt45.svg",273
"author": "Original work by C. Burnett (2006)\n\n(https://en.wikipedia.org/wiki/User:Cburnett)",274
"license": "CC BY-SA 3.0",275
"licenseUrl": "https://creativecommons.org/licenses/by-sa/3.0"276
},277
{278
"id": "white-king",279
"name": "White king",280
"group": "standard",281
"color": "White",282
"file": "white-king.png",283
"source": "https://commons.wikimedia.org/wiki/File:Chess_klt45.svg",284
"author": "Original work by C. Burnett (2006)\n\n(https://en.wikipedia.org/wiki/User:Cburnett)",285
"license": "CC BY-SA 3.0",286
"licenseUrl": "https://creativecommons.org/licenses/by-sa/3.0"287
},288
{289
"id": "white-knight",290
"name": "White knight",291
"group": "standard",292
"color": "White",293
"file": "white-knight.png",294
"source": "https://commons.wikimedia.org/wiki/File:Chess_nlt45.svg",295
"author": "Original work by C. Burnett (2006)\n\n(https://en.wikipedia.org/wiki/User:Cburnett)",296
"license": "CC BY-SA 3.0",297
"licenseUrl": "https://creativecommons.org/licenses/by-sa/3.0"298
},299
{300
"id": "white-pawn",301
"name": "White pawn",302
"group": "standard",303
"color": "White",304
"file": "white-pawn.png",305
"source": "https://commons.wikimedia.org/wiki/File:Chess_plt45.svg",306
"author": "Original work by C. Burnett (2006)\n\n(https://en.wikipedia.org/wiki/User:Cburnett)",307
"license": "CC BY-SA 3.0",308
"licenseUrl": "https://creativecommons.org/licenses/by-sa/3.0"309
},310
{311
"id": "white-queen",312
"name": "White queen",313
"group": "standard",314
"color": "White",315
"file": "white-queen.png",316
"source": "https://commons.wikimedia.org/wiki/File:Chess_qlt45.svg",317
"author": "Original work by C. Burnett (2006)\n\n(https://en.wikipedia.org/wiki/User:Cburnett)",318
"license": "CC BY-SA 3.0",319
"licenseUrl": "https://creativecommons.org/licenses/by-sa/3.0"320
},321
{322
"id": "white-rook",323
"name": "White rook",324
"group": "standard",325
"color": "White",326
"file": "white-rook.png",327
"source": "https://commons.wikimedia.org/wiki/File:Chess_rlt45.svg",328
"author": "Original work by C. Burnett (2006)\n\n(https://en.wikipedia.org/wiki/User:Cburnett)",329
"license": "CC BY-SA 3.0",330
"licenseUrl": "https://creativecommons.org/licenses/by-sa/3.0"331
},200
{332
{201
"id": "yellow-bishop",333
"id": "yellow-bishop",202
"name": "Yellow bishop",334
"name": "Yellow bishop",The contents of this binary file are not shown.
@@ -0,0 +1,12 @@
1
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
3
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="45" height="45">
4
<g style="opacity:1; fill:none; fill-rule:evenodd; fill-opacity:1; stroke:#000000; stroke-width:1.5; stroke-linecap:round; stroke-linejoin:round; stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;" transform="translate(0,0.6)">
5
<g style="fill:#ffffff; stroke:#000000; stroke-linecap:butt;">
6
<path d="M 9,36 C 12.39,35.03 19.11,36.43 22.5,34 C 25.89,36.43 32.61,35.03 36,36 C 36,36 37.65,36.54 39,38 C 38.32,38.97 37.35,38.99 36,38.5 C 32.61,37.53 25.89,38.96 22.5,37.5 C 19.11,38.96 12.39,37.53 9,38.5 C 7.65,38.99 6.68,38.97 6,38 C 7.35,36.54 9,36 9,36 z"/>
7
<path d="M 15,32 C 17.5,34.5 27.5,34.5 30,32 C 30.5,30.5 30,30 30,30 C 30,27.5 27.5,26 27.5,26 C 33,24.5 33.5,14.5 22.5,10.5 C 11.5,14.5 12,24.5 17.5,26 C 17.5,26 15,27.5 15,30 C 15,30 14.5,30.5 15,32 z"/>
8
<path d="M 25 8 A 2.5 2.5 0 1 1 20,8 A 2.5 2.5 0 1 1 25 8 z"/>
9
</g>
10
<path d="M 17.5,26 L 27.5,26 M 15,30 L 30,30 M 22.5,15.5 L 22.5,20.5 M 20,18 L 25,18" style="fill:none; stroke:#000000; stroke-linejoin:miter;"/>
11
</g>
12
</svg>
@@ -0,0 +1,12 @@1
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
3
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="45" height="45">
4
<g style="opacity:1; fill:none; fill-rule:evenodd; fill-opacity:1; stroke:#000000; stroke-width:1.5; stroke-linecap:round; stroke-linejoin:round; stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;" transform="translate(0,0.6)">
5
<g style="fill:#ffffff; stroke:#000000; stroke-linecap:butt;">
6
<path d="M 9,36 C 12.39,35.03 19.11,36.43 22.5,34 C 25.89,36.43 32.61,35.03 36,36 C 36,36 37.65,36.54 39,38 C 38.32,38.97 37.35,38.99 36,38.5 C 32.61,37.53 25.89,38.96 22.5,37.5 C 19.11,38.96 12.39,37.53 9,38.5 C 7.65,38.99 6.68,38.97 6,38 C 7.35,36.54 9,36 9,36 z"/>
7
<path d="M 15,32 C 17.5,34.5 27.5,34.5 30,32 C 30.5,30.5 30,30 30,30 C 30,27.5 27.5,26 27.5,26 C 33,24.5 33.5,14.5 22.5,10.5 C 11.5,14.5 12,24.5 17.5,26 C 17.5,26 15,27.5 15,30 C 15,30 14.5,30.5 15,32 z"/>
8
<path d="M 25 8 A 2.5 2.5 0 1 1 20,8 A 2.5 2.5 0 1 1 25 8 z"/>
9
</g>
10
<path d="M 17.5,26 L 27.5,26 M 15,30 L 30,30 M 22.5,15.5 L 22.5,20.5 M 20,18 L 25,18" style="fill:none; stroke:#000000; stroke-linejoin:miter;"/>
11
</g>
12
</svg>
The contents of this binary file are not shown.
@@ -0,0 +1,9 @@
1
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
<svg xmlns="http://www.w3.org/2000/svg" width="45" height="45">
3
<g fill="none" fill-rule="evenodd" stroke="#000" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5">
4
<path stroke-linejoin="miter" d="M22.5 11.63V6M20 8h5"/>
5
<path fill="#fff" stroke-linecap="butt" stroke-linejoin="miter" d="M22.5 25s4.5-7.5 3-10.5c0 0-1-2.5-3-2.5s-3 2.5-3 2.5c-1.5 3 3 10.5 3 10.5"/>
6
<path fill="#fff" d="M12.5 37c5.5 3.5 14.5 3.5 20 0v-7s9-4.5 6-10.5c-4-6.5-13.5-3.5-16 4V27v-3.5c-2.5-7.5-12-10.5-16-4-3 6 6 10.5 6 10.5v7"/>
7
<path d="M12.5 30c5.5-3 14.5-3 20 0m-20 3.5c5.5-3 14.5-3 20 0m-20 3.5c5.5-3 14.5-3 20 0"/>
8
</g>
9
</svg>
@@ -0,0 +1,9 @@1
<?xml version="1.0" encoding="UTF-8" standalone="no"?>2
<svg xmlns="http://www.w3.org/2000/svg" width="45" height="45">3
<g fill="none" fill-rule="evenodd" stroke="#000" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5">4
<path stroke-linejoin="miter" d="M22.5 11.63V6M20 8h5"/>5
<path fill="#fff" stroke-linecap="butt" stroke-linejoin="miter" d="M22.5 25s4.5-7.5 3-10.5c0 0-1-2.5-3-2.5s-3 2.5-3 2.5c-1.5 3 3 10.5 3 10.5"/>6
<path fill="#fff" d="M12.5 37c5.5 3.5 14.5 3.5 20 0v-7s9-4.5 6-10.5c-4-6.5-13.5-3.5-16 4V27v-3.5c-2.5-7.5-12-10.5-16-4-3 6 6 10.5 6 10.5v7"/>7
<path d="M12.5 30c5.5-3 14.5-3 20 0m-20 3.5c5.5-3 14.5-3 20 0m-20 3.5c5.5-3 14.5-3 20 0"/>8
</g>9
</svg>The contents of this binary file are not shown.
@@ -0,0 +1,19 @@
1
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
3
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="45" height="45">
4
<g style="opacity:1; fill:none; fill-opacity:1; fill-rule:evenodd; stroke:#000000; stroke-width:1.5; stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;" transform="translate(0,0.3)">
5
<path
6
d="M 22,10 C 32.5,11 38.5,18 38,39 L 15,39 C 15,30 25,32.5 23,18"
7
style="fill:#ffffff; stroke:#000000;" />
8
<path
9
d="M 24,18 C 24.38,20.91 18.45,25.37 16,27 C 13,29 13.18,31.34 11,31 C 9.958,30.06 12.41,27.96 11,28 C 10,28 11.19,29.23 10,30 C 9,30 5.997,31 6,26 C 6,24 12,14 12,14 C 12,14 13.89,12.1 14,10.5 C 13.27,9.506 13.5,8.5 13.5,7.5 C 14.5,6.5 16.5,10 16.5,10 L 18.5,10 C 18.5,10 19.28,8.008 21,7 C 22,7 22,10 22,10"
10
style="fill:#ffffff; stroke:#000000;" />
11
<path
12
d="M 9.5 25.5 A 0.5 0.5 0 1 1 8.5,25.5 A 0.5 0.5 0 1 1 9.5 25.5 z"
13
style="fill:#000000; stroke:#000000;" />
14
<path
15
d="M 15 15.5 A 0.5 1.5 0 1 1 14,15.5 A 0.5 1.5 0 1 1 15 15.5 z"
16
transform="matrix(0.866,0.5,-0.5,0.866,9.693,-5.173)"
17
style="fill:#000000; stroke:#000000;" />
18
</g>
19
</svg>
@@ -0,0 +1,19 @@1
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
3
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="45" height="45">
4
<g style="opacity:1; fill:none; fill-opacity:1; fill-rule:evenodd; stroke:#000000; stroke-width:1.5; stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;" transform="translate(0,0.3)">
5
<path
6
d="M 22,10 C 32.5,11 38.5,18 38,39 L 15,39 C 15,30 25,32.5 23,18"
7
style="fill:#ffffff; stroke:#000000;" />
8
<path
9
d="M 24,18 C 24.38,20.91 18.45,25.37 16,27 C 13,29 13.18,31.34 11,31 C 9.958,30.06 12.41,27.96 11,28 C 10,28 11.19,29.23 10,30 C 9,30 5.997,31 6,26 C 6,24 12,14 12,14 C 12,14 13.89,12.1 14,10.5 C 13.27,9.506 13.5,8.5 13.5,7.5 C 14.5,6.5 16.5,10 16.5,10 L 18.5,10 C 18.5,10 19.28,8.008 21,7 C 22,7 22,10 22,10"
10
style="fill:#ffffff; stroke:#000000;" />
11
<path
12
d="M 9.5 25.5 A 0.5 0.5 0 1 1 8.5,25.5 A 0.5 0.5 0 1 1 9.5 25.5 z"
13
style="fill:#000000; stroke:#000000;" />
14
<path
15
d="M 15 15.5 A 0.5 1.5 0 1 1 14,15.5 A 0.5 1.5 0 1 1 15 15.5 z"
16
transform="matrix(0.866,0.5,-0.5,0.866,9.693,-5.173)"
17
style="fill:#000000; stroke:#000000;" />
18
</g>
19
</svg>
The contents of this binary file are not shown.
@@ -0,0 +1,5 @@
1
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
3
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="45" height="45">
4
<path d="m 22.5,9 c -2.21,0 -4,1.79 -4,4 0,0.89 0.29,1.71 0.78,2.38 C 17.33,16.5 16,18.59 16,21 c 0,2.03 0.94,3.84 2.41,5.03 C 15.41,27.09 11,31.58 11,39.5 H 34 C 34,31.58 29.59,27.09 26.59,26.03 28.06,24.84 29,23.03 29,21 29,18.59 27.67,16.5 25.72,15.38 26.21,14.71 26.5,13.89 26.5,13 c 0,-2.21 -1.79,-4 -4,-4 z" style="opacity:1; fill:#ffffff; fill-opacity:1; fill-rule:nonzero; stroke:#000000; stroke-width:1.5; stroke-linecap:round; stroke-linejoin:miter; stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;"/>
5
</svg>
@@ -0,0 +1,5 @@1
<?xml version="1.0" encoding="UTF-8" standalone="no"?>2
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">3
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="45" height="45">4
<path d="m 22.5,9 c -2.21,0 -4,1.79 -4,4 0,0.89 0.29,1.71 0.78,2.38 C 17.33,16.5 16,18.59 16,21 c 0,2.03 0.94,3.84 2.41,5.03 C 15.41,27.09 11,31.58 11,39.5 H 34 C 34,31.58 29.59,27.09 26.59,26.03 28.06,24.84 29,23.03 29,21 29,18.59 27.67,16.5 25.72,15.38 26.21,14.71 26.5,13.89 26.5,13 c 0,-2.21 -1.79,-4 -4,-4 z" style="opacity:1; fill:#ffffff; fill-opacity:1; fill-rule:nonzero; stroke:#000000; stroke-width:1.5; stroke-linecap:round; stroke-linejoin:miter; stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;"/>5
</svg>The contents of this binary file are not shown.
@@ -0,0 +1,15 @@
1
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
3
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="45" height="45">
4
<g style="fill:#ffffff;stroke:#000000;stroke-width:1.5;stroke-linejoin:round">
5
<path d="M 9,26 C 17.5,24.5 30,24.5 36,26 L 38.5,13.5 L 31,25 L 30.7,10.9 L 25.5,24.5 L 22.5,10 L 19.5,24.5 L 14.3,10.9 L 14,25 L 6.5,13.5 L 9,26 z"/>
6
<path d="M 9,26 C 9,28 10.5,28 11.5,30 C 12.5,31.5 12.5,31 12,33.5 C 10.5,34.5 11,36 11,36 C 9.5,37.5 11,38.5 11,38.5 C 17.5,39.5 27.5,39.5 34,38.5 C 34,38.5 35.5,37.5 34,36 C 34,36 34.5,34.5 33,33.5 C 32.5,31 32.5,31.5 33.5,30 C 34.5,28 36,28 36,26 C 27.5,24.5 17.5,24.5 9,26 z"/>
7
<path d="M 11.5,30 C 15,29 30,29 33.5,30" style="fill:none"/>
8
<path d="M 12,33.5 C 18,32.5 27,32.5 33,33.5" style="fill:none"/>
9
<circle cx="6" cy="12" r="2" />
10
<circle cx="14" cy="9" r="2" />
11
<circle cx="22.5" cy="8" r="2" />
12
<circle cx="31" cy="9" r="2" />
13
<circle cx="39" cy="12" r="2" />
14
</g>
15
</svg>
@@ -0,0 +1,15 @@1
<?xml version="1.0" encoding="UTF-8" standalone="no"?>2
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">3
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="45" height="45">4
<g style="fill:#ffffff;stroke:#000000;stroke-width:1.5;stroke-linejoin:round">5
<path d="M 9,26 C 17.5,24.5 30,24.5 36,26 L 38.5,13.5 L 31,25 L 30.7,10.9 L 25.5,24.5 L 22.5,10 L 19.5,24.5 L 14.3,10.9 L 14,25 L 6.5,13.5 L 9,26 z"/>6
<path d="M 9,26 C 9,28 10.5,28 11.5,30 C 12.5,31.5 12.5,31 12,33.5 C 10.5,34.5 11,36 11,36 C 9.5,37.5 11,38.5 11,38.5 C 17.5,39.5 27.5,39.5 34,38.5 C 34,38.5 35.5,37.5 34,36 C 34,36 34.5,34.5 33,33.5 C 32.5,31 32.5,31.5 33.5,30 C 34.5,28 36,28 36,26 C 27.5,24.5 17.5,24.5 9,26 z"/>7
<path d="M 11.5,30 C 15,29 30,29 33.5,30" style="fill:none"/>8
<path d="M 12,33.5 C 18,32.5 27,32.5 33,33.5" style="fill:none"/>9
<circle cx="6" cy="12" r="2" />10
<circle cx="14" cy="9" r="2" />11
<circle cx="22.5" cy="8" r="2" />12
<circle cx="31" cy="9" r="2" />13
<circle cx="39" cy="12" r="2" />14
</g>15
</svg>The contents of this binary file are not shown.
@@ -0,0 +1,25 @@
1
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
3
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="45" height="45">
4
<g style="opacity:1; fill:#ffffff; fill-opacity:1; fill-rule:evenodd; stroke:#000000; stroke-width:1.5; stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;" transform="translate(0,0.3)">
5
<path
6
d="M 9,39 L 36,39 L 36,36 L 9,36 L 9,39 z "
7
style="stroke-linecap:butt;" />
8
<path
9
d="M 12,36 L 12,32 L 33,32 L 33,36 L 12,36 z "
10
style="stroke-linecap:butt;" />
11
<path
12
d="M 11,14 L 11,9 L 15,9 L 15,11 L 20,11 L 20,9 L 25,9 L 25,11 L 30,11 L 30,9 L 34,9 L 34,14"
13
style="stroke-linecap:butt;" />
14
<path
15
d="M 34,14 L 31,17 L 14,17 L 11,14" />
16
<path
17
d="M 31,17 L 31,29.5 L 14,29.5 L 14,17"
18
style="stroke-linecap:butt; stroke-linejoin:miter;" />
19
<path
20
d="M 31,29.5 L 32.5,32 L 12.5,32 L 14,29.5" />
21
<path
22
d="M 11,14 L 34,14"
23
style="fill:none; stroke:#000000; stroke-linejoin:miter;" />
24
</g>
25
</svg>
@@ -0,0 +1,25 @@1
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
3
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="45" height="45">
4
<g style="opacity:1; fill:#ffffff; fill-opacity:1; fill-rule:evenodd; stroke:#000000; stroke-width:1.5; stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;" transform="translate(0,0.3)">
5
<path
6
d="M 9,39 L 36,39 L 36,36 L 9,36 L 9,39 z "
7
style="stroke-linecap:butt;" />
8
<path
9
d="M 12,36 L 12,32 L 33,32 L 33,36 L 12,36 z "
10
style="stroke-linecap:butt;" />
11
<path
12
d="M 11,14 L 11,9 L 15,9 L 15,11 L 20,11 L 20,9 L 25,9 L 25,11 L 30,11 L 30,9 L 34,9 L 34,14"
13
style="stroke-linecap:butt;" />
14
<path
15
d="M 34,14 L 31,17 L 14,17 L 11,14" />
16
<path
17
d="M 31,17 L 31,29.5 L 14,29.5 L 14,17"
18
style="stroke-linecap:butt; stroke-linejoin:miter;" />
19
<path
20
d="M 31,29.5 L 32.5,32 L 12.5,32 L 14,29.5" />
21
<path
22
d="M 11,14 L 34,14"
23
style="fill:none; stroke:#000000; stroke-linejoin:miter;" />
24
</g>
25
</svg>
@@ -0,0 +1,124 @@
1
<?php
2
declare(strict_types=1);
3
4
const PIECE_COLORS = ['White', 'Black', 'Red', 'Blue', 'Green', 'Yellow'];
5
6
function defaultPieceColorPrefs(): array
7
{
8
return ['color_mode' => 'default', 'preferred_color' => 'White', 'alternative_color' => 'Black'];
9
}
10
11
function pieceColorPrefs(string $userId): array
12
{
13
$row = query('SELECT color_mode, preferred_color, alternative_color FROM user_piece_colors WHERE user_id=?', [$userId])->fetch();
14
return $row ?: defaultPieceColorPrefs();
15
}
16
17
function validatePieceColors(string $mode, string $preferred, string $alternative): void
18
{
19
if (!in_array($mode, ['default', 'custom'], true)) {
20
throw new DomainException('Choose default or custom colours.');
21
}
22
if (!in_array($preferred, PIECE_COLORS, true) || !in_array($alternative, PIECE_COLORS, true)) {
23
throw new DomainException('Choose colours from White, Black, Red, Blue, Green or Yellow.');
24
}
25
if ($preferred === $alternative) {
26
throw new DomainException('Preferred and alternative colours must differ.');
27
}
28
}
29
30
function savePieceColorPrefs(string $userId, string $mode, string $preferred, string $alternative): void
31
{
32
validatePieceColors($mode, $preferred, $alternative);
33
query(
34
'INSERT INTO user_piece_colors(user_id,color_mode,preferred_color,alternative_color) VALUES(?,?,?,?)
35
ON CONFLICT(user_id) DO UPDATE SET color_mode=excluded.color_mode, preferred_color=excluded.preferred_color, alternative_color=excluded.alternative_color',
36
[$userId, $mode, $preferred, $alternative]
37
);
38
}
39
40
function effectivePreferredColor(array $prefs, string $rulesColour): string
41
{
42
return ($prefs['color_mode'] ?? 'default') === 'default' ? $rulesColour : $prefs['preferred_color'];
43
}
44
45
function nextDistinctPieceColor(string $from, string $skip): string
46
{
47
$i = array_search($from, PIECE_COLORS, true);
48
if ($i === false) {
49
$i = 0;
50
}
51
for ($n = 0; $n < count(PIECE_COLORS); $n++) {
52
$i = ($i + 1) % count(PIECE_COLORS);
53
if (PIECE_COLORS[$i] !== $skip) {
54
return PIECE_COLORS[$i];
55
}
56
}
57
throw new RuntimeException('Unable to pick a distinct piece colour.');
58
}
59
60
/**
61
* Resolve display skins for the white and black rules sides.
62
* @param null|callable():int $coinFlip returns 0 or 1; injectable for tests
63
* @return array{white:string,black:string}
64
*/
65
function resolvePieceSkins(array $whitePrefs, array $blackPrefs, ?callable $coinFlip = null): array
66
{
67
$coinFlip ??= static fn(): int => random_int(0, 1);
68
$whiteWant = effectivePreferredColor($whitePrefs, 'White');
69
$blackWant = effectivePreferredColor($blackPrefs, 'Black');
70
if ($whiteWant !== $blackWant) {
71
return ['white' => $whiteWant, 'black' => $blackWant];
72
}
73
74
$whiteMode = $whitePrefs['color_mode'] ?? 'default';
75
$blackMode = $blackPrefs['color_mode'] ?? 'default';
76
77
if ($whiteMode === 'default' && $blackMode === 'custom') {
78
$alt = $blackPrefs['alternative_color'];
79
if ($alt === $whiteWant) {
80
$alt = nextDistinctPieceColor($alt, $whiteWant);
81
}
82
return ['white' => $whiteWant, 'black' => $alt];
83
}
84
if ($blackMode === 'default' && $whiteMode === 'custom') {
85
$alt = $whitePrefs['alternative_color'];
86
if ($alt === $blackWant) {
87
$alt = nextDistinctPieceColor($alt, $blackWant);
88
}
89
return ['white' => $alt, 'black' => $blackWant];
90
}
91
92
// Both custom (or residual conflict): randomly pick who keeps preferred.
93
if ($coinFlip()) {
94
$alt = $blackPrefs['alternative_color'];
95
if ($alt === $whiteWant) {
96
$alt = nextDistinctPieceColor($alt, $whiteWant);
97
}
98
return ['white' => $whiteWant, 'black' => $alt];
99
}
100
$alt = $whitePrefs['alternative_color'];
101
if ($alt === $blackWant) {
102
$alt = nextDistinctPieceColor($alt, $blackWant);
103
}
104
return ['white' => $alt, 'black' => $blackWant];
105
}
106
107
function assignGamePieceSkins(int $gameId, string $whiteId, string $blackId): void
108
{
109
$skins = resolvePieceSkins(pieceColorPrefs($whiteId), pieceColorPrefs($blackId));
110
query('UPDATE games SET piece_skin_white=?, piece_skin_black=? WHERE id=?', [$skins['white'], $skins['black'], $gameId]);
111
}
112
113
function gamePieceSkins(array $g): array
114
{
115
$white = $g['piece_skin_white'] ?? null;
116
$black = $g['piece_skin_black'] ?? null;
117
if (!is_string($white) || $white === '' || !in_array($white, PIECE_COLORS, true)) {
118
$white = 'White';
119
}
120
if (!is_string($black) || $black === '' || !in_array($black, PIECE_COLORS, true)) {
121
$black = 'Black';
122
}
123
return ['white' => $white, 'black' => $black];
124
}
@@ -0,0 +1,124 @@1
<?php2
declare(strict_types=1);3
4
const PIECE_COLORS = ['White', 'Black', 'Red', 'Blue', 'Green', 'Yellow'];5
6
function defaultPieceColorPrefs(): array7
{8
return ['color_mode' => 'default', 'preferred_color' => 'White', 'alternative_color' => 'Black'];9
}10
11
function pieceColorPrefs(string $userId): array12
{13
$row = query('SELECT color_mode, preferred_color, alternative_color FROM user_piece_colors WHERE user_id=?', [$userId])->fetch();14
return $row ?: defaultPieceColorPrefs();15
}16
17
function validatePieceColors(string $mode, string $preferred, string $alternative): void18
{19
if (!in_array($mode, ['default', 'custom'], true)) {20
throw new DomainException('Choose default or custom colours.');21
}22
if (!in_array($preferred, PIECE_COLORS, true) || !in_array($alternative, PIECE_COLORS, true)) {23
throw new DomainException('Choose colours from White, Black, Red, Blue, Green or Yellow.');24
}25
if ($preferred === $alternative) {26
throw new DomainException('Preferred and alternative colours must differ.');27
}28
}29
30
function savePieceColorPrefs(string $userId, string $mode, string $preferred, string $alternative): void31
{32
validatePieceColors($mode, $preferred, $alternative);33
query(34
'INSERT INTO user_piece_colors(user_id,color_mode,preferred_color,alternative_color) VALUES(?,?,?,?)35
ON CONFLICT(user_id) DO UPDATE SET color_mode=excluded.color_mode, preferred_color=excluded.preferred_color, alternative_color=excluded.alternative_color',36
[$userId, $mode, $preferred, $alternative]37
);38
}39
40
function effectivePreferredColor(array $prefs, string $rulesColour): string41
{42
return ($prefs['color_mode'] ?? 'default') === 'default' ? $rulesColour : $prefs['preferred_color'];43
}44
45
function nextDistinctPieceColor(string $from, string $skip): string46
{47
$i = array_search($from, PIECE_COLORS, true);48
if ($i === false) {49
$i = 0;50
}51
for ($n = 0; $n < count(PIECE_COLORS); $n++) {52
$i = ($i + 1) % count(PIECE_COLORS);53
if (PIECE_COLORS[$i] !== $skip) {54
return PIECE_COLORS[$i];55
}56
}57
throw new RuntimeException('Unable to pick a distinct piece colour.');58
}59
60
/**61
* Resolve display skins for the white and black rules sides.62
* @param null|callable():int $coinFlip returns 0 or 1; injectable for tests63
* @return array{white:string,black:string}64
*/65
function resolvePieceSkins(array $whitePrefs, array $blackPrefs, ?callable $coinFlip = null): array66
{67
$coinFlip ??= static fn(): int => random_int(0, 1);68
$whiteWant = effectivePreferredColor($whitePrefs, 'White');69
$blackWant = effectivePreferredColor($blackPrefs, 'Black');70
if ($whiteWant !== $blackWant) {71
return ['white' => $whiteWant, 'black' => $blackWant];72
}73
74
$whiteMode = $whitePrefs['color_mode'] ?? 'default';75
$blackMode = $blackPrefs['color_mode'] ?? 'default';76
77
if ($whiteMode === 'default' && $blackMode === 'custom') {78
$alt = $blackPrefs['alternative_color'];79
if ($alt === $whiteWant) {80
$alt = nextDistinctPieceColor($alt, $whiteWant);81
}82
return ['white' => $whiteWant, 'black' => $alt];83
}84
if ($blackMode === 'default' && $whiteMode === 'custom') {85
$alt = $whitePrefs['alternative_color'];86
if ($alt === $blackWant) {87
$alt = nextDistinctPieceColor($alt, $blackWant);88
}89
return ['white' => $alt, 'black' => $blackWant];90
}91
92
// Both custom (or residual conflict): randomly pick who keeps preferred.93
if ($coinFlip()) {94
$alt = $blackPrefs['alternative_color'];95
if ($alt === $whiteWant) {96
$alt = nextDistinctPieceColor($alt, $whiteWant);97
}98
return ['white' => $whiteWant, 'black' => $alt];99
}100
$alt = $whitePrefs['alternative_color'];101
if ($alt === $blackWant) {102
$alt = nextDistinctPieceColor($alt, $blackWant);103
}104
return ['white' => $alt, 'black' => $blackWant];105
}106
107
function assignGamePieceSkins(int $gameId, string $whiteId, string $blackId): void108
{109
$skins = resolvePieceSkins(pieceColorPrefs($whiteId), pieceColorPrefs($blackId));110
query('UPDATE games SET piece_skin_white=?, piece_skin_black=? WHERE id=?', [$skins['white'], $skins['black'], $gameId]);111
}112
113
function gamePieceSkins(array $g): array114
{115
$white = $g['piece_skin_white'] ?? null;116
$black = $g['piece_skin_black'] ?? null;117
if (!is_string($white) || $white === '' || !in_array($white, PIECE_COLORS, true)) {118
$white = 'White';119
}120
if (!is_string($black) || $black === '' || !in_array($black, PIECE_COLORS, true)) {121
$black = 'Black';122
}123
return ['white' => $white, 'black' => $black];124
}@@ -3,6 +3,7 @@ declare(strict_types=1);
3
3
require_once __DIR__.'/Chess.php';
4
4
require_once __DIR__.'/MoveFeedback.php';
5
5
require_once __DIR__.'/Push.php';
6
require_once __DIR__.'/PieceColors.php';
6
7
ini_set('display_errors','0');
7
8
ini_set('log_errors','1');
8
9
ini_set('error_log',dirname(__DIR__).'/data/php-errors.log');
@@ -64,6 +65,40 @@ function db(): PDO {
64
65
$db->exec('CREATE TABLE IF NOT EXISTS replays (result_id INTEGER PRIMARY KEY REFERENCES results(id), white TEXT NOT NULL, moves BLOB NOT NULL);
65
66
CREATE INDEX IF NOT EXISTS results_ended ON results(ended);
66
67
CREATE TABLE IF NOT EXISTS replay_links (result_id INTEGER PRIMARY KEY REFERENCES replays(result_id), token TEXT NOT NULL UNIQUE);');
68
$db->exec('CREATE TABLE IF NOT EXISTS user_piece_colors (
69
user_id TEXT PRIMARY KEY REFERENCES users(id),
70
color_mode TEXT NOT NULL DEFAULT \'default\' CHECK(color_mode IN (\'default\',\'custom\')),
71
preferred_color TEXT NOT NULL DEFAULT \'White\',
72
alternative_color TEXT NOT NULL DEFAULT \'Black\',
73
CHECK(preferred_color IN (\'White\',\'Black\',\'Red\',\'Blue\',\'Green\',\'Yellow\')),
74
CHECK(alternative_color IN (\'White\',\'Black\',\'Red\',\'Blue\',\'Green\',\'Yellow\')),
75
CHECK(preferred_color <> alternative_color)
76
);');
77
$gameCols=$db->query('PRAGMA table_info(games)')->fetchAll(PDO::FETCH_COLUMN,1);
78
if (!in_array('piece_skin_white',$gameCols,true)) {
79
$db->exec('BEGIN IMMEDIATE');
80
try {
81
$gameCols=$db->query('PRAGMA table_info(games)')->fetchAll(PDO::FETCH_COLUMN,1);
82
if (!in_array('piece_skin_white',$gameCols,true)) {
83
$db->exec('ALTER TABLE games ADD COLUMN piece_skin_white TEXT');
84
$db->exec('ALTER TABLE games ADD COLUMN piece_skin_black TEXT');
85
}
86
$db->exec('COMMIT');
87
} catch (Throwable $e) { $db->exec('ROLLBACK');throw $e; }
88
}
89
$replayCols=$db->query('PRAGMA table_info(replays)')->fetchAll(PDO::FETCH_COLUMN,1);
90
if (!in_array('piece_skin_white',$replayCols,true)) {
91
$db->exec('BEGIN IMMEDIATE');
92
try {
93
$replayCols=$db->query('PRAGMA table_info(replays)')->fetchAll(PDO::FETCH_COLUMN,1);
94
if (!in_array('piece_skin_white',$replayCols,true)) {
95
$db->exec('ALTER TABLE replays ADD COLUMN piece_skin_white TEXT');
96
$db->exec('ALTER TABLE replays ADD COLUMN piece_skin_black TEXT');
97
}
98
$db->exec('COMMIT');
99
} catch (Throwable $e) { $db->exec('ROLLBACK');throw $e; }
100
}
101
67
102
if (!in_array('turn_order',$db->query('PRAGMA table_info(games)')->fetchAll(PDO::FETCH_COLUMN,1),true)) {
68
103
$db->exec('BEGIN IMMEDIATE');
69
104
try {
@@ -83,6 +118,7 @@ function db(): PDO {
83
118
try {saveReplay((int)$r['id'],$r['white'],$position);} catch (PDOException $e) {if ($e->getCode()!=='23000') throw $e;}
84
119
}
85
120
}
121
86
122
return $db;
87
123
}
88
124
function activityTriggers(PDO $db): void {
@@ -91,7 +127,8 @@ function activityTriggers(PDO $db): void {
91
127
}
92
128
function query(string $sql,array $args=[]): PDOStatement { $s=db()->prepare($sql);$s->execute($args);return $s; }
93
129
function profile(string $id): array {
94
return query('SELECT u.*,a.avatar,COALESCE(r.rating,1200) AS rating,COALESCE(r.played,0) AS ratedGames FROM users u LEFT JOIN user_avatars a ON a.user_id=u.id LEFT JOIN ratings r ON r.user_id=u.id WHERE u.id=?',[$id])->fetch();
130
$p=query('SELECT u.*,a.avatar,COALESCE(r.rating,1200) AS rating,COALESCE(r.played,0) AS ratedGames,COALESCE(c.color_mode,\'default\') AS colorMode,COALESCE(c.preferred_color,\'White\') AS preferredColor,COALESCE(c.alternative_color,\'Black\') AS alternativeColor FROM users u LEFT JOIN user_avatars a ON a.user_id=u.id LEFT JOIN ratings r ON r.user_id=u.id LEFT JOIN user_piece_colors c ON c.user_id=u.id WHERE u.id=?',[$id])->fetch();
131
return $p;
95
132
}
96
133
function avatarCatalog(): array {
97
134
static $avatars;
@@ -198,7 +235,7 @@ function befriend(string $a,string $b): void {
198
235
}
199
236
// Two bytes per ply: source square, destination square and resulting piece (promotion included).
200
237
// Only the initial board is stored in full; no repeated position snapshots.
201
function saveReplay(int $result,string $white,array $s): void {
238
function saveReplay(int $result,string $white,array $s,string $skinWhite='White',string $skinBlack='Black'): void {
202
239
$history=$s['history'];
203
240
$packed=substr($history[0],0,21);
204
241
$pieces='.prnbqkPRNBQK';
@@ -209,8 +246,8 @@ function saveReplay(int $result,string $white,array $s): void {
209
246
}
210
247
$packed.=pack('n',($from*20+$to)*13+strpos($pieces,$after[$to]));
211
248
}
212
$q=db()->prepare('INSERT INTO replays VALUES(?,?,?)');
213
$q->bindValue(1,$result);$q->bindValue(2,$white);$q->bindValue(3,$packed,PDO::PARAM_LOB);$q->execute();
249
$q=db()->prepare('INSERT INTO replays(result_id,white,moves,piece_skin_white,piece_skin_black) VALUES(?,?,?,?,?)');
250
$q->bindValue(1,$result);$q->bindValue(2,$white);$q->bindValue(3,$packed,PDO::PARAM_LOB);$q->bindValue(4,$skinWhite);$q->bindValue(5,$skinBlack);$q->execute();
214
251
query("UPDATE results SET state='{}' WHERE id=?",[$result]);
215
252
}
216
253
function replayLink(int $id): string {
@@ -238,7 +275,7 @@ function finishGame(array $g,?string $winner,string $reason,array $s): void {
238
275
if ($finished->rowCount()!==1) throw new DomainException('The game has changed. Please try again.');
239
276
query('INSERT INTO results(game_id,a,b,winner,reason,state,ended) VALUES(?,?,?,?,?,?,?)',[$g['id'],$g['a'],$g['b'],$winner,$reason,json_encode($s),time()]);
240
277
$result=(int)db()->lastInsertId();
241
saveReplay($result,$g['white'],$s);
278
$skins=gamePieceSkins($g);saveReplay($result,$g['white'],$s,$skins['white'],$skins['black']);
242
279
$a=(int)profile($g['a'])['rating'];$b=(int)profile($g['b'])['rating'];
243
280
$score=$winner===null?0.5:($winner===$g['a']?1:0);
244
281
$delta=(int)round(32*($score-1/(1+10**(($b-$a)/400))));
@@ -270,8 +307,10 @@ function matchPlayers(bool $force=false): void {
270
307
}
271
308
}
272
309
function startGame(string $a,string $b): int {
273
query("INSERT INTO games(a,b,status,white,state,created) VALUES(?,?,'active',?,?,?)",[$a,$b,random_int(0,1)?$a:$b,json_encode(Chess::initial()),time()]);
310
$white=random_int(0,1)?$a:$b;
311
query("INSERT INTO games(a,b,status,white,state,created) VALUES(?,?,'active',?,?,?)",[$a,$b,$white,json_encode(Chess::initial()),time()]);
274
312
$id=(int)db()->lastInsertId();
313
assignGamePieceSkins($id,$white,$white===$a?$b:$a);
275
314
pushGame($id);
276
315
return $id;
277
316
}
@@ -280,7 +319,10 @@ function gameView(array $g,string $u): array {
280
319
$opponent=profile($other);
281
320
$s=$g['state']?json_decode($g['state'],true):null;
282
321
$color=$g['white']===$u?'w':'b';
283
return ['id'=>(int)$g['id'],'turnOrder'=>(int)$g['turn_order'],'replayId'=>$g['status']==='ended'?(int)query('SELECT MAX(result_id) FROM replays JOIN results ON results.id=replays.result_id WHERE game_id=?',[$g['id']])->fetchColumn():null,'opponentId'=>$other,'rivalry'=>rivalry($u,$other),'opponent'=>$opponent['name'],'opponentAvatar'=>$opponent['avatar'],'opponentRating'=>(int)$opponent['rating'], 'status'=>$g['status'],'incoming'=>$g['b']===$u,'color'=>$color,
322
$skins=gamePieceSkins($g);
323
$displayColor=$color==='w'?$skins['white']:$skins['black'];
324
$opponentDisplayColor=$color==='w'?$skins['black']:$skins['white'];
325
return ['id'=>(int)$g['id'],'turnOrder'=>(int)$g['turn_order'],'replayId'=>$g['status']==='ended'?(int)query('SELECT MAX(result_id) FROM replays JOIN results ON results.id=replays.result_id WHERE game_id=?',[$g['id']])->fetchColumn():null,'opponentId'=>$other,'rivalry'=>rivalry($u,$other),'opponent'=>$opponent['name'],'opponentAvatar'=>$opponent['avatar'],'opponentRating'=>(int)$opponent['rating'], 'status'=>$g['status'],'incoming'=>$g['b']===$u,'color'=>$color,'displayColor'=>$displayColor,'opponentDisplayColor'=>$opponentDisplayColor,'pieceSkinWhite'=>$skins['white'],'pieceSkinBlack'=>$skins['black'],
284
326
'inactiveDays'=>max(0,(int)floor((time()-($g['activity_at']??time()))/86400)),
285
327
'outcome'=>$g['winner']===null?'draw':($g['winner']===$u?'win':'loss'),
286
328
'state'=>$s,'yourTurn'=>$g['status']==='active' && $s['turn']===$color,'legal'=>$g['status']==='active' && $s['turn']===$color?Chess::legal($s):[],
@@ -3,6 +3,7 @@ declare(strict_types=1);3
require_once __DIR__.'/Chess.php';3
require_once __DIR__.'/Chess.php';4
require_once __DIR__.'/MoveFeedback.php';4
require_once __DIR__.'/MoveFeedback.php';5
require_once __DIR__.'/Push.php';5
require_once __DIR__.'/Push.php';6
require_once __DIR__.'/PieceColors.php';6
ini_set('display_errors','0');7
ini_set('display_errors','0');7
ini_set('log_errors','1');8
ini_set('log_errors','1');8
ini_set('error_log',dirname(__DIR__).'/data/php-errors.log');9
ini_set('error_log',dirname(__DIR__).'/data/php-errors.log');@@ -64,6 +65,40 @@ function db(): PDO {64
$db->exec('CREATE TABLE IF NOT EXISTS replays (result_id INTEGER PRIMARY KEY REFERENCES results(id), white TEXT NOT NULL, moves BLOB NOT NULL);65
$db->exec('CREATE TABLE IF NOT EXISTS replays (result_id INTEGER PRIMARY KEY REFERENCES results(id), white TEXT NOT NULL, moves BLOB NOT NULL);65
CREATE INDEX IF NOT EXISTS results_ended ON results(ended);66
CREATE INDEX IF NOT EXISTS results_ended ON results(ended);66
CREATE TABLE IF NOT EXISTS replay_links (result_id INTEGER PRIMARY KEY REFERENCES replays(result_id), token TEXT NOT NULL UNIQUE);');67
CREATE TABLE IF NOT EXISTS replay_links (result_id INTEGER PRIMARY KEY REFERENCES replays(result_id), token TEXT NOT NULL UNIQUE);');68
$db->exec('CREATE TABLE IF NOT EXISTS user_piece_colors (69
user_id TEXT PRIMARY KEY REFERENCES users(id),70
color_mode TEXT NOT NULL DEFAULT \'default\' CHECK(color_mode IN (\'default\',\'custom\')),71
preferred_color TEXT NOT NULL DEFAULT \'White\',72
alternative_color TEXT NOT NULL DEFAULT \'Black\',73
CHECK(preferred_color IN (\'White\',\'Black\',\'Red\',\'Blue\',\'Green\',\'Yellow\')),74
CHECK(alternative_color IN (\'White\',\'Black\',\'Red\',\'Blue\',\'Green\',\'Yellow\')),75
CHECK(preferred_color <> alternative_color)76
);');77
$gameCols=$db->query('PRAGMA table_info(games)')->fetchAll(PDO::FETCH_COLUMN,1);78
if (!in_array('piece_skin_white',$gameCols,true)) {79
$db->exec('BEGIN IMMEDIATE');80
try {81
$gameCols=$db->query('PRAGMA table_info(games)')->fetchAll(PDO::FETCH_COLUMN,1);82
if (!in_array('piece_skin_white',$gameCols,true)) {83
$db->exec('ALTER TABLE games ADD COLUMN piece_skin_white TEXT');84
$db->exec('ALTER TABLE games ADD COLUMN piece_skin_black TEXT');85
}86
$db->exec('COMMIT');87
} catch (Throwable $e) { $db->exec('ROLLBACK');throw $e; }88
}89
$replayCols=$db->query('PRAGMA table_info(replays)')->fetchAll(PDO::FETCH_COLUMN,1);90
if (!in_array('piece_skin_white',$replayCols,true)) {91
$db->exec('BEGIN IMMEDIATE');92
try {93
$replayCols=$db->query('PRAGMA table_info(replays)')->fetchAll(PDO::FETCH_COLUMN,1);94
if (!in_array('piece_skin_white',$replayCols,true)) {95
$db->exec('ALTER TABLE replays ADD COLUMN piece_skin_white TEXT');96
$db->exec('ALTER TABLE replays ADD COLUMN piece_skin_black TEXT');97
}98
$db->exec('COMMIT');99
} catch (Throwable $e) { $db->exec('ROLLBACK');throw $e; }100
}101
67
if (!in_array('turn_order',$db->query('PRAGMA table_info(games)')->fetchAll(PDO::FETCH_COLUMN,1),true)) {102
if (!in_array('turn_order',$db->query('PRAGMA table_info(games)')->fetchAll(PDO::FETCH_COLUMN,1),true)) {68
$db->exec('BEGIN IMMEDIATE');103
$db->exec('BEGIN IMMEDIATE');69
try {104
try {@@ -83,6 +118,7 @@ function db(): PDO {83
try {saveReplay((int)$r['id'],$r['white'],$position);} catch (PDOException $e) {if ($e->getCode()!=='23000') throw $e;}118
try {saveReplay((int)$r['id'],$r['white'],$position);} catch (PDOException $e) {if ($e->getCode()!=='23000') throw $e;}84
}119
}85
}120
}121
86
return $db;122
return $db;87
}123
}88
function activityTriggers(PDO $db): void {124
function activityTriggers(PDO $db): void {@@ -91,7 +127,8 @@ function activityTriggers(PDO $db): void {91
}127
}92
function query(string $sql,array $args=[]): PDOStatement { $s=db()->prepare($sql);$s->execute($args);return $s; }128
function query(string $sql,array $args=[]): PDOStatement { $s=db()->prepare($sql);$s->execute($args);return $s; }93
function profile(string $id): array {129
function profile(string $id): array {94
return query('SELECT u.*,a.avatar,COALESCE(r.rating,1200) AS rating,COALESCE(r.played,0) AS ratedGames FROM users u LEFT JOIN user_avatars a ON a.user_id=u.id LEFT JOIN ratings r ON r.user_id=u.id WHERE u.id=?',[$id])->fetch();130
$p=query('SELECT u.*,a.avatar,COALESCE(r.rating,1200) AS rating,COALESCE(r.played,0) AS ratedGames,COALESCE(c.color_mode,\'default\') AS colorMode,COALESCE(c.preferred_color,\'White\') AS preferredColor,COALESCE(c.alternative_color,\'Black\') AS alternativeColor FROM users u LEFT JOIN user_avatars a ON a.user_id=u.id LEFT JOIN ratings r ON r.user_id=u.id LEFT JOIN user_piece_colors c ON c.user_id=u.id WHERE u.id=?',[$id])->fetch();131
return $p;95
}132
}96
function avatarCatalog(): array {133
function avatarCatalog(): array {97
static $avatars;134
static $avatars;@@ -198,7 +235,7 @@ function befriend(string $a,string $b): void {198
}235
}199
// Two bytes per ply: source square, destination square and resulting piece (promotion included).236
// Two bytes per ply: source square, destination square and resulting piece (promotion included).200
// Only the initial board is stored in full; no repeated position snapshots.237
// Only the initial board is stored in full; no repeated position snapshots.201
function saveReplay(int $result,string $white,array $s): void {238
function saveReplay(int $result,string $white,array $s,string $skinWhite='White',string $skinBlack='Black'): void {202
$history=$s['history'];239
$history=$s['history'];203
$packed=substr($history[0],0,21);240
$packed=substr($history[0],0,21);204
$pieces='.prnbqkPRNBQK';241
$pieces='.prnbqkPRNBQK';@@ -209,8 +246,8 @@ function saveReplay(int $result,string $white,array $s): void {209
}246
}210
$packed.=pack('n',($from*20+$to)*13+strpos($pieces,$after[$to]));247
$packed.=pack('n',($from*20+$to)*13+strpos($pieces,$after[$to]));211
}248
}212
$q=db()->prepare('INSERT INTO replays VALUES(?,?,?)');249
$q=db()->prepare('INSERT INTO replays(result_id,white,moves,piece_skin_white,piece_skin_black) VALUES(?,?,?,?,?)');213
$q->bindValue(1,$result);$q->bindValue(2,$white);$q->bindValue(3,$packed,PDO::PARAM_LOB);$q->execute();250
$q->bindValue(1,$result);$q->bindValue(2,$white);$q->bindValue(3,$packed,PDO::PARAM_LOB);$q->bindValue(4,$skinWhite);$q->bindValue(5,$skinBlack);$q->execute();214
query("UPDATE results SET state='{}' WHERE id=?",[$result]);251
query("UPDATE results SET state='{}' WHERE id=?",[$result]);215
}252
}216
function replayLink(int $id): string {253
function replayLink(int $id): string {@@ -238,7 +275,7 @@ function finishGame(array $g,?string $winner,string $reason,array $s): void {238
if ($finished->rowCount()!==1) throw new DomainException('The game has changed. Please try again.');275
if ($finished->rowCount()!==1) throw new DomainException('The game has changed. Please try again.');239
query('INSERT INTO results(game_id,a,b,winner,reason,state,ended) VALUES(?,?,?,?,?,?,?)',[$g['id'],$g['a'],$g['b'],$winner,$reason,json_encode($s),time()]);276
query('INSERT INTO results(game_id,a,b,winner,reason,state,ended) VALUES(?,?,?,?,?,?,?)',[$g['id'],$g['a'],$g['b'],$winner,$reason,json_encode($s),time()]);240
$result=(int)db()->lastInsertId();277
$result=(int)db()->lastInsertId();241
saveReplay($result,$g['white'],$s);278
$skins=gamePieceSkins($g);saveReplay($result,$g['white'],$s,$skins['white'],$skins['black']);242
$a=(int)profile($g['a'])['rating'];$b=(int)profile($g['b'])['rating'];279
$a=(int)profile($g['a'])['rating'];$b=(int)profile($g['b'])['rating'];243
$score=$winner===null?0.5:($winner===$g['a']?1:0);280
$score=$winner===null?0.5:($winner===$g['a']?1:0);244
$delta=(int)round(32*($score-1/(1+10**(($b-$a)/400))));281
$delta=(int)round(32*($score-1/(1+10**(($b-$a)/400))));@@ -270,8 +307,10 @@ function matchPlayers(bool $force=false): void {270
}307
}271
}308
}272
function startGame(string $a,string $b): int {309
function startGame(string $a,string $b): int {273
query("INSERT INTO games(a,b,status,white,state,created) VALUES(?,?,'active',?,?,?)",[$a,$b,random_int(0,1)?$a:$b,json_encode(Chess::initial()),time()]);310
$white=random_int(0,1)?$a:$b;311
query("INSERT INTO games(a,b,status,white,state,created) VALUES(?,?,'active',?,?,?)",[$a,$b,$white,json_encode(Chess::initial()),time()]);274
$id=(int)db()->lastInsertId();312
$id=(int)db()->lastInsertId();313
assignGamePieceSkins($id,$white,$white===$a?$b:$a);275
pushGame($id);314
pushGame($id);276
return $id;315
return $id;277
}316
}@@ -280,7 +319,10 @@ function gameView(array $g,string $u): array {280
$opponent=profile($other);319
$opponent=profile($other);281
$s=$g['state']?json_decode($g['state'],true):null;320
$s=$g['state']?json_decode($g['state'],true):null;282
$color=$g['white']===$u?'w':'b';321
$color=$g['white']===$u?'w':'b';283
return ['id'=>(int)$g['id'],'turnOrder'=>(int)$g['turn_order'],'replayId'=>$g['status']==='ended'?(int)query('SELECT MAX(result_id) FROM replays JOIN results ON results.id=replays.result_id WHERE game_id=?',[$g['id']])->fetchColumn():null,'opponentId'=>$other,'rivalry'=>rivalry($u,$other),'opponent'=>$opponent['name'],'opponentAvatar'=>$opponent['avatar'],'opponentRating'=>(int)$opponent['rating'], 'status'=>$g['status'],'incoming'=>$g['b']===$u,'color'=>$color,322
$skins=gamePieceSkins($g);323
$displayColor=$color==='w'?$skins['white']:$skins['black'];324
$opponentDisplayColor=$color==='w'?$skins['black']:$skins['white'];325
return ['id'=>(int)$g['id'],'turnOrder'=>(int)$g['turn_order'],'replayId'=>$g['status']==='ended'?(int)query('SELECT MAX(result_id) FROM replays JOIN results ON results.id=replays.result_id WHERE game_id=?',[$g['id']])->fetchColumn():null,'opponentId'=>$other,'rivalry'=>rivalry($u,$other),'opponent'=>$opponent['name'],'opponentAvatar'=>$opponent['avatar'],'opponentRating'=>(int)$opponent['rating'], 'status'=>$g['status'],'incoming'=>$g['b']===$u,'color'=>$color,'displayColor'=>$displayColor,'opponentDisplayColor'=>$opponentDisplayColor,'pieceSkinWhite'=>$skins['white'],'pieceSkinBlack'=>$skins['black'],284
'inactiveDays'=>max(0,(int)floor((time()-($g['activity_at']??time()))/86400)),326
'inactiveDays'=>max(0,(int)floor((time()-($g['activity_at']??time()))/86400)),285
'outcome'=>$g['winner']===null?'draw':($g['winner']===$u?'win':'loss'),327
'outcome'=>$g['winner']===null?'draw':($g['winner']===$u?'win':'loss'),286
'state'=>$s,'yourTurn'=>$g['status']==='active' && $s['turn']===$color,'legal'=>$g['status']==='active' && $s['turn']===$color?Chess::legal($s):[],328
'state'=>$s,'yourTurn'=>$g['status']==='active' && $s['turn']===$color,'legal'=>$g['status']==='active' && $s['turn']===$color?Chess::legal($s):[],@@ -73,6 +73,10 @@ try{
73
73
await a.locator('[data-avatar-choice="blue-knight"]').waitFor();
74
74
75
75
await a.locator('[data-avatar-group="standard"]').click();
76
await a.locator('#avatar-color').selectOption('White');
77
assert.equal(await a.locator('.avatar-choice').count(),6,'Six white standard chess pieces');
78
await a.locator('#avatar-color').selectOption('Black');
79
assert.equal(await a.locator('.avatar-choice').count(),6,'Six black standard chess pieces');
76
80
await a.locator('#avatar-color').selectOption('Blue');
77
81
assert.equal(await a.locator('.avatar-choice').count(),6,'Six blue standard chess pieces');
78
82
await a.screenshot({path:path.join(web,'tests/artifacts/avatar-picker-desktop.png')});
@@ -73,6 +73,10 @@ try{73
await a.locator('[data-avatar-choice="blue-knight"]').waitFor();73
await a.locator('[data-avatar-choice="blue-knight"]').waitFor();74
74
75
await a.locator('[data-avatar-group="standard"]').click();75
await a.locator('[data-avatar-group="standard"]').click();76
await a.locator('#avatar-color').selectOption('White');77
assert.equal(await a.locator('.avatar-choice').count(),6,'Six white standard chess pieces');78
await a.locator('#avatar-color').selectOption('Black');79
assert.equal(await a.locator('.avatar-choice').count(),6,'Six black standard chess pieces');76
await a.locator('#avatar-color').selectOption('Blue');80
await a.locator('#avatar-color').selectOption('Blue');77
assert.equal(await a.locator('.avatar-choice').count(),6,'Six blue standard chess pieces');81
assert.equal(await a.locator('.avatar-choice').count(),6,'Six blue standard chess pieces');78
await a.screenshot({path:path.join(web,'tests/artifacts/avatar-picker-desktop.png')});82
await a.screenshot({path:path.join(web,'tests/artifacts/avatar-picker-desktop.png')});@@ -0,0 +1,61 @@
1
<?php
2
declare(strict_types=1);
3
require dirname(__DIR__).'/lib/PieceColors.php';
4
5
// Stub query()/db() unused by pure resolve helpers.
6
$checks=0;
7
function check(bool $condition,string $label): void {global $checks;$checks++;if(!$condition)throw new RuntimeException($label);}
8
9
function prefs(string $mode,string $preferred,string $alternative): array {
10
return ['color_mode'=>$mode,'preferred_color'=>$preferred,'alternative_color'=>$alternative];
11
}
12
13
// No conflict: both default on opposite rules sides.
14
$r=resolvePieceSkins(prefs('default','White','Black'),prefs('default','White','Black'));
15
check($r===['white'=>'White','black'=>'Black'],'Both default keep rules colours');
16
17
// No conflict: custom preferreds differ.
18
$r=resolvePieceSkins(prefs('custom','Red','Blue'),prefs('custom','Green','Yellow'));
19
check($r===['white'=>'Red','black'=>'Green'],'Different custom preferreds');
20
21
// Default vs custom conflict: default keeps rules colour; custom uses alternative.
22
$r=resolvePieceSkins(prefs('default','White','Black'),prefs('custom','White','Red'));
23
check($r===['white'=>'White','black'=>'Red'],'Black custom yields to alternative when conflicting with default White');
24
25
$r=resolvePieceSkins(prefs('custom','Black','Blue'),prefs('default','White','Black'));
26
check($r===['white'=>'Blue','black'=>'Black'],'White custom yields to alternative when conflicting with default Black');
27
28
// Default vs custom with broken alternative equal to default colour: cycle further.
29
$r=resolvePieceSkins(prefs('default','White','Black'),prefs('custom','White','White'));
30
// validatePieceColors would reject equal prefs; resolution still cycles if alternative equals.
31
// Here alternative equals preferred (invalid), but also equals whiteWant; nextDistinct from White skip White -> Black
32
check($r['white']==='White' && $r['black']!=='White','Cycled alternative when equal to default colour');
33
34
// Both custom same preferred: coin flip 1 => white keeps, black takes alternative
35
$r=resolvePieceSkins(prefs('custom','Red','Blue'),prefs('custom','Red','Green'),fn()=>1);
36
check($r===['white'=>'Red','black'=>'Green'],'Both custom conflict: white keeps when coin=1');
37
38
$r=resolvePieceSkins(prefs('custom','Red','Blue'),prefs('custom','Red','Green'),fn()=>0);
39
check($r===['white'=>'Blue','black'=>'Red'],'Both custom conflict: black keeps when coin=0');
40
41
// Custom preferred matches other side's rules/default without being same mode conflict path already covered.
42
$r=resolvePieceSkins(prefs('custom','Black','Red'),prefs('custom','White','Blue'));
43
check($r===['white'=>'Black','black'=>'White'],'Cross-coloured customs with no clash');
44
45
// effectivePreferred
46
check(effectivePreferredColor(prefs('default','Red','Blue'),'White')==='White','Default mode uses rules colour');
47
check(effectivePreferredColor(prefs('custom','Red','Blue'),'White')==='Red','Custom mode uses preferred');
48
49
// nextDistinct
50
check(nextDistinctPieceColor('White','Black')==='Red','Cycle White skip Black -> Red');
51
check(nextDistinctPieceColor('Yellow','White')==='Black','Cycle Yellow wrap skip White -> Black');
52
check(nextDistinctPieceColor('Red','Blue')==='Green','Cycle Red skip Blue -> Green');
53
54
// Validation
55
try {validatePieceColors('nope','White','Black');check(false,'bad mode');} catch(DomainException){check(true,'bad mode rejected');}
56
try {validatePieceColors('custom','Purple','Black');check(false,'bad colour');} catch(DomainException){check(true,'bad colour rejected');}
57
try {validatePieceColors('custom','Red','Red');check(false,'same colours');} catch(DomainException){check(true,'same colours rejected');}
58
validatePieceColors('custom','Red','Blue');
59
check(true,'valid custom accepted');
60
61
echo "Colors: $checks assertions passed.\n";
@@ -0,0 +1,61 @@1
<?php2
declare(strict_types=1);3
require dirname(__DIR__).'/lib/PieceColors.php';4
5
// Stub query()/db() unused by pure resolve helpers.6
$checks=0;7
function check(bool $condition,string $label): void {global $checks;$checks++;if(!$condition)throw new RuntimeException($label);}8
9
function prefs(string $mode,string $preferred,string $alternative): array {10
return ['color_mode'=>$mode,'preferred_color'=>$preferred,'alternative_color'=>$alternative];11
}12
13
// No conflict: both default on opposite rules sides.14
$r=resolvePieceSkins(prefs('default','White','Black'),prefs('default','White','Black'));15
check($r===['white'=>'White','black'=>'Black'],'Both default keep rules colours');16
17
// No conflict: custom preferreds differ.18
$r=resolvePieceSkins(prefs('custom','Red','Blue'),prefs('custom','Green','Yellow'));19
check($r===['white'=>'Red','black'=>'Green'],'Different custom preferreds');20
21
// Default vs custom conflict: default keeps rules colour; custom uses alternative.22
$r=resolvePieceSkins(prefs('default','White','Black'),prefs('custom','White','Red'));23
check($r===['white'=>'White','black'=>'Red'],'Black custom yields to alternative when conflicting with default White');24
25
$r=resolvePieceSkins(prefs('custom','Black','Blue'),prefs('default','White','Black'));26
check($r===['white'=>'Blue','black'=>'Black'],'White custom yields to alternative when conflicting with default Black');27
28
// Default vs custom with broken alternative equal to default colour: cycle further.29
$r=resolvePieceSkins(prefs('default','White','Black'),prefs('custom','White','White'));30
// validatePieceColors would reject equal prefs; resolution still cycles if alternative equals.31
// Here alternative equals preferred (invalid), but also equals whiteWant; nextDistinct from White skip White -> Black32
check($r['white']==='White' && $r['black']!=='White','Cycled alternative when equal to default colour');33
34
// Both custom same preferred: coin flip 1 => white keeps, black takes alternative35
$r=resolvePieceSkins(prefs('custom','Red','Blue'),prefs('custom','Red','Green'),fn()=>1);36
check($r===['white'=>'Red','black'=>'Green'],'Both custom conflict: white keeps when coin=1');37
38
$r=resolvePieceSkins(prefs('custom','Red','Blue'),prefs('custom','Red','Green'),fn()=>0);39
check($r===['white'=>'Blue','black'=>'Red'],'Both custom conflict: black keeps when coin=0');40
41
// Custom preferred matches other side's rules/default without being same mode conflict path already covered.42
$r=resolvePieceSkins(prefs('custom','Black','Red'),prefs('custom','White','Blue'));43
check($r===['white'=>'Black','black'=>'White'],'Cross-coloured customs with no clash');44
45
// effectivePreferred46
check(effectivePreferredColor(prefs('default','Red','Blue'),'White')==='White','Default mode uses rules colour');47
check(effectivePreferredColor(prefs('custom','Red','Blue'),'White')==='Red','Custom mode uses preferred');48
49
// nextDistinct50
check(nextDistinctPieceColor('White','Black')==='Red','Cycle White skip Black -> Red');51
check(nextDistinctPieceColor('Yellow','White')==='Black','Cycle Yellow wrap skip White -> Black');52
check(nextDistinctPieceColor('Red','Blue')==='Green','Cycle Red skip Blue -> Green');53
54
// Validation55
try {validatePieceColors('nope','White','Black');check(false,'bad mode');} catch(DomainException){check(true,'bad mode rejected');}56
try {validatePieceColors('custom','Purple','Black');check(false,'bad colour');} catch(DomainException){check(true,'bad colour rejected');}57
try {validatePieceColors('custom','Red','Red');check(false,'same colours');} catch(DomainException){check(true,'same colours rejected');}58
validatePieceColors('custom','Red','Blue');59
check(true,'valid custom accepted');60
61
echo "Colors: $checks assertions passed.\n";@@ -116,7 +116,7 @@ with tempfile.TemporaryDirectory(prefix='api-', dir=ARTIFACTS) as tmp:
116
116
a.post('push_unsubscribe',endpoint=subscription['endpoint'])
117
117
check(a.state()['user']['rating']==b.state()['user']['rating']==1200, 'Accounts start at 1200 Elo')
118
118
avatars=json.loads((root/'assets/avatars/catalog.json').read_text())
119
check(len(avatars)==91 and sum(v['group']=='fairy' for v in avatars)==67,'Only retained fairy and colored avatars are available')
119
check(len(avatars)==103 and sum(v['group']=='fairy' for v in avatars)==67 and sum(v['group']=='standard' for v in avatars)==36,'Retained fairy and standard avatars including White/Black')
120
120
check(len({Path(v['file']).stem.casefold() for v in avatars})==len(avatars),'PNG and SVG versions of a piece appear only once')
121
121
check(len({v['id'] for v in avatars})==len(avatars),'Avatar IDs are unique')
122
122
check(all((root/'assets/avatars'/v['file']).read_bytes().startswith(b'\x89PNG\r\n\x1a\n') for v in avatars),'Every selectable avatar has a local PNG')
@@ -132,6 +132,19 @@ with tempfile.TemporaryDirectory(prefix='api-', dir=ARTIFACTS) as tmp:
132
132
check(b.state()['user']['avatar']=='purple-elephant','Fairy avatar can be selected')
133
133
b.post('set_avatar',avatar=None)
134
134
check(b.state()['user']['avatar'] is not None,'Random avatar reset')
135
check(any(v['id']=='white-king' for v in avatars) and any(v['id']=='black-king' for v in avatars),'White/Black standard avatars catalogued')
136
a.post('set_avatar',avatar='white-king')
137
check(a.state()['user']['avatar']=='white-king','White king avatar selectable')
138
a.post('set_avatar',avatar='blue-knight')
139
check(a.state()['user']['avatar']=='blue-knight','Restore blue knight avatar for later checks')
140
a.post('set_piece_colors',colorMode='custom',preferredColor='Red',alternativeColor='Blue')
141
user=a.state()['user']
142
check(user['colorMode']=='custom' and user['preferredColor']=='Red' and user['alternativeColor']=='Blue','Colour preference persists')
143
a.post('set_piece_colors',colorMode='custom',preferredColor='Red',alternativeColor='Red',expected=409)
144
a.post('set_piece_colors',colorMode='custom',preferredColor='Purple',alternativeColor='Blue',expected=409)
145
# Conflict: a custom White vs b default — skins assigned when challenge accepted below
146
a.post('set_piece_colors',colorMode='custom',preferredColor='White',alternativeColor='Red')
147
b.post('set_piece_colors',colorMode='default',preferredColor='White',alternativeColor='Black')
135
148
a.post('switch_user', user='admin', expected=409)
136
149
old = a.csrf; a.csrf = 'wrong'; a.post('create_link', kind='match', expected=403); a.csrf = old
137
150
token = a.post('create_link', kind='friend')['url'].split('=')[1]
@@ -154,6 +167,16 @@ with tempfile.TemporaryDirectory(prefix='api-', dir=ARTIFACTS) as tmp:
154
167
a.post('challenge', friend='local:test_user_2'); id = b.state()['games'][0]['id']; b.game_action('accept', id)
155
168
ga, gb = a.game(id), b.game(id)
156
169
check(gb['opponentAvatar']=='blue-knight','Game tile includes opponent avatar')
170
check(ga.get('pieceSkinWhite') in {'White','Black','Red','Blue','Green','Yellow'} and ga.get('pieceSkinBlack') in {'White','Black','Red','Blue','Green','Yellow'},'Game stores piece skins')
171
check(ga['pieceSkinWhite']==gb['pieceSkinWhite'] and ga['pieceSkinBlack']==gb['pieceSkinBlack'],'Both players see the same skins')
172
check(ga['displayColor']==(ga['pieceSkinWhite'] if ga['color']=='w' else ga['pieceSkinBlack']),'displayColor matches rules side skin')
173
# a prefers White (custom), b is default. Whichever side a is on: if a is white rules -> skins White vs Black; if a is black rules and wants White while b(default white) wants White -> conflict, a uses Red.
174
if ga['color']=='w':
175
check(ga['pieceSkinWhite']=='White' and ga['pieceSkinBlack']=='Black','Custom White as white rules keeps White; default black stays Black')
176
else:
177
check(ga['pieceSkinWhite']=='White' and ga['pieceSkinBlack']=='Red','Custom White as black rules yields to Red vs default White')
178
a.post('set_piece_colors',colorMode='default',preferredColor='White',alternativeColor='Black')
179
b.post('set_piece_colors',colorMode='default',preferredColor='White',alternativeColor='Black')
157
180
check(push_events()[-1]['kind']=='turn' and push_events()[-1]['user']==('local:test_user_1' if ga['yourTurn'] else 'local:test_user_2'),'Acceptance notifies first player')
158
181
check(ga['color'] != gb['color'] and ga['yourTurn'] != gb['yourTurn'], 'Opposite colors and one turn')
159
182
white, black = (a,b) if ga['color']=='w' else (b,a)
@@ -370,7 +393,7 @@ with tempfile.TemporaryDirectory(prefix='api-', dir=ARTIFACTS) as tmp:
370
393
con.close()
371
394
with sqlite3.connect(root/'data/microchess.sqlite') as archive_db:
372
395
private_id=archive_db.execute("INSERT INTO results(game_id,a,b,winner,reason,state,ended) SELECT game_id,'queue:oldest','queue:near',NULL,'Draw','{}',ended FROM results WHERE id=?",(saved_id,)).lastrowid
373
archive_db.execute("INSERT INTO replays SELECT ?,'queue:oldest',moves FROM replays WHERE result_id=?",(private_id,saved_id))
396
archive_db.execute("INSERT INTO replays(result_id,white,moves,piece_skin_white,piece_skin_black) SELECT ?, 'queue:oldest', moves, piece_skin_white, piece_skin_black FROM replays WHERE result_id=?",(private_id,saved_id))
374
397
outsider_token=os.urandom(24).hex()
375
398
archive_db.execute('INSERT INTO replay_links(result_id,token) VALUES(?,?)',(private_id,outsider_token))
376
399
check(all(r['id']!=private_id for r in a.get('/api.php?action=history')),'History excludes other players games')
@@ -116,7 +116,7 @@ with tempfile.TemporaryDirectory(prefix='api-', dir=ARTIFACTS) as tmp:116
a.post('push_unsubscribe',endpoint=subscription['endpoint'])116
a.post('push_unsubscribe',endpoint=subscription['endpoint'])117
check(a.state()['user']['rating']==b.state()['user']['rating']==1200, 'Accounts start at 1200 Elo')117
check(a.state()['user']['rating']==b.state()['user']['rating']==1200, 'Accounts start at 1200 Elo')118
avatars=json.loads((root/'assets/avatars/catalog.json').read_text())118
avatars=json.loads((root/'assets/avatars/catalog.json').read_text())119
check(len(avatars)==91 and sum(v['group']=='fairy' for v in avatars)==67,'Only retained fairy and colored avatars are available')119
check(len(avatars)==103 and sum(v['group']=='fairy' for v in avatars)==67 and sum(v['group']=='standard' for v in avatars)==36,'Retained fairy and standard avatars including White/Black')120
check(len({Path(v['file']).stem.casefold() for v in avatars})==len(avatars),'PNG and SVG versions of a piece appear only once')120
check(len({Path(v['file']).stem.casefold() for v in avatars})==len(avatars),'PNG and SVG versions of a piece appear only once')121
check(len({v['id'] for v in avatars})==len(avatars),'Avatar IDs are unique')121
check(len({v['id'] for v in avatars})==len(avatars),'Avatar IDs are unique')122
check(all((root/'assets/avatars'/v['file']).read_bytes().startswith(b'\x89PNG\r\n\x1a\n') for v in avatars),'Every selectable avatar has a local PNG')122
check(all((root/'assets/avatars'/v['file']).read_bytes().startswith(b'\x89PNG\r\n\x1a\n') for v in avatars),'Every selectable avatar has a local PNG')@@ -132,6 +132,19 @@ with tempfile.TemporaryDirectory(prefix='api-', dir=ARTIFACTS) as tmp:132
check(b.state()['user']['avatar']=='purple-elephant','Fairy avatar can be selected')132
check(b.state()['user']['avatar']=='purple-elephant','Fairy avatar can be selected')133
b.post('set_avatar',avatar=None)133
b.post('set_avatar',avatar=None)134
check(b.state()['user']['avatar'] is not None,'Random avatar reset')134
check(b.state()['user']['avatar'] is not None,'Random avatar reset')135
check(any(v['id']=='white-king' for v in avatars) and any(v['id']=='black-king' for v in avatars),'White/Black standard avatars catalogued')136
a.post('set_avatar',avatar='white-king')137
check(a.state()['user']['avatar']=='white-king','White king avatar selectable')138
a.post('set_avatar',avatar='blue-knight')139
check(a.state()['user']['avatar']=='blue-knight','Restore blue knight avatar for later checks')140
a.post('set_piece_colors',colorMode='custom',preferredColor='Red',alternativeColor='Blue')141
user=a.state()['user']142
check(user['colorMode']=='custom' and user['preferredColor']=='Red' and user['alternativeColor']=='Blue','Colour preference persists')143
a.post('set_piece_colors',colorMode='custom',preferredColor='Red',alternativeColor='Red',expected=409)144
a.post('set_piece_colors',colorMode='custom',preferredColor='Purple',alternativeColor='Blue',expected=409)145
# Conflict: a custom White vs b default — skins assigned when challenge accepted below146
a.post('set_piece_colors',colorMode='custom',preferredColor='White',alternativeColor='Red')147
b.post('set_piece_colors',colorMode='default',preferredColor='White',alternativeColor='Black')135
a.post('switch_user', user='admin', expected=409)148
a.post('switch_user', user='admin', expected=409)136
old = a.csrf; a.csrf = 'wrong'; a.post('create_link', kind='match', expected=403); a.csrf = old149
old = a.csrf; a.csrf = 'wrong'; a.post('create_link', kind='match', expected=403); a.csrf = old137
token = a.post('create_link', kind='friend')['url'].split('=')[1]150
token = a.post('create_link', kind='friend')['url'].split('=')[1]@@ -154,6 +167,16 @@ with tempfile.TemporaryDirectory(prefix='api-', dir=ARTIFACTS) as tmp:154
a.post('challenge', friend='local:test_user_2'); id = b.state()['games'][0]['id']; b.game_action('accept', id)167
a.post('challenge', friend='local:test_user_2'); id = b.state()['games'][0]['id']; b.game_action('accept', id)155
ga, gb = a.game(id), b.game(id)168
ga, gb = a.game(id), b.game(id)156
check(gb['opponentAvatar']=='blue-knight','Game tile includes opponent avatar')169
check(gb['opponentAvatar']=='blue-knight','Game tile includes opponent avatar')170
check(ga.get('pieceSkinWhite') in {'White','Black','Red','Blue','Green','Yellow'} and ga.get('pieceSkinBlack') in {'White','Black','Red','Blue','Green','Yellow'},'Game stores piece skins')171
check(ga['pieceSkinWhite']==gb['pieceSkinWhite'] and ga['pieceSkinBlack']==gb['pieceSkinBlack'],'Both players see the same skins')172
check(ga['displayColor']==(ga['pieceSkinWhite'] if ga['color']=='w' else ga['pieceSkinBlack']),'displayColor matches rules side skin')173
# a prefers White (custom), b is default. Whichever side a is on: if a is white rules -> skins White vs Black; if a is black rules and wants White while b(default white) wants White -> conflict, a uses Red.174
if ga['color']=='w':175
check(ga['pieceSkinWhite']=='White' and ga['pieceSkinBlack']=='Black','Custom White as white rules keeps White; default black stays Black')176
else:177
check(ga['pieceSkinWhite']=='White' and ga['pieceSkinBlack']=='Red','Custom White as black rules yields to Red vs default White')178
a.post('set_piece_colors',colorMode='default',preferredColor='White',alternativeColor='Black')179
b.post('set_piece_colors',colorMode='default',preferredColor='White',alternativeColor='Black')157
check(push_events()[-1]['kind']=='turn' and push_events()[-1]['user']==('local:test_user_1' if ga['yourTurn'] else 'local:test_user_2'),'Acceptance notifies first player')180
check(push_events()[-1]['kind']=='turn' and push_events()[-1]['user']==('local:test_user_1' if ga['yourTurn'] else 'local:test_user_2'),'Acceptance notifies first player')158
check(ga['color'] != gb['color'] and ga['yourTurn'] != gb['yourTurn'], 'Opposite colors and one turn')181
check(ga['color'] != gb['color'] and ga['yourTurn'] != gb['yourTurn'], 'Opposite colors and one turn')159
white, black = (a,b) if ga['color']=='w' else (b,a)182
white, black = (a,b) if ga['color']=='w' else (b,a)@@ -370,7 +393,7 @@ with tempfile.TemporaryDirectory(prefix='api-', dir=ARTIFACTS) as tmp:370
con.close()393
con.close()371
with sqlite3.connect(root/'data/microchess.sqlite') as archive_db:394
with sqlite3.connect(root/'data/microchess.sqlite') as archive_db:372
private_id=archive_db.execute("INSERT INTO results(game_id,a,b,winner,reason,state,ended) SELECT game_id,'queue:oldest','queue:near',NULL,'Draw','{}',ended FROM results WHERE id=?",(saved_id,)).lastrowid395
private_id=archive_db.execute("INSERT INTO results(game_id,a,b,winner,reason,state,ended) SELECT game_id,'queue:oldest','queue:near',NULL,'Draw','{}',ended FROM results WHERE id=?",(saved_id,)).lastrowid373
archive_db.execute("INSERT INTO replays SELECT ?,'queue:oldest',moves FROM replays WHERE result_id=?",(private_id,saved_id))396
archive_db.execute("INSERT INTO replays(result_id,white,moves,piece_skin_white,piece_skin_black) SELECT ?, 'queue:oldest', moves, piece_skin_white, piece_skin_black FROM replays WHERE result_id=?",(private_id,saved_id))374
outsider_token=os.urandom(24).hex()397
outsider_token=os.urandom(24).hex()375
archive_db.execute('INSERT INTO replay_links(result_id,token) VALUES(?,?)',(private_id,outsider_token))398
archive_db.execute('INSERT INTO replay_links(result_id,token) VALUES(?,?)',(private_id,outsider_token))376
check(all(r['id']!=private_id for r in a.get('/api.php?action=history')),'History excludes other players games')399
check(all(r['id']!=private_id for r in a.get('/api.php?action=history')),'History excludes other players games')@@ -3,7 +3,7 @@
3
3
declare(strict_types=1);
4
4
$root=sys_get_temp_dir().'/microchess-push-'.bin2hex(random_bytes(6));
5
5
mkdir($root.'/data',0700,true);mkdir($root.'/lib');mkdir($root.'/assets/avatars',0700,true);
6
foreach (['bootstrap.php','Chess.php','MoveFeedback.php','Push.php'] as $file) copy(__DIR__.'/../lib/'.$file,$root.'/lib/'.$file);
6
foreach (['bootstrap.php','Chess.php','MoveFeedback.php','Push.php','PieceColors.php'] as $file) copy(__DIR__.'/../lib/'.$file,$root.'/lib/'.$file);
7
7
symlink(realpath(__DIR__.'/../lib/push'),$root.'/lib/push');
8
8
copy(__DIR__.'/../assets/avatars/catalog.json',$root.'/assets/avatars/catalog.json');
9
9
$_SERVER+=['HTTP_HOST'=>'localhost','REMOTE_ADDR'=>'127.0.0.1','SCRIPT_NAME'=>'/microchess/api.php'];
@@ -3,7 +3,7 @@3
declare(strict_types=1);3
declare(strict_types=1);4
$root=sys_get_temp_dir().'/microchess-push-'.bin2hex(random_bytes(6));4
$root=sys_get_temp_dir().'/microchess-push-'.bin2hex(random_bytes(6));5
mkdir($root.'/data',0700,true);mkdir($root.'/lib');mkdir($root.'/assets/avatars',0700,true);5
mkdir($root.'/data',0700,true);mkdir($root.'/lib');mkdir($root.'/assets/avatars',0700,true);6
foreach (['bootstrap.php','Chess.php','MoveFeedback.php','Push.php'] as $file) copy(__DIR__.'/../lib/'.$file,$root.'/lib/'.$file);6
foreach (['bootstrap.php','Chess.php','MoveFeedback.php','Push.php','PieceColors.php'] as $file) copy(__DIR__.'/../lib/'.$file,$root.'/lib/'.$file);7
symlink(realpath(__DIR__.'/../lib/push'),$root.'/lib/push');7
symlink(realpath(__DIR__.'/../lib/push'),$root.'/lib/push');8
copy(__DIR__.'/../assets/avatars/catalog.json',$root.'/assets/avatars/catalog.json');8
copy(__DIR__.'/../assets/avatars/catalog.json',$root.'/assets/avatars/catalog.json');9
$_SERVER+=['HTTP_HOST'=>'localhost','REMOTE_ADDR'=>'127.0.0.1','SCRIPT_NAME'=>'/microchess/api.php'];9
$_SERVER+=['HTTP_HOST'=>'localhost','REMOTE_ADDR'=>'127.0.0.1','SCRIPT_NAME'=>'/microchess/api.php'];