Skip to content

Commit

Permalink
Fixing package definition and exporting functions
Browse files Browse the repository at this point in the history
The web-dice-of-doom (now called by :dice-of-doom-v3) are fucked up.
I'll skip the last chapter which is just a improvement of this version.
A new dice of doom.
  • Loading branch information
ryukinix committed Mar 17, 2017
1 parent b8cde3d commit 7eeb93c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 22 deletions.
3 changes: 1 addition & 2 deletions land-of-lisp/cap13-webserver.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@

(defpackage :webserver
(:use :cl :usocket)
(:export :serve)
(:shadow :usocket))
(:export :serve))

(in-package :webserver)

Expand Down
1 change: 1 addition & 0 deletions land-of-lisp/cap18-dice-of-doom-v2.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
:gen-board
:game-tree
:player-letter
:*ai-level*
:*num-players*
:*max-dice*
:*board-size*
Expand Down
57 changes: 37 additions & 20 deletions land-of-lisp/cap19-web-dice-of-doom-v3.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,23 @@
(load "cap18-dice-of-doom-v2") ;; as :dice-of-doom-v2 package
(load "cap18-lazy-programming") ;; as :lazy package

(defpackage :web-dice-of-doom
(defpackage :dice-of-doom-v3
(:use :cl :svg :dice-of-doom-v2 :lazy :webserver)
(:export :main
:gen-board
:attacking-moves
:handle-human
:handle-computer
:get-ratings
:limit-tree-depth
:*num-players*
:*die-colors*
:*ai-level*
:*board-width* :*board-height*
:*board-scale* :*top-offset*
:*dice-scale* :*dot-size*))

(in-package :web-dice-of-doom)
(in-package :dice-of-doom-v3)


(defparameter *board-width* 900)
Expand Down Expand Up @@ -147,29 +155,38 @@
(lazy-mapcar #'caar (caddr tree)))))))



(defun dod-request-handler (path header params)
(declare (ignore header))
(if (equal path "game.html")
(progn (princ "<!doctype html>")
(tag center ()
(princ "Welcome to DICE OF DOOM!")
(tag br ())
(let ((chosen (assoc 'chosen params)))
(when (or (not *cur-game-tree*)
(not chosen))
(setf chosen nil)
(web-initialize))
(cond ((lazy-null (caddr *cur-game-tree*))
(web-announce-winner (cadr *cur-game-tree*)))
((zerop (car *cur-game-tree*))
(web-handle-human
(when chosen
(read-from-string (cdr chosen)))))
(t (web-handle-computer))))
(tag br ())
(draw-dod-page *cur-game-tree* *from-tile*)))
(progn (html
(body
(tag center ()
(princ "Welcome to DICE OF DOOM!")
(tag br ())
(let ((chosen (assoc 'chosen params)))
(when (or (not *cur-game-tree*)
(not chosen))
(setf chosen nil)
(web-initialize))
(cond ((lazy-null (caddr *cur-game-tree*))
(web-announce-winner (cadr *cur-game-tree*)))
((zerop (car *cur-game-tree*))
(web-handle-human
(when chosen
(read-from-string (cdr chosen)))))
(t (web-handle-computer))))
(tag br ())
(draw-dod-page *cur-game-tree* *from-tile*)))))
(princ "Sorry... I don't know that page.")))


(defun main ()
(serve #'dod-request-handler))


;; NOTE:
;; UNFORTUNATELY THIS EXAMPLE DOESN'T WORKS ON MODERN BROWSERS
;; BECAUSE THE BAD IMPLEMENTATION OF :WEBSERVER WITHOUT SEND A STANDARD HEADER.

;; By the way, the svg drawing is fucked up too. GREAT.

0 comments on commit 7eeb93c

Please sign in to comment.