1 (import (chicken process-context)
9 (define INITIAL-INSTR (make-instr 'DAT 'F 'immediate 0 'immediate 0))
11 (define (file->prog file)
12 (string->prog (with-input-from-file fname read)))
14 (define (run-all-challenges challenger-file other-files)
15 (let ((challenger-prog (file->prog challenger-file))
16 (challenger-name (prog-name challenger-prog))
17 (other-progs (apply file->prog other-files)))
20 (let ((other-name (prog-name other-prog))
21 (result (run-match challenger-prog other-prog)))
22 (cond ((or (= (length result) 2)
23 (= (length result) 0))
24 `((,challenger-name 1) (,other-name 1)))
25 ((eq? (queue-name (car result)) challenger-name)
26 `((,challenger-name 3) (,other-name 0)))
28 `((,challenger-name 0) (,other-name 3))))))
31 (define (run-match . progs)
32 (let* ((core (make-core CORE-SIZE INITIAL-INSTR))
33 (queues (install-progs core (list challenger-prog other-prog))))
34 (run-mars core queues)))
39 (define (load-specs dir)
40 (with-input-from-file (make-pathname dir "specs") read))
42 (define (make-specs core-size match-length games-per-match hill-size)
43 (list 'specs hill-size core-size match-length games-per-match))
45 (define (specs? specs)
46 (and (pair? specs) (eq? (car specs) 'specs)))
48 (define (specs-hill-size specs) (list-ref specs 1))
49 (define (specs-core-size specs) (list-ref specs 2))
50 (define (specs-game-length specs) (list-ref specs 3))
51 (define (specs-games-per-match specs) (list-ref specs 4))
53 (define (init-hill-dir dir hill-size core-size game-length games-per-match)
54 (if (or (not (directory-exists? dir)) (not (file-writable? dir)))
55 (print "Directory " dir " doesn't exist or is not writable.")
56 (if (not (null? (glob (make-pathname dir "*"))))
57 (print "Directory " dir " exists but is non-empty.")
58 (with-output-to-file (make-pathname dir "specs")
60 (print ";; Hill specifications.")
61 (print ";; ('specs hill-size core-size game-length games-per-match\n")
62 (pp (make-specs core-size game-length games-per-match hill-size)))))))
68 (define default-core-size 8000)
69 (define default-game-length 80000)
70 (define default-games-per-match 1)
71 (define default-hill-size 10)
76 (let ((binary (pathname-file (car (argv)))))
77 (print "King of the Hill Tournament Manager")
78 (print "\nUsage:\t" binary " hill-directory challenger-file")
79 (print "\t" binary " [-h|--help]")
80 (print "\t" binary " [-i|--init] hill-directory [hill-size [core-size game-length games-per-match]]")
81 (print "\nDefault values are as follows:\n"
82 "\thill-size: " default-hill-size "\n"
83 "\tcore-size: " default-core-size "\n"
84 "\tgame-length: " default-game-length "\n"
85 "\tgames-per-match: " default-games-per-match)))
87 (define (process-args args)
89 ((or () ((or "-h" "--help")))
91 (((or "-i" "--init") dir hill-size core-size game-length games-per-match)
92 (init-hill-dir dir hill-size core-size game-length games-per-match))
93 (((or "-i" "--init") dir)
98 default-games-per-match))
99 (((or "-i" "--init") dir hill-size)
104 default-games-per-match))
105 ((hill-dir challenger-file)
106 (print "Not implemented"))
108 (print "Invalid arguments: " (apply conc else)))))
111 (process-args (cdr (argv))))