From b2bcaa8086f25402b081e2710aff2f3aa58fc00d Mon Sep 17 00:00:00 2001 From: Vivianne Langdon Date: Fri, 3 Feb 2023 06:19:04 -0800 Subject: [PATCH] Added randomness and more cleanups --- gib-gab-gob.scm | 7 +++++++ gib-gab-gob/actors.scm | 4 ++-- gib-gab-gob/rps.scm | 13 ++++++++----- hall.scm | 13 +++++++++++-- 4 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 gib-gab-gob.scm diff --git a/gib-gab-gob.scm b/gib-gab-gob.scm new file mode 100644 index 0000000..1121b68 --- /dev/null +++ b/gib-gab-gob.scm @@ -0,0 +1,7 @@ +(define-module (gib-gab-gob) + #:use-module (gib-gab-gob rps) + #:use-module (gib-gab-gob actors) + #:re-export (do-rps + join-rps)) + +(set! *random-state* (random-state-from-platform)) diff --git a/gib-gab-gob/actors.scm b/gib-gab-gob/actors.scm index d168ce0..688675c 100644 --- a/gib-gab-gob/actors.scm +++ b/gib-gab-gob/actors.scm @@ -7,7 +7,7 @@ #:export (^rps ^client-picker)) (define* (^rps bcom) - (define pick 'scissors) + (define pick (pick-rps)) (methods ((register-opponent name client sealed-pick) (format #t "Hey there, ~a! You sent me your pick of rock-paper-scissors; now I will send mine.\n" name) @@ -19,7 +19,7 @@ (define (^client-picker bcom) (define-values (seal-pick unseal-pick my-pick?) (spawn-sealer-triplet)) - (define pick 'rock) + (define pick (pick-rps)) (methods ;; client always picks rock, it's the real good strat ((get-sealed-pick) ($ seal-pick pick)) diff --git a/gib-gab-gob/rps.scm b/gib-gab-gob/rps.scm index 59f47e0..c18d65e 100644 --- a/gib-gab-gob/rps.scm +++ b/gib-gab-gob/rps.scm @@ -6,7 +6,7 @@ #:use-module (goblins ocapn ids) #:use-module (goblins ocapn netlayer testuds) #:use-module (oop goops) - #:export (do-rps join-rps rps-winner rock-paper-scissors)) + #:export (do-rps join-rps pick-rps rps-winner rock-paper-scissors)) (define-class () (vat #:accessor vat) @@ -27,7 +27,9 @@ (define (new-testuds-netlayer) - (spawn ^testuds-netlayer "/tmp/netlayers")) + (define tmp "/tmp/netlayers") + (unless (access? tmp X_OK) (mkdir tmp)) + (spawn ^testuds-netlayer tmp)) (define (do-rps user-name) (init (make #:user-name user-name))) @@ -43,14 +45,12 @@ (define uds-netlayer (new-testuds-netlayer)) (define mycapn (spawn-mycapn uds-netlayer)) (set! (rps client) - (<- mycapn 'enliven rps-sref)) - (on (rps client) pk)) + (<- mycapn 'enliven rps-sref))) (define (join-rps user-name rps-addr) (define client (make #:user-name user-name #:rps-addr rps-addr)) (with-vat (vat client) (init client) - (format #t "Tor will take a bit...\n") (let ((client-picker (spawn ^client-picker)) (rps (rps client))) (on (<- rps 'register-opponent user-name client-picker ($ client-picker 'get-sealed-pick)) @@ -60,6 +60,9 @@ (define rock-paper-scissors (list 'rock 'paper 'scissors)) +(define (pick-rps) + (list-ref rock-paper-scissors (random (length rock-paper-scissors)))) + (define (rps-winner a b) (if (and (memq a rock-paper-scissors) (memq b rock-paper-scissors)) (match (list a b) diff --git a/hall.scm b/hall.scm index 909e5f8..996573a 100644 --- a/hall.scm +++ b/hall.scm @@ -16,14 +16,23 @@ (files (libraries ((directory "gib-gab-gob" - ((scheme-file "rps") (scheme-file "actors"))))) + ((compiled-scheme-file "actors") + (scheme-file "rps") + (scheme-file "actors") + (compiled-scheme-file "rps"))))) (tests ((directory "tests" ()))) (programs ((directory "scripts" ()))) (documentation ((text-file "ChangeLog") (text-file "AUTHORS") (text-file "NEWS") - (directory "doc" ((texi-file "gib-gab-gob"))) + (directory + "doc" + ((texi-file "version") + (text-file ".dirstamp") + (text-file "stamp-vti") + (info-file "gib-gab-gob") + (texi-file "gib-gab-gob"))) (text-file "COPYING") (text-file "HACKING") (text-file "README")))