From a1e1cabee935128a7b06f877f45c4d89058950e7 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Thu, 26 Sep 2019 20:29:10 -0400 Subject: net: ror/ten/source.rkt: Update attacking. Roll dice to decide the winner for the attack. This kinda completes challenge one in ch. 10. --- net/ricketyspace/ror/ten/source.rkt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/net/ricketyspace/ror/ten/source.rkt b/net/ricketyspace/ror/ten/source.rkt index 8cb98dc..71c73b4 100644 --- a/net/ricketyspace/ror/ten/source.rkt +++ b/net/ricketyspace/ror/ten/source.rkt @@ -521,7 +521,14 @@ (define feasible (game-moves (dice-world-gt w))) (define attack (list source target)) (define next (find-move feasible attack)) - (if next (dice-world #f (game-board next) next) w)) + (define src-t (findf (lambda (t) (= (territory-index t) source)) + (dice-world-board w))) + (define dst-t (findf (lambda (t) (= (territory-index t) target)) + (dice-world-board w))) + (define win? (dice-attack-win src-t dst-t)) + (cond [(not next) w] + [win? (dice-world #f (game-board next) next)] + [else (dice-world-attack-lost w src-t)])) ;; [List-of Moves] [or '() [List Natural Natural]] -> [or #f Game-tree] ;; find the move from the current list of moves -- cgit v1.2.3