From 70f921d266de4dab51052a7306b7732808428531 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Thu, 26 Sep 2019 20:27:52 -0400 Subject: net: ror/ten/sourc.rkt: Add dice-attack-win. --- net/ricketyspace/ror/ten/source.rkt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/net/ricketyspace/ror/ten/source.rkt b/net/ricketyspace/ror/ten/source.rkt index 4bffdd0..b4fb6f2 100644 --- a/net/ricketyspace/ror/ten/source.rkt +++ b/net/ricketyspace/ror/ten/source.rkt @@ -534,6 +534,19 @@ (define (no-more-moves? g) (empty? (game-moves g))) +;; Territory Territory -> Boolean +;; attack from src territory to destination territory +;; and see who wins +(define (dice-attack-win src-t dst-t) + (define (roll-dice n) + (for/list ([i n]) + (random 1 7))) + (define (sum l) + (foldl + 0 l)) + (define src-attack (sum (roll-dice (territory-dice src-t)))) + (define dst-defend (sum (roll-dice (territory-dice dst-t)))) + (if (> src-attack dst-defend) #t #f)) + ; ; ; -- cgit v1.2.3