-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a base-game for coin games to inherit from and make nash-bargain …
…depend on that
- Loading branch information
Showing
3 changed files
with
80 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
(in-package #:tpd2.game) | ||
|
||
(defgame coin-game () | ||
() | ||
(defplayer () | ||
((coins 0))) | ||
(:unplayable t)) | ||
|
||
(my-defun coin-game finished :before (&rest args) | ||
(declare (ignorable args)) | ||
(loop for p in (my players) | ||
do | ||
(setf (player-controller-var p 'coins) (its coins p)))) | ||
|
||
(my-defun coin-game-player 'object-to-ml () | ||
(<div :class "coin-game-player" | ||
(call-next-method) | ||
(let ((coins (or (my coins) (my 'player-controller-var 'coins)))) | ||
(when coins | ||
(<p (format nil "~D coin~:P" coins)))))) | ||
|
||
(my-defun coin-game 'object-to-ml :around () | ||
(<div :class "coin-game" | ||
(call-next-method) | ||
(let ((coins (webapp-frame-var 'coins))) | ||
(cond ( | ||
(and coins (plusp coins)) | ||
(<h3 (format nil "You have ~D coin~:P." coins))) | ||
(t | ||
(<h3 :class "bankrupt" "You have no coins.")))))) | ||
|
||
(my-defun coin-game setup-coins () | ||
(loop for p in (my players) | ||
do (setf (its coins p) | ||
(setf (player-controller-var p 'coins) | ||
(max-nil-ok (its coins p) (player-controller-var p 'coins)))))) | ||
|
||
(my-defun coin-game players-ready :after () | ||
(my setup-coins)) | ||
|
||
(my-defun coin-game-player give-coins (amount) | ||
(incf (my coins) amount) | ||
(my announce :profit :player me :amount amount) | ||
(when (minusp (my coins)) | ||
(my announce :bankrupt :player me)) | ||
(values)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters