<reponame>jimmahoney/tron-engine<filename>bots/logbot.py
#!/usr/bin/env python
"""
logbot.py

 An example of a random bot which writes debug messages
 and errors to a log file.

 See the details of this approach to debugging in tron.py .

 <NAME> | cs.marlboro.edu | Feb 2014 

"""
import random, tron, time

DEBUG = False

if DEBUG:
    #      On csmarlboro.org, change 'everyone' to your username.
    #      Keep the rest of the path - that folder is world writable.
    #      This opens that file for appending, and writes one line
    #      to it with the date and time.
    logfile = '/var/www/csmarlboro/tron/logs/everyone.txt'
    tron.init_error_log(logfile)
    tron.warn("Starting logbot")   # Change this to whatever you like.

def debug(message):
    if DEBUG:
        tron.warn(message)

def which_move(board):
    """ Return the direction to move (1,2,3,4) given a Board object. """
    choices = board.moves()
    debug('')
    debug(' legal moves are' + str(choices))
    move = random.choice(choices)
    debug(' chosen move is ' + str(move))

    ## test: take longer than the 1 sec allowd.
    # time.sleep(2)

    ## test: occasionaly crash (divide by zero error)        
    # if random.randint(1,10) == 3: a = 1/0

    return move

# You probably don't need to change this part.
for board in tron.Board.generate():
    tron.move(which_move(board))

#!/usr/bin/env python
"""
logbot.py

 An example of a random bot which writes debug messages
 and errors to a log file.

 See the details of this approach to debugging in tron.py .

 <NAME> | cs.marlboro.edu | Feb 2014 

"""
import random, tron, time

DEBUG = False

if DEBUG:
    #      On csmarlboro.org, change 'everyone' to your username.
    #      Keep the rest of the path - that folder is world writable.
    #      This opens that file for appending, and writes one line
    #      to it with the date and time.
    logfile = '/var/www/csmarlboro/tron/logs/everyone.txt'
    tron.init_error_log(logfile)
    tron.warn("Starting logbot")   # Change this to whatever you like.

def debug(message):
    if DEBUG:
        tron.warn(message)

def which_move(board):
    """ Return the direction to move (1,2,3,4) given a Board object. """
    choices = board.moves()
    debug('')
    debug(' legal moves are' + str(choices))
    move = random.choice(choices)
    debug(' chosen move is ' + str(move))

    ## test: take longer than the 1 sec allowd.
    # time.sleep(2)

    ## test: occasionaly crash (divide by zero error)        
    # if random.randint(1,10) == 3: a = 1/0

    return move

# You probably don't need to change this part.
for board in tron.Board.generate():
    tron.move(which_move(board))
#!/usr/bin/env python logbot.py   An example of a random bot which writes debug messages  and errors to a log file.   See the details of this approach to debugging in tron.py .   <NAME> | cs.marlboro.edu | Feb 2014 #      On csmarlboro.org, change 'everyone' to your username. #      Keep the rest of the path - that folder is world writable. #      This opens that file for appending, and writes one line #      to it with the date and time. # Change this to whatever you like. Return the direction to move (1,2,3,4) given a Board object. ## test: take longer than the 1 sec allowd. # time.sleep(2) ## test: occasionaly crash (divide by zero error) # if random.randint(1,10) == 3: a = 1/0 # You probably don't need to change this part.