Example #1
0
d['select3'] = generate_select('player3', player_choices, chosen[2])
d['select4'] = generate_select('player4', player_choices, chosen[3])
body += PLAYER_SELECT_AREA.format(**d)

# actually run the game simulation
try:
    game_trace = sandbox.complete_game(play_paths)
    body += "<p>Winner: {0}</p>".format(chosen[game_trace[0][-1]])
    round_count = 0
    prev_winner = 0

    for winner, round, hands in zip(*game_trace):
        round_count += 1
        play_names = cycle(chosen[(i+prev_winner)%4] for i in xrange(4))
    
        body += lists2ul(['HANDS', ["{0}({2}): {1}".format(p,str(sorted(h)),len(h)) for p,h in zip(chosen,hands)]])
        body += lists2ul(['ROUND {0}'.format(round_count),["{0}: {1}".format(*x) for x in zip(play_names,round)]])
        body += lists2ul(['WINNER', [chosen[winner]]])
        prev_winner = winner
    logger.info('players: {0} winner {1}'.format(chosen, chosen[winner]), extra=env_info)

except game.InvalidAction,e :
    body += "<p>Invalid Action: {0}</p>".format(e)
    body += "<p>Please remain calm. This incident has been logged.</p>"
    logger.info('InvalidAction: {1} players:{0}'.format(chosen, str(e)), extra=env_info)
    
except Exception, e:
    body += "<p>Exception Occurred:</p>"
    body += "<p>{0}: {1}</p>".format(e.__class__.__name__, str(e))
    body += "<p>Please remain calm. This incident has been logged.</p>"
    logger.info('{0}: {1} players:{2}'.format(e.__class__.__name__, str(e), chosen), extra=env_info)
Example #2
0
# actually run the game simulation
try:
    game_trace = sandbox.complete_game(play_paths)
    body += "<p>Winner: {0}</p>".format(chosen[game_trace[0][-1]])
    round_count = 0
    prev_winner = 0

    for winner, round, hands in zip(*game_trace):
        round_count += 1
        play_names = cycle(chosen[(i + prev_winner) % 4] for i in xrange(4))

        body += lists2ul([
            'HANDS',
            [
                "{0}({2}): {1}".format(p, str(sorted(h)), len(h))
                for p, h in zip(chosen, hands)
            ]
        ])
        body += lists2ul([
            'ROUND {0}'.format(round_count),
            ["{0}: {1}".format(*x) for x in zip(play_names, round)]
        ])
        body += lists2ul(['WINNER', [chosen[winner]]])
        prev_winner = winner
    logger.info('players: {0} winner {1}'.format(chosen, chosen[winner]),
                extra=env_info)

except game.InvalidAction, e:
    body += "<p>Invalid Action: {0}</p>".format(e)
    body += "<p>Please remain calm. This incident has been logged.</p>"
Example #3
0
    except Exception, e:
        body += "<p>The following exception was raised when importing your code:</p>"
        body += "<h2>{0}: {1}</h2><br>".format(e.__class__.__name__,e) 
        student_code = None
        
    t_pass = True    
    for t, t_fn in sandbox.TEST_SUITE:
        if hasattr(student_code, t):
            t_result = t_fn(getattr(student_code,t))
            t_pass = t_pass and t_result[0]
            
            body += "<p>Testing: {0}</p>".format(t)
            if add_player:
                body += "<p>{0}</p>".format("Pass" if t_result[0] else "Fail")
            else:
                body += lists2ul(t_result[1])
        else:
            body += "<p>No implementation of {0}!</p>".format(t)
            t_pass = False
    
    if add_player:
        if t_pass:
            # player qualifies for playground
            player_id = generate_id(source)

            if not os.path.isdir(PLAYERS_DIR):
                os.mkdir(PLAYERS_DIR)

            path = os.path.join(PLAYERS_DIR, player_id)
            with open(path,'w') as f:
                f.write(source)