Raevnos's Chess
A chess board which you can @parent to.
Commands:
@adescribe,
@cpattr,
@create,
@describe,
@dolist,
@emit,
@mvattr,
@parent,
@pemit,
@select,
@set,
@switch,
@va,
@vb,
@vc,
@vd,
@wa,
@wipe.
Functions:
add(),
ansi(),
cand(),
center(),
cor(),
dist2d(),
edit(),
emit(),
eq(),
extract(),
first(),
foreach(),
gte(),
hasattr(),
hasattrval(),
if(),
isdbref(),
iter(),
last(),
lattr(),
ljust(),
lnum(),
lte(),
match(),
member(),
mod(),
mul(),
name(),
neq(),
not(),
owner(),
parent(),
pmatch(),
pos(),
regmatch(),
repeat(),
rest(),
s(),
secs(),
set(),
setq(),
setr(),
sort(),
space(),
squish(),
strmatch(),
sub(),
switch(),
tagwrap(),
timestring(),
u(),
udefault(),
v(),
wipe(),
words().
Instructions
Copy and paste the below code into a compatible MUSH or MUX.
MUSHCode for Raevnos's Chess
@@ -*- mushcode -*- $Id: chess.txt 1.2 Wed, 02 Aug 2000 22:39:31 -0700 shawnw $
@create Chessboard Parent
@lock/Link Chessboard Parent==#0
@lock/Basic Chessboard Parent==me
@set Chessboard Parent = LINK_OK
@set Chessboard Parent = VISUAL
@set Chessboard Parent = SAFE
@set Chessboard Parent = NO_COMMAND
@ADESCRIBE Chessboard Parent=@pemit %#=switch(member(#5048 #2295, %!), >0, This is the chessboard parent. To use\, @create an object\, @parent it to #5048\, and set it !no_command.,Use +CHESS/HELP for help.)
@set Chessboard Parent/ADESCRIBE=no_command
&CAN_MOVE_BISHOP Chessboard Parent=eq(dist2d(match(a b c d e f g h, %0), 0, match(a b c d e f g h, %2), 0), dist2d(0, %1, 0, %3))
&CAN_MOVE_KING Chessboard Parent=member(1 1.414214, dist2d(match(a b c d e f g h, %0), %1, match(a b c d e f g h,%2), %3))
&CAN_MOVE_KNIGHT Chessboard Parent=cor(cand(eq(1, dist2d(match(a b c d e f g h, %0), 0, match(a b c d e f g h, %2), 0)), eq(2, dist2d(0, %1, 0, %3))), cand(eq(2, dist2d(match(a b c d e f g h, %0), 0, match(a b c d e f g h, %2), 0)), eq(1, dist2d(0, %1, 0, %3))))
&CAN_MOVE_PAWN Chessboard Parent=cand(cor(match(%0, %2), cand(eq(1,dist2d(match(a b c d e f g h, %0), 0, match(a b c d e f g h, %2), 0)), regmatch(v(square_%3.%2), ^\[[s([if(pos(v(square_%1.%0), rnbqkp), u, l)]cstr(rnbqkp))]\]$))), s([if(pos(v(square_%1.%0), rnbqkp), gt, lt)](%3,%1)), lte(dist2d(1,%1,1,%3), if(member(2 7, %1), 2, 1)))
&CAN_MOVE_QUEEN Chessboard Parent=cor(u(can_move_rook, %0, %1, %2, %3), u(can_move_bishop, %0, %1, %2, %3))
&CAN_MOVE_ROOK Chessboard Parent=cor(eq(%1, %3), eq(match(a b c d e f g h, %0), match(a b c d e f g h, %2)))
&CASTLE_KING Chessboard Parent=$+chess/castle *:@select 0=match(%#, v(v(turn))),@pemit %#=It's not your turn!,not(hasattrval(me, promote)),@pemit %#=Please wait for a pawn promotion.,match(Left Right,%0),@pemit %#=You must castle to the left or right only.,cand(match(repeat(-, setr(0, switch(%0, left, 3, 2))),[setq(1, switch(v(turn), white, 1, 8))][iter(switch(%q0, 3, B C D, F G), v(square_%q1.##), ,)]),match(r, v(square_%q1.[setr(2,switch(%0, left, A, H))])),match(k, v(square_%q1.e))),@pemit %#=%wa,{@emit %n castles to the %0.;@wipe me/backup_*;@cpattr me/[v(turn)]_captures=me/backup_captures;@cpattr me/square_%q1.%q2=me/backup_%q1.%q2;&square_%q1.%q2 me=-;@cpattr me/square_%q1.e=me/backup_%q1.e;&square_%q1.e me=-;@cpattr me/square_%q1.[setr(9,switch(%0, left, c, g))]=me/backup_%q1.%q9;&square_%q1.%q9 me=v(backup_%q1.e);@cpattr me/square_%q1.[setr(8, switch(%0, left, d, f))]=me/backup_%q1.%q8;&square_%q1.%q8 me=v(backup_%q1.%q2);&[v(turn)]_time me=add(v(v(turn)_time), sub(secs(), v(last_move)));&last_move me=[secs()]; think if(cand(neq(0, v(max_time)), gte(v(v(turn)_time), v(max_time))), emit(%n ran out of time and looses.));&turn me=switch(v(turn), white, black, white)}
&CLEAR_PATH Chessboard Parent=switch(1,cand(eq(%0, %2), eq(%1, %3)), 1, match(v(square_%1.[extract(a b c d e f g h, %0, 1)]), -), u(clear_path, add(%0, %4), add(%1, %5)), 0)
@DESCRIBE Chessboard Parent=u(draw_board)
@set Chessboard Parent/DESCRIBE=no_command visual
&DRAW_BOARD Chessboard Parent=tagwrap(PRE,if(v(in_game), [if(v(max_time),Total time limit for this game: [timestring(mul(2, v(max_time)))]. [timestring(setr(0, sub(secs(), v(start_time))))] used up. [if(gte(%q0, mul(2, v(max_time))), %r[center(ansi(r, GAME OVER), 77)])]%r)][center(if(strmatch(v(turn), black), *%b)[ansi(h, name(v(black)))] [if(v(max_time), ([setq(0,add(switch(v(turn), black, sub(secs(), v(last_move)), 0), v(black_time)))][ansi(if(gte(%q0, v(max_time)), r, n), timestring(%q0))])%b)]is playing [ansi(Wx,BLACK)].,77)]%r[center(sort(v(black_captures)), 77)]%r[space(27)][iter(A B C D E F G H,##, ,%b%b)]%r[edit(edit(iter(lnum(8, 1), u(draw_line, ##), ,), -, %b), |, %r)][space(27)][iter(A B C D E F G H, ##, , %b%b)]%r[center(sort(v(white_captures)), 77)]%r[center(if(strmatch(v(turn), white),*%b)[ansi(h, name(v(white)))] [if(v(max_time), ([setq(0,add(switch(v(turn), white, sub(secs(), v(last_move)), 0), v(white_time)))][ansi(if(gte(%q0, v(max_time)), r, n), timestring(%q0))])%b)]is playing [ansi(Xw,white)].,77)],No game in progess. Use +CHESS/SETUP to start one.))
&DRAW_LINE Chessboard Parent=[setq(2, mod(%0, 2))][space(24)]%0 [setr(3, u(draw_line_2, %0))]|[space(26)]%q3%b%0|
&DRAW_LINE_2 Chessboard Parent=iter(a b c d e f g h, ansi(if(eq(mod(#@, 2), %q2), if(pos(v(square_%0.##), rnbqkp), %vc, %vd), if(pos(v(square_%0.##), rnbqkp), %va, %vb)), repeat(v(square_%0.##), 3)), ,)
&HELP Chessboard Parent=$+chess/help:@pemit %#=Chessboard commands:%r[ljust(+CHESS/SHOW,35)]Shows the board, just like looking does.%r[ljust(+CHESS/RESET,35)]Clear a game in progress.%r[ljust(+CHESS/SETUP <WHITE> and <BLACK>,35)]Start a new game with the given players. To add a timelimit to the game, add a 'FOR <MINUTE>' after black's player. When a player goes over that number of minutes of play, they loose, so that the maximum time a game would take is MINUTES * 2.%r[ljust(+CHESS/MOVE <SQUARE> to <SQUARE>,35)]Move a piece. (Squares are in LetterNumber format.)%r[ljust(+CHESS/PROMOTE <TYPE OF PIECE>,35)]Promote a pawn in the back row.%r[ljust(+CHESS/CASTLE <DIRECTION>,35)]Castles to the left or right.%r[ljust(+CHESS/UNDO,35)]Undo the last move.%r%rNote: The board is still in a primitive state when it comes to checking validity of moves. It doesn't check to see if all contiguous squares between the source and destination are open, or if a move would put you in check.%rTo make your own board: @create an object, @parent it to #5048, and @set it !no_command.%rReport problems to [name(owner(parent(me)))].
&INGAME Chessboard Parent=1
&IN_GAME Chessboard Parent=0
&IS_CLEAR Chessboard Parent=match(-, v(square_%0.%1))
&LICENSE Chessboard Parent=This object (Raevnos' Chessboard Parent) is released under the Gnu Public License. A copy of that license is avaliable at [tagwrap(a, href="http://www.gnu.org/copyleft/gpl.html", http://www.gnu.org/copyleft/gpl.html)]
&MOVE_PIECE Chessboard Parent=$+chess/move ?? to ??:@select 0=match(%#, v(v(turn))),@pemit %#=It's not your turn!,not(hasattrval(me, promote)),@pemit %#=Please wait for a pawn promotion.,cand(hasattr(me, setr(0, square_%1.%0)), hasattr(me, setr(1, square_%3.%2)), pos(v(%q0), s([switch(v(turn), white, l, u)]cstr(rnbqkp))), udefault(can_move_[u(name, v(%q0))], 1, %0, %1, %2, %3)),@pemit %#=%wa,regmatch(v(%q1), \[[s([if(pos(v(%q0), rnbqkp), u, l)]cstr(rnbqkp))]-\]),@pemit %#=%wa,{@emit %n moves a [u(name, v(%q0))] from %0%1 to %2%3[if(match(-,v(%q1)),, %band captures a [u(name, v(%q1))])].;@wipe me/backup_*;&[edit(%q0, square, backup)] me=v(%q0);&[edit(%q1, square, backup)] me=v(%q1);@cpattr me/[v(turn)]_captures=me/backup_captures;think setq(2,v(%q0))[setq(3, v(%q1))];&%q0 me=-;&%q1 me=%q2;think if(match(-, %q3),, set(me, v(turn)_captures:[squish(v(v(turn)_captures)%b%q3)]));&[v(turn)]_time me=[add(v(v(turn)_time),sub(secs(),v(last_move)))];&last_move me=[secs()];think if(cand(neq(0, v(max_time)), gte(v(v(turn)_time), v(max_time))), emit(%n ran out of time and looses.));&turn me=switch(v(turn), white, black, white);@switch 1=cand(match(%3, switch(v(turn), white, 1, 8)), match(%q2, p)),{@pemit %#=Use +chess/promote <name of piece>;&promote me=%q1}}
&NAME Chessboard Parent=switch(%0, p, Pawn, r, Rook, n, Knight, b, Bishop, q, Queen, k, King, Ack!)
&PROMOTE_PAWN Chessboard Parent=$+chess/promote *:@select 0=hasattrval(me, promote),@pemit %#=You can't promote a pawn right now.,match(%#, v(switch(v(turn), white, black, white))),@pemit %#=It's not your turn!,setr(0,match(Queen Bishop Knight Rook, %0)),@pemit %#=You can only promote to Queen, Bishop, Knight or Rook.,{@emit %n promotes a pawn to [extract(Queen Bishop Knight Rook, %q0, 1)].;&[v(promote)] me=switch(v(turn)%q0, white1, Q, white2, B, white3, N, white4, R, black1, q, black2, b, black3, n, black4, r);&promote me}
&SETUP_BOARD Chessboard Parent=$+chess/setup * and *:@switch isdbref(pmatch(%0))[isdbref(pmatch(first(%1)))][v(in_game)]=110,{@emit %n sets up the chess board with %0 playing white and [first(%1)] playing black.;think [wipe(me/square_*)][iter(3 4 5 6,[setq(0, ##)][setq(1, -)][foreach(setup_line, abcdefgh)])][setq(0, 2)][setq(1, p)][foreach(setup_line, abcdefgh)][setq(0, 7)][setq(1, P)][foreach(setup_line, abcdefgh)][set(me, square_1.a:r)][set(me, square_1.b:n)][set(me, square_1.c:b)][set(me, square_1.d:q)][set(me, square_1.e:k)][set(me, square_1.f:b)][set(me, square_1.g:n)][set(me, square_1.h:r)][set(me, square_8.a:R)][set(me, square_8.b:N)][set(me, square_8.c:B)][set(me, square_8.d:Q)][set(me, square_8.e:K)][set(me, square_8.f:B)][set(me, square_8.g:N)][set(me, square_8.h:R)][set(me, in_game:1)][set(me, white:[pmatch(%0)])][set(me, black:[pmatch(first(%1))])][set(me, white_captures:)][set(me, black_captures:)][set(me, turn:white)][set(me, last_move:[secs()])][set(me, start_time:[secs()])][set(me, black_time:0)][set(me, white_time:0)][set(me, max_time:[if(strmatch(rest(%1), for *), mul(last(%1),60), 0)])]},*1,@pemit %#=There's already a game in progress.,@pemit %#=You must have two players.
&SETUP_LINE Chessboard Parent=[set(me,square_%q0.%0:%q1)]
&SHOW_BOARD Chessboard Parent=$+chess/show:@pemit %#=u(draw_board)
&UNDO_MOVE Chessboard Parent=$+chess/undo:@select 0=member(v(black) [v(white)], %#),@pemit %#=You're not playing!,words(lattr(me/backup_*)),@pemit %#=No move to undo.,{@emit %n undos the last move.;&turn me=switch(v(turn), white, black, white);@mvattr me/backup_captures=me/[v(turn)]_captures;@dolist lattr(me/backup_*)=@mvattr me/##=me/[edit(##, BACKUP, SQUARE)];@wipe me/promote}
&V-NOTES Chessboard Parent=Codes for ansi() should go in the following attributes to customize colors, with the following meanings. VA: White piece on White square. VB: Black piece on White square. VC: White piece on Black square. VD: Black piece on Black square.
@VA Chessboard Parent=Wx
@VB Chessboard Parent=Wx
@VC Chessboard Parent=Xw
@VD Chessboard Parent=Xw
@WA Chessboard Parent=Invalid Move.
&WIPE_BOARD Chessboard Parent=$+chess/reset:think [wipe(me/square_*)][wipe(me/backup_*)][wipe(me/promote)][set(me, in_game:0)][wipe(me/white*)][wipe(me/black*)][wipe(me/turn)][wipe(me/last_move)][wipe(me/max_time)][wipe(me/start_time)];@emit %n brushes the chessboard clean of pieces.
@create Chessboard Parent
@lock/Link Chessboard Parent==#0
@lock/Basic Chessboard Parent==me
@set Chessboard Parent = LINK_OK
@set Chessboard Parent = VISUAL
@set Chessboard Parent = SAFE
@set Chessboard Parent = NO_COMMAND
@ADESCRIBE Chessboard Parent=@pemit %#=switch(member(#5048 #2295, %!), >0, This is the chessboard parent. To use\, @create an object\, @parent it to #5048\, and set it !no_command.,Use +CHESS/HELP for help.)
@set Chessboard Parent/ADESCRIBE=no_command
&CAN_MOVE_BISHOP Chessboard Parent=eq(dist2d(match(a b c d e f g h, %0), 0, match(a b c d e f g h, %2), 0), dist2d(0, %1, 0, %3))
&CAN_MOVE_KING Chessboard Parent=member(1 1.414214, dist2d(match(a b c d e f g h, %0), %1, match(a b c d e f g h,%2), %3))
&CAN_MOVE_KNIGHT Chessboard Parent=cor(cand(eq(1, dist2d(match(a b c d e f g h, %0), 0, match(a b c d e f g h, %2), 0)), eq(2, dist2d(0, %1, 0, %3))), cand(eq(2, dist2d(match(a b c d e f g h, %0), 0, match(a b c d e f g h, %2), 0)), eq(1, dist2d(0, %1, 0, %3))))
&CAN_MOVE_PAWN Chessboard Parent=cand(cor(match(%0, %2), cand(eq(1,dist2d(match(a b c d e f g h, %0), 0, match(a b c d e f g h, %2), 0)), regmatch(v(square_%3.%2), ^\[[s([if(pos(v(square_%1.%0), rnbqkp), u, l)]cstr(rnbqkp))]\]$))), s([if(pos(v(square_%1.%0), rnbqkp), gt, lt)](%3,%1)), lte(dist2d(1,%1,1,%3), if(member(2 7, %1), 2, 1)))
&CAN_MOVE_QUEEN Chessboard Parent=cor(u(can_move_rook, %0, %1, %2, %3), u(can_move_bishop, %0, %1, %2, %3))
&CAN_MOVE_ROOK Chessboard Parent=cor(eq(%1, %3), eq(match(a b c d e f g h, %0), match(a b c d e f g h, %2)))
&CASTLE_KING Chessboard Parent=$+chess/castle *:@select 0=match(%#, v(v(turn))),@pemit %#=It's not your turn!,not(hasattrval(me, promote)),@pemit %#=Please wait for a pawn promotion.,match(Left Right,%0),@pemit %#=You must castle to the left or right only.,cand(match(repeat(-, setr(0, switch(%0, left, 3, 2))),[setq(1, switch(v(turn), white, 1, 8))][iter(switch(%q0, 3, B C D, F G), v(square_%q1.##), ,)]),match(r, v(square_%q1.[setr(2,switch(%0, left, A, H))])),match(k, v(square_%q1.e))),@pemit %#=%wa,{@emit %n castles to the %0.;@wipe me/backup_*;@cpattr me/[v(turn)]_captures=me/backup_captures;@cpattr me/square_%q1.%q2=me/backup_%q1.%q2;&square_%q1.%q2 me=-;@cpattr me/square_%q1.e=me/backup_%q1.e;&square_%q1.e me=-;@cpattr me/square_%q1.[setr(9,switch(%0, left, c, g))]=me/backup_%q1.%q9;&square_%q1.%q9 me=v(backup_%q1.e);@cpattr me/square_%q1.[setr(8, switch(%0, left, d, f))]=me/backup_%q1.%q8;&square_%q1.%q8 me=v(backup_%q1.%q2);&[v(turn)]_time me=add(v(v(turn)_time), sub(secs(), v(last_move)));&last_move me=[secs()]; think if(cand(neq(0, v(max_time)), gte(v(v(turn)_time), v(max_time))), emit(%n ran out of time and looses.));&turn me=switch(v(turn), white, black, white)}
&CLEAR_PATH Chessboard Parent=switch(1,cand(eq(%0, %2), eq(%1, %3)), 1, match(v(square_%1.[extract(a b c d e f g h, %0, 1)]), -), u(clear_path, add(%0, %4), add(%1, %5)), 0)
@DESCRIBE Chessboard Parent=u(draw_board)
@set Chessboard Parent/DESCRIBE=no_command visual
&DRAW_BOARD Chessboard Parent=tagwrap(PRE,if(v(in_game), [if(v(max_time),Total time limit for this game: [timestring(mul(2, v(max_time)))]. [timestring(setr(0, sub(secs(), v(start_time))))] used up. [if(gte(%q0, mul(2, v(max_time))), %r[center(ansi(r, GAME OVER), 77)])]%r)][center(if(strmatch(v(turn), black), *%b)[ansi(h, name(v(black)))] [if(v(max_time), ([setq(0,add(switch(v(turn), black, sub(secs(), v(last_move)), 0), v(black_time)))][ansi(if(gte(%q0, v(max_time)), r, n), timestring(%q0))])%b)]is playing [ansi(Wx,BLACK)].,77)]%r[center(sort(v(black_captures)), 77)]%r[space(27)][iter(A B C D E F G H,##, ,%b%b)]%r[edit(edit(iter(lnum(8, 1), u(draw_line, ##), ,), -, %b), |, %r)][space(27)][iter(A B C D E F G H, ##, , %b%b)]%r[center(sort(v(white_captures)), 77)]%r[center(if(strmatch(v(turn), white),*%b)[ansi(h, name(v(white)))] [if(v(max_time), ([setq(0,add(switch(v(turn), white, sub(secs(), v(last_move)), 0), v(white_time)))][ansi(if(gte(%q0, v(max_time)), r, n), timestring(%q0))])%b)]is playing [ansi(Xw,white)].,77)],No game in progess. Use +CHESS/SETUP to start one.))
&DRAW_LINE Chessboard Parent=[setq(2, mod(%0, 2))][space(24)]%0 [setr(3, u(draw_line_2, %0))]|[space(26)]%q3%b%0|
&DRAW_LINE_2 Chessboard Parent=iter(a b c d e f g h, ansi(if(eq(mod(#@, 2), %q2), if(pos(v(square_%0.##), rnbqkp), %vc, %vd), if(pos(v(square_%0.##), rnbqkp), %va, %vb)), repeat(v(square_%0.##), 3)), ,)
&HELP Chessboard Parent=$+chess/help:@pemit %#=Chessboard commands:%r[ljust(+CHESS/SHOW,35)]Shows the board, just like looking does.%r[ljust(+CHESS/RESET,35)]Clear a game in progress.%r[ljust(+CHESS/SETUP <WHITE> and <BLACK>,35)]Start a new game with the given players. To add a timelimit to the game, add a 'FOR <MINUTE>' after black's player. When a player goes over that number of minutes of play, they loose, so that the maximum time a game would take is MINUTES * 2.%r[ljust(+CHESS/MOVE <SQUARE> to <SQUARE>,35)]Move a piece. (Squares are in LetterNumber format.)%r[ljust(+CHESS/PROMOTE <TYPE OF PIECE>,35)]Promote a pawn in the back row.%r[ljust(+CHESS/CASTLE <DIRECTION>,35)]Castles to the left or right.%r[ljust(+CHESS/UNDO,35)]Undo the last move.%r%rNote: The board is still in a primitive state when it comes to checking validity of moves. It doesn't check to see if all contiguous squares between the source and destination are open, or if a move would put you in check.%rTo make your own board: @create an object, @parent it to #5048, and @set it !no_command.%rReport problems to [name(owner(parent(me)))].
&INGAME Chessboard Parent=1
&IN_GAME Chessboard Parent=0
&IS_CLEAR Chessboard Parent=match(-, v(square_%0.%1))
&LICENSE Chessboard Parent=This object (Raevnos' Chessboard Parent) is released under the Gnu Public License. A copy of that license is avaliable at [tagwrap(a, href="http://www.gnu.org/copyleft/gpl.html", http://www.gnu.org/copyleft/gpl.html)]
&MOVE_PIECE Chessboard Parent=$+chess/move ?? to ??:@select 0=match(%#, v(v(turn))),@pemit %#=It's not your turn!,not(hasattrval(me, promote)),@pemit %#=Please wait for a pawn promotion.,cand(hasattr(me, setr(0, square_%1.%0)), hasattr(me, setr(1, square_%3.%2)), pos(v(%q0), s([switch(v(turn), white, l, u)]cstr(rnbqkp))), udefault(can_move_[u(name, v(%q0))], 1, %0, %1, %2, %3)),@pemit %#=%wa,regmatch(v(%q1), \[[s([if(pos(v(%q0), rnbqkp), u, l)]cstr(rnbqkp))]-\]),@pemit %#=%wa,{@emit %n moves a [u(name, v(%q0))] from %0%1 to %2%3[if(match(-,v(%q1)),, %band captures a [u(name, v(%q1))])].;@wipe me/backup_*;&[edit(%q0, square, backup)] me=v(%q0);&[edit(%q1, square, backup)] me=v(%q1);@cpattr me/[v(turn)]_captures=me/backup_captures;think setq(2,v(%q0))[setq(3, v(%q1))];&%q0 me=-;&%q1 me=%q2;think if(match(-, %q3),, set(me, v(turn)_captures:[squish(v(v(turn)_captures)%b%q3)]));&[v(turn)]_time me=[add(v(v(turn)_time),sub(secs(),v(last_move)))];&last_move me=[secs()];think if(cand(neq(0, v(max_time)), gte(v(v(turn)_time), v(max_time))), emit(%n ran out of time and looses.));&turn me=switch(v(turn), white, black, white);@switch 1=cand(match(%3, switch(v(turn), white, 1, 8)), match(%q2, p)),{@pemit %#=Use +chess/promote <name of piece>;&promote me=%q1}}
&NAME Chessboard Parent=switch(%0, p, Pawn, r, Rook, n, Knight, b, Bishop, q, Queen, k, King, Ack!)
&PROMOTE_PAWN Chessboard Parent=$+chess/promote *:@select 0=hasattrval(me, promote),@pemit %#=You can't promote a pawn right now.,match(%#, v(switch(v(turn), white, black, white))),@pemit %#=It's not your turn!,setr(0,match(Queen Bishop Knight Rook, %0)),@pemit %#=You can only promote to Queen, Bishop, Knight or Rook.,{@emit %n promotes a pawn to [extract(Queen Bishop Knight Rook, %q0, 1)].;&[v(promote)] me=switch(v(turn)%q0, white1, Q, white2, B, white3, N, white4, R, black1, q, black2, b, black3, n, black4, r);&promote me}
&SETUP_BOARD Chessboard Parent=$+chess/setup * and *:@switch isdbref(pmatch(%0))[isdbref(pmatch(first(%1)))][v(in_game)]=110,{@emit %n sets up the chess board with %0 playing white and [first(%1)] playing black.;think [wipe(me/square_*)][iter(3 4 5 6,[setq(0, ##)][setq(1, -)][foreach(setup_line, abcdefgh)])][setq(0, 2)][setq(1, p)][foreach(setup_line, abcdefgh)][setq(0, 7)][setq(1, P)][foreach(setup_line, abcdefgh)][set(me, square_1.a:r)][set(me, square_1.b:n)][set(me, square_1.c:b)][set(me, square_1.d:q)][set(me, square_1.e:k)][set(me, square_1.f:b)][set(me, square_1.g:n)][set(me, square_1.h:r)][set(me, square_8.a:R)][set(me, square_8.b:N)][set(me, square_8.c:B)][set(me, square_8.d:Q)][set(me, square_8.e:K)][set(me, square_8.f:B)][set(me, square_8.g:N)][set(me, square_8.h:R)][set(me, in_game:1)][set(me, white:[pmatch(%0)])][set(me, black:[pmatch(first(%1))])][set(me, white_captures:)][set(me, black_captures:)][set(me, turn:white)][set(me, last_move:[secs()])][set(me, start_time:[secs()])][set(me, black_time:0)][set(me, white_time:0)][set(me, max_time:[if(strmatch(rest(%1), for *), mul(last(%1),60), 0)])]},*1,@pemit %#=There's already a game in progress.,@pemit %#=You must have two players.
&SETUP_LINE Chessboard Parent=[set(me,square_%q0.%0:%q1)]
&SHOW_BOARD Chessboard Parent=$+chess/show:@pemit %#=u(draw_board)
&UNDO_MOVE Chessboard Parent=$+chess/undo:@select 0=member(v(black) [v(white)], %#),@pemit %#=You're not playing!,words(lattr(me/backup_*)),@pemit %#=No move to undo.,{@emit %n undos the last move.;&turn me=switch(v(turn), white, black, white);@mvattr me/backup_captures=me/[v(turn)]_captures;@dolist lattr(me/backup_*)=@mvattr me/##=me/[edit(##, BACKUP, SQUARE)];@wipe me/promote}
&V-NOTES Chessboard Parent=Codes for ansi() should go in the following attributes to customize colors, with the following meanings. VA: White piece on White square. VB: Black piece on White square. VC: White piece on Black square. VD: Black piece on Black square.
@VA Chessboard Parent=Wx
@VB Chessboard Parent=Wx
@VC Chessboard Parent=Xw
@VD Chessboard Parent=Xw
@WA Chessboard Parent=Invalid Move.
&WIPE_BOARD Chessboard Parent=$+chess/reset:think [wipe(me/square_*)][wipe(me/backup_*)][wipe(me/promote)][set(me, in_game:0)][wipe(me/white*)][wipe(me/black*)][wipe(me/turn)][wipe(me/last_move)][wipe(me/max_time)][wipe(me/start_time)];@emit %n brushes the chessboard clean of pieces.