More fleshing out of KOTH.
[jars.git] / koth.scm
index 1ca77c3..c14008d 100644 (file)
--- a/koth.scm
+++ b/koth.scm
@@ -6,14 +6,18 @@
         matchable
         mars parser)
 
-(define CORE-SIZE 8000)
-(define GAMES-PER-MATCH 1)
+;;; Constants
+;;
+
 (define INITIAL-INSTR (make-instr 'DAT 'F 'immediate 0 'immediate 0))
 
+;;; Games and Matches
+;;
+
 (define (file->prog file)
   (string->prog (with-input-from-file fname read)))
 
-(define (run-all-challenges challenger-file other-files)
+(define (run-all-matches challenger-file other-files)
   (let ((challenger-prog (file->prog challenger-file))
         (challenger-name (prog-name challenger-prog))
         (other-progs (apply file->prog other-files)))
                 `((,challenger-name 0) (,other-name 3))))))
      other-progs)))
 
-(define (run-match . progs)
-  (let* ((core (make-core CORE-SIZE INITIAL-INSTR))
-         (queues (install-progs core (list challenger-prog other-prog))))
-    (run-mars core queues)))
+(define (run-match spec . progs)
+  (let loop ((remaining (spec-games-per-match spec)))
+    (let* ((core (make-core (spec-core-size spec) INITIAL-INSTR))
+           (queues (install-progs core (list challenger-prog other-prog))))
+      (run-mars core queues))
+    (loop (- remaining 1))))
 
-;;; Score keeping
+;;; Score keeping and specs
 ;;
 
+(define (load-scores dir)
+  (with-input-from-file (make-pathname dir "scores") read))
+
 (define (load-specs dir)
   (with-input-from-file (make-pathname dir "specs") read))
 
             (lambda ()
               (print ";; Hill specifications.")
               (print ";; ('specs hill-size core-size game-length games-per-match\n")
-              (pp (make-specs core-size game-length games-per-match hill-size)))))))
+              (pp (make-specs core-size game-length games-per-match hill-size))))
+          (with-output-to-file (make-pathname dir "scores")
+            (lambda ()
+              (pp '()))))))
 
 ;;;; Main ;;;;
 
+;; Default values
+
+(define default-core-size 8000)
+(define default-game-length 80000)
+(define default-games-per-match 1)
+(define default-hill-size 10)
+
+
+
 (define (print-usage)
   (let ((binary (pathname-file (car (argv)))))
     (print "King of the Hill Tournament Manager")
-    (print "Usage:\t" binary " hill-directory challenger-file")
+    (print "\nUsage:\t" binary " hill-directory challenger-file")
     (print "\t" binary " [-h|--help]")
-    (print "\t" binary " [-i|--init] hill-directory [hill-size [core-size game-length games-per-match]]")))
+    (print "\t" binary " [-i|--init] hill-directory [hill-size [core-size game-length games-per-match]]")
+    (print "\nDefault values are as follows:\n"
+           "\thill-size: " default-hill-size "\n"
+           "\tcore-size: " default-core-size "\n"
+           "\tgame-length: " default-game-length "\n"
+           "\tgames-per-match: " default-games-per-match)))
 
 (define (process-args args)
   (match args
     (((or "-i" "--init") dir hill-size core-size game-length games-per-match)
      (init-hill-dir dir hill-size core-size game-length games-per-match))
     (((or "-i" "--init") dir)
-     (init-hill-dir dir 10 8000 80000 10))
+     (init-hill-dir dir
+                    default-hill-size
+                    default-core-size
+                    default-game-length
+                    default-games-per-match))
     (((or "-i" "--init") dir hill-size)
-     (init-hill-dir dir hill-size 8000 80000 10))
+     (init-hill-dir dir
+                    hill-size
+                    default-core-size
+                    default-game-length
+                    default-games-per-match))
     ((hill-dir challenger-file)
      (print "Not implemented"))
     (else