"tkMOO-light is Copyright (c) Andrew Wilson 1994,1995,1996,1997,1998,1999 " " All Rights Reserved " "Permission is hereby granted to use this software for private, academic "and non-commercial use. No commercial or profitable use of this "software may be made without the prior permission of the author. " "THIS SOFTWARE IS PROVIDED BY ANDREW WILSON ``AS IS'' AND ANY "EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, "THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR "PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANDREW WILSON BE LIABLE "FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR "CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT "OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR "BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, "WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE "OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, "EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. @create $thing named Chess Board:Chess Board,board @prop chess."players" {} rc @prop chess."board" {} rc @prop chess."turn" 1 rc @prop chess."driver" #263 rc @prop chess."sequence" 0 rc @prop chess."old_board" {} rc ;chess.("description") = "A chessboard. Some of it is black and some of it is white." @verb chess:"play" this none none @program chess:play "first person to join plays white..."; if (player in this.players) player:tell("You're already playing chess."); this:show_board(player); return; endif if (length(this.players) > 1) people = $string_utils:english_list($list_utils:map_verb(this.players, "title")); player:tell("Sorry, ", people, " are already playing chess."); return; endif this.players = {@this.players, player}; player:tell("You're now playing chess."); this:show_board(player); . @verb chess:"leave" this none none @program chess:leave if (!(psn = player in this.players)) player:tell("You weren't playing chess anyway."); return; endif "if one player leaves, then both do..."; this.players = {}; player:tell("You're no longer playing chess."); . @verb chess:"show_board" this none this @program chess:show_board if (caller != this) return E_PERM; endif who = args[1]; board = ""; for c in [1..8] for r in [1..8] board = board + this.board[c][r]; endfor endfor kv = {}; kv = {@kv, {"object", tostr(this)}}; kv = {@kv, {"board", board}}; "is it your turn, whoever you are?..."; colour = {"white", "black"}[who in this.players]; if (((colour == "white") && this.turn) || ((colour == "black") && (!this.turn))) your_turn = 1; else your_turn = 0; endif kv = {@kv, {"turn", tostr(your_turn)}}; kv = {@kv, {"colour", colour}}; kv = {@kv, {"sequence", tostr(this.sequence)}}; this.driver:client_notify(who, "chess-board", kv); . @verb chess:"look_self" this none this @program chess:look_self pass(@args); if (this.players) people = $string_utils:english_list($list_utils:map_verb(this.players, "title")); player:tell(people, (length(this.players) == 2) ? " are" | " is", " playing a game."); else player:tell("Noone's playing a game at the moment."); endif . @verb chess:"init" this none none @program chess:init this.sequence = 0; "white moves first..."; this.turn = 1; this.board = $list_utils:make(8, $list_utils:make(8, ".")); this.board[1][1] = "R"; this.board[2][1] = "N"; this.board[3][1] = "B"; this.board[4][1] = "K"; this.board[5][1] = "Q"; this.board[6][1] = "B"; this.board[7][1] = "N"; this.board[8][1] = "R"; this.board[1][2] = "P"; this.board[2][2] = "P"; this.board[3][2] = "P"; this.board[4][2] = "P"; this.board[5][2] = "P"; this.board[6][2] = "P"; this.board[7][2] = "P"; this.board[8][2] = "P"; this.board[1][8] = "r"; this.board[2][8] = "n"; this.board[3][8] = "b"; this.board[4][8] = "k"; this.board[5][8] = "q"; this.board[6][8] = "b"; this.board[7][8] = "n"; this.board[8][8] = "r"; this.board[1][7] = "p"; this.board[2][7] = "p"; this.board[3][7] = "p"; this.board[4][7] = "p"; this.board[5][7] = "p"; this.board[6][7] = "p"; this.board[7][7] = "p"; this.board[8][7] = "p"; this.old_board = {}; for player in (this.players) this:show_board(player); endfor . @verb chess:"move" any on this @program chess:move if (!(player in this.players)) return E_PERM; endif x1 = tonum(args[1]); y1 = tonum(args[2]); x2 = tonum(args[3]); y2 = tonum(args[4]); sequence = tonum(args[5]); if (sequence != this.sequence) player:tell("Your client is out of sync with the game, updating..."); this:show_board(player); return; endif if ((((((((x1 < 1) || (x1 > 8)) || (y1 < 1)) || (y1 > 8)) || (x2 < 1)) || (x2 > 8)) || (y2 < 1)) || (y2 > 8)) player:tell("Can't move off the board..."); return; endif "keep one level of undo"; this.old_board = this.board; this.board[x2][y2] = this.board[x1][y1]; this.board[x1][y1] = "."; this.sequence = this.sequence + 1; this.turn = this.turn ? 0 | 1; people = this.players; for person in (people) this:show_board(person); endfor . "***finished***