Re: [sl4] Rolf's gambit revisited

From: Benja Fallenstein (benja.fallenstein@gmail.com)
Date: Mon Jan 12 2009 - 13:41:49 MST


Hi Matt,

On Mon, Jan 12, 2009 at 7:21 PM, Matt Mahoney <matmahoney@yahoo.com> wrote:
> Perhaps you could write a simple program of two agents simulating each other and prove me wrong.

Fair enough. Here goes.

The following is a Python program of two agents, one guessing a number
and the other one telling whether the guess is high or low, conducting
a dialog by simulating each other. The program as given is the
guesser; to get the verifier (which behaves the same way except that
it prints "Running the verifier" instead of "Running the guesser" --
but they have different main loops that just happen to do the same
thing), change the last line from "exec guesser" to "exec verifier."

=====
verifier = '''
guesserState = {'verifier':verifier, 'guesser':guesser, 'number':number}
isFirstStep = True

def stepVerifier():
    global verifierSays, isFirstStep

    if isFirstStep: exec guesser in guesserState; isFirstStep = False
    else: exec 'stepGuesser()' in guesserState

    if guesserState['guesserSays'] < number:
        verifierSays = "Too low."
    elif guesserState['guesserSays'] == number:
        verifierSays = "Correct!"
    else:
        verifierSays = "Too high."

if __name__ == '__main__':
    print "Running the verifier!"
    while True:
        stepVerifier()
        print "Guess:", guesserState['guesserSays']
        print "->", verifierSays
        if verifierSays == "Correct!": break
'''

guesser = '''
low = 1; high = 10
verifierState = {'verifier':verifier, 'guesser':guesser, 'number':number}
isFirstStep = True

guesserSays = 5

def stepGuesser():
    global low, high, guesserSays, isFirstStep

    if isFirstStep: exec verifier in verifierState; isFirstStep = False
    exec 'stepVerifier()' in verifierState

    if verifierState['verifierSays'] == "Too low.":
        low = guesserSays + 1
    elif verifierState['verifierSays'] == "Too high.":
        high = guesserSays - 1

    guesserSays = low + ((high-low) % 2)

if __name__ == '__main__':
    print "Running the guesser!"
    while True:
        print "Guess:", guesserSays
        stepGuesser()
        print "->", verifierState['verifierSays']
        if verifierState['verifierSays'] == "Correct!": break
'''

from random import choice
number = choice(range(1,11))
exec guesser
=====

Is this convincing, or do you see something in it that you don't think
carries over to the situation under discussion?

(It's possible to get rid of the exec on the outer level by turning
this into a less magical quine-- compare to the difference between

http://users.aims.ac.za/~mackay/python/quine/quine3.py

and

http://users.aims.ac.za/~mackay/python/quine/quine4a.py )

Thanks,
- Benja



This archive was generated by hypermail 2.1.5 : Wed Jul 17 2013 - 04:01:03 MDT