Morendil comments on Prisoner's Dilemma (with visible source code) Tournament - Less Wrong

47 Post author: AlexMennen 07 June 2013 08:30AM

You are viewing a comment permalink. View the original post to see all comments and the full post content.

Comments (232)

You are viewing a single comment's thread. Show more comments above.

Comment author: AlexMennen 06 June 2013 02:13:09AM *  2 points [-]

Tentatively: I'll paste "(YourCode TheirCode)" into the interpreter with DrRacket, with #lang scheme.

Edit: Oops, that doesn't enforce the time limit. Just a sec while I figure this out.

Edit2: I tried this:

(define (kill-when-done thd) (sleep 10) (kill-thread thd) (print 'time-is-up))

(begin (define main-thread (thread (lambda () (your-code their-code)))) (kill-when-done main-thread))

but unfortunately threads are not guaranteed to start back up again as soon as sleep allows them to; it took about 18 seconds to terminate when I ran the second line with "your-code" being an infinite loop. I'll figure out how to do this properly tomorrow.

Edit3: A marvelously improper but correct way to do it:

(begin (define x (current-milliseconds)) (print (your-code their-code) (- (current-milliseconds) x))

Allow to run more than 10 seconds by looking at clock at stopping manually. Throw out result if it says it took more than 10 seconds.

Comment author: Morendil 08 June 2013 08:26:11AM *  1 point [-]

Tentatively: I'll paste "(YourCode TheirCode)" into the interpreter with DrRacket, with #lang scheme.

The most elegant, it seems to me, would be to require entires to be sumitted as a .rkt file that defines a module providing a single variable (possibly with a required name, eg "bot") that must be a quoted expression.

This makes it simple to call programs (eval the expressions), pass opponent's source code, or even provide programs with their own source code; and could be used to automate static checking of various constraints, such as the ban on file I/O.

It also allows more flexibility for submitters in constructing their entry, for instance I was able to considerably streamline the source code to the CliqueBot template:

(define matcher
'(let pattern-match ((pattern template) (value opponent))
(cond
((pair? pattern) (and (pair? value)
(pattern-match (car pattern) (car value))
(pattern-match (cdr pattern) (cdr value))))
((number? pattern) (case (+ pattern 1)
((1) #t)
((3) (equal? value template))
(else (and (number? value)
(= pattern value)))))
(#t (eq? pattern value)))))

(this is the "workhorse" part, providing the program as a quoted expression obviates the need for repeating it twice, as we can then leverage the quasiquote and unquote language features)

(define clique-templ
(quasiquote
(let ((template '2))
(lambda (opponent)
(if (unquote matcher)
'C
0)))))

(this is the "template", it will be expanded to include the program-matching portion)

(define clique-bot
(quasiquote
(let ((template (quote (unquote clique-templ))))
(lambda (opponent)
(if (unquote matcher)
'C
'D)))))

(this is the actual program, it both quotes (via inclusion of the template) and uses the program-matching part).

The top of the file would consist of the following declaration:

#lang scheme
(provide clique-bot)

...or if you're requiring that all entries use the same name "bot" (which could make it easier to administrate the actual running of the contest):

#lang scheme
(provide (rename-out (clique-bot bot)))