[bknr-cvs] r2256 - in branches/trunk-reorg/projects/scrabble: src website
bknr at bknr.net
bknr at bknr.net
Mon Nov 5 10:44:32 UTC 2007
Author: hhubner
Date: 2007-11-05 05:44:32 -0500 (Mon, 05 Nov 2007)
New Revision: 2256
Modified:
branches/trunk-reorg/projects/scrabble/src/web.lisp
branches/trunk-reorg/projects/scrabble/website/scrabble.html
Log:
add alternate /make-move handler that does enough to test the functionality
for now.
Modified: branches/trunk-reorg/projects/scrabble/src/web.lisp
===================================================================
--- branches/trunk-reorg/projects/scrabble/src/web.lisp 2007-11-05 10:14:48 UTC (rev 2255)
+++ branches/trunk-reorg/projects/scrabble/src/web.lisp 2007-11-05 10:44:32 UTC (rev 2256)
@@ -66,15 +66,20 @@
(:tr (:td "Password") (:td (:input :type "PASSWORD" :name "password")))
(:tr (:td) (:td (:input :type "SUBMIT")))))))))
-(defun parse-move (string)
+(defun parse-move (tray string)
"Given a string X1,Y1,LETTER1,X2,Y2,LETTER2..., return a list of
-tile-placement objects describing the move"
+moves ((X1 Y1 LETTER-TILE2) (X2 Y2 LETTER-TILE2) ...)"
(let (list-of-moves)
(labels
- ((recurse (x-string y-string letter &rest more)
+ ((use-letter (letter)
+ (awhen (find letter tray :key #'char-of)
+ (setf tray (remove it tray))
+ (return-from use-letter it))
+ (error "tray does not contain letter ~A" letter))
+ (recurse (x-string y-string letter &rest more)
(push (list (parse-integer x-string)
(parse-integer y-string)
- (aref letter 0))
+ (use-letter (aref letter 0)))
list-of-moves)
(when more
(apply #'recurse more))))
@@ -92,10 +97,13 @@
(define-easy-handler (make-move-handler :uri "/make-move" :default-request-type :post)
(move game)
(start-session)
- ;; MOVE contains the move to make. Check that it is the session
- ;; users' turn, that the move is legal, then actually make the move.
- (format t "game: ~A move: ~A~%" game move)
- (scrabble:make-move (board-of (find-game game)) (parse-move move)))
+ ;; MOVE contains the move to make. (This should) check that it is
+ ;; the session users' turn, that the move is legal, then actually
+ ;; make the move.
+ (let* ((game (find-game game))
+ (participant (find (find-user (session-value :user)) (participants-of game) :key #'player-of)))
+ (scrabble:make-move (board-of game)
+ (parse-move (tray-of participant) move))))
(define-easy-handler (games :uri "/games") ()
(start-session)
Modified: branches/trunk-reorg/projects/scrabble/website/scrabble.html
===================================================================
--- branches/trunk-reorg/projects/scrabble/website/scrabble.html 2007-11-05 10:14:48 UTC (rev 2255)
+++ branches/trunk-reorg/projects/scrabble/website/scrabble.html 2007-11-05 10:44:32 UTC (rev 2256)
@@ -11,42 +11,6 @@
</head>
<body onload="init()">
<div id='playfield'>
- <div id='their-name-0'>Horst</div>
- <div id='their-score-0'>192</div>
- <div id='their-tray-0-0'><img src="images/NIL.png"/></div>
- <div id='their-tray-0-1'><img src="images/NIL.png"/></div>
- <div id='their-tray-0-2'><img src="images/NIL.png"/></div>
- <div id='their-tray-0-3'><img src="images/NIL.png"/></div>
- <div id='their-tray-0-4'><img src="images/NIL.png"/></div>
- <div id='their-tray-0-5'><img src="images/NIL.png"/></div>
- <div id='their-tray-0-6'><img src="images/NIL.png"/></div>
- <div id='their-name-1'>Vladimir</div>
- <div id='their-score-1'>188</div>
- <div id='their-tray-1-0'><img src="images/NIL.png"/></div>
- <div id='their-tray-1-1'><img src="images/NIL.png"/></div>
- <div id='their-tray-1-2'><img src="images/NIL.png"/></div>
- <div id='their-tray-1-3'><img src="images/NIL.png"/></div>
- <div id='their-tray-1-4'><img src="images/NIL.png"/></div>
- <div id='their-tray-1-5'><img src="images/NIL.png"/></div>
- <div id='their-tray-1-6'><img src="images/NIL.png"/></div>
- <div id='their-name-2'>Klarabella</div>
- <div id='their-score-2'>190</div>
- <div id='their-tray-2-0'><img src="images/NIL.png"/></div>
- <div id='their-tray-2-1'><img src="images/NIL.png"/></div>
- <div id='their-tray-2-2'><img src="images/NIL.png"/></div>
- <div id='their-tray-2-3'><img src="images/NIL.png"/></div>
- <div id='their-tray-2-4'><img src="images/NIL.png"/></div>
- <div id='their-tray-2-5'><img src="images/NIL.png"/></div>
- <div id='their-tray-2-6'><img src="images/NIL.png"/></div>
- <div id='their-name-3'>Heidi</div>
- <div id='their-score-3'>210</div>
- <div id='their-tray-3-0'><img src="images/NIL.png"/></div>
- <div id='their-tray-3-1'><img src="images/NIL.png"/></div>
- <div id='their-tray-3-2'><img src="images/NIL.png"/></div>
- <div id='their-tray-3-3'><img src="images/NIL.png"/></div>
- <div id='their-tray-3-4'><img src="images/NIL.png"/></div>
- <div id='their-tray-3-5'><img src="images/NIL.png"/></div>
- <div id='their-tray-3-6'><img src="images/NIL.png"/></div>
</div>
</body>
</html>
\ No newline at end of file
More information about the Bknr-cvs
mailing list