Exemple #1
0
def init_view(context, request):
    session = request.session
    board = T3Game.reset([])
    session['board'] = board        
    
    #json_out tools will take this and convert it to valid JSON and set appropriate headers
    return dict(success = True, board = board )
Exemple #2
0
def init():
    with GetSession() as session:
        board = T3Game.reset([])
        session["board"] = board

        # json_out tools will take this and convert it to valid JSON and set appropriate headers
        return dict(success=True, board=board)
Exemple #3
0
def init_view(context, request):
    session = request.session
    board = T3Game.reset([])
    session['board'] = board

    #json_out tools will take this and convert it to valid JSON and set appropriate headers
    return dict(success=True, board=board)
Exemple #4
0
def init():
    with GetSession() as session:
        board = T3Game.reset([])
        session['board'] = board

        #json_out tools will take this and convert it to valid JSON and set appropriate headers
        return dict(success=True, board=board)
Exemple #5
0
def init(request):
    """
        Initializes the game logic on the server side
    """
    
    board = T3Game.reset([])
    request.session['board'] = board
    
    response = dict(success = True, board = board )
    return HttpResponse( dumps(response), content_type = "application/json" )
Exemple #6
0
def move(request, x, y):
    """
        returns a JSON object that
            must contain bool success, [...] board
                in error must contain str error
                on win must contain str msg, bool game_end
    """

    x = int(x)
    y = int(y)
    response = dict(success=False, board=None)

    board = request.session.get('board', T3Game.reset(None))
    board, player_won, error = T3Game.player_move(board, x, y)

    if error:
        response['error'] = error

    elif player_won == True:
        response['success'] = True
        response['board'] = request.session['board']
        response[
            'msg'] = "Success! You beat the super smart Tic-Tac-Toe AI but the Princess is in another castle."
        response['game_end'] = True

    else:
        board, cpu_won, error = T3Game.cpu_move(board)

        if error:
            response['error'] = error

        elif cpu_won == True:
            response['success'] = True
            response['board'] = request.session['board']
            #Trademarks are there for comedic effect and are not applicable
            response[
                'msg'] = "Somehow the Brute Force (tm) AI of Doom! (tm) has conquered you at Tic-Tac-Toe"
            response['game_end'] = True

    request.session['board'] = board
    response['board'] = board
    response['success'] = 'error' not in response
    return HttpResponse(dumps(response), content_type="application/json")
Exemple #7
0
def init(request):
    """
        Initializes the game logic on the server side
    """

    board = T3Game.reset([])
    request.session['board'] = board

    response = dict(success=True, board=board)
    return HttpResponse(dumps(response), content_type="application/json")
Exemple #8
0
def move(request, x, y):
    """
        returns a JSON object that
            must contain bool success, [...] board
                in error must contain str error
                on win must contain str msg, bool game_end
    """
    
    x = int(x)
    y = int(y)
    response = dict(success = False, board = None)
    
    board = request.session.get('board', T3Game.reset(None))
    board, player_won, error = T3Game.player_move(board, x, y)
    
    if error:
        response['error'] = error    
    
    elif player_won == True:
        response['success'] = True
        response['board'] = request.session['board']
        response['msg'] = "Success! You beat the super smart Tic-Tac-Toe AI but the Princess is in another castle."
        response['game_end'] = True
        
    else:
        board, cpu_won, error = T3Game.cpu_move(board)
        
        if error:
            response['error'] = error
            
        elif cpu_won == True:
            response['success'] = True
            response['board'] = request.session['board']
            #Trademarks are there for comedic effect and are not applicable
            response['msg'] = "Somehow the Brute Force (tm) AI of Doom! (tm) has conquered you at Tic-Tac-Toe"
            response['game_end'] = True
    
    
    request.session['board'] = board
    response['board'] = board
    response['success'] = 'error' not in response
    return HttpResponse(dumps(response), content_type = "application/json")
Exemple #9
0
def move_view(context, request):
    session = request.session
    x = int(request.matchdict['x'])
    y = int(request.matchdict['y'])

    response = dict(success=False, board=None)

    board = session.get("board", T3Game.reset(None))
    board, player_won, error = T3Game.player_move(board, x, y)

    if error:
        response['error'] = error

    elif player_won == True:
        response['success'] = True
        response['board'] = board
        response[
            'msg'] = "Success! You beat the super smart Tic-Tac-Toe AI but the Princess is in another castle."
        response['game_end'] = True

    else:
        board, cpu_won, error = T3Game.cpu_move(board)

        if error:
            response['error'] = error

        elif cpu_won == True:
            response['success'] = True
            response['board'] = board
            #Trademarks are there for comedic effect and are not applicable
            response[
                'msg'] = "Somehow the Brute Force (tm) AI of Doom! (tm) has conquered you at Tic-Tac-Toe"
            response['game_end'] = True

    session['board'] = board

    response['board'] = board
    response['x'] = x
    response['y'] = y
    response['success'] = 'error' not in response
    return response
Exemple #10
0
def move_view(context, request):
    session = request.session
    x = int(request.matchdict['x'])
    y = int(request.matchdict['y'])
    
    response = dict(success = False, board = None)
    
    board = session.get("board", T3Game.reset(None) )
    board, player_won, error = T3Game.player_move(board, x, y)
    
    if error:
        response['error'] = error    
    
    elif player_won == True:
        response['success'] = True
        response['board'] = board
        response['msg'] = "Success! You beat the super smart Tic-Tac-Toe AI but the Princess is in another castle."
        response['game_end'] = True
        
    else:
        board, cpu_won, error = T3Game.cpu_move(board)
        
        if error:
            response['error'] = error
            
        elif cpu_won == True:
            response['success'] = True
            response['board'] = board
            #Trademarks are there for comedic effect and are not applicable
            response['msg'] = "Somehow the Brute Force (tm) AI of Doom! (tm) has conquered you at Tic-Tac-Toe"
            response['game_end'] = True
    
    
    session['board'] = board
    
    response['board'] = board
    response['x'] = x
    response['y'] = y
    response['success'] = 'error' not in response
    return response
Exemple #11
0
def move(x, y):
    with GetSession() as session:
        x = int(x)
        y = int(y)
        response = dict(success=False, board=None)

        board = session.get("board", T3Game.reset(None))
        board, player_won, error = T3Game.player_move(board, x, y)

        if error:
            response["error"] = error

        elif player_won == True:
            response["success"] = True
            response["board"] = board
            response["msg"] = "Success! You beat the super smart Tic-Tac-Toe AI but the Princess is in another castle."
            response["game_end"] = True

        else:
            board, cpu_won, error = T3Game.cpu_move(board)

            if error:
                response["error"] = error

            elif cpu_won == True:
                response["success"] = True
                response["board"] = board
                # Trademarks are there for comedic effect and are not applicable
                response["msg"] = "Somehow the Brute Force (tm) AI of Doom! (tm) has conquered you at Tic-Tac-Toe"
                response["game_end"] = True

        session["board"] = board

        response["board"] = board
        response["success"] = "error" not in response
        return response
Exemple #12
0
 def init(self):
     board = T3Game.reset([])
     cherrypy.session['board'] = board        
     
     #json_out tools will take this and convert it to valid JSON and set appropriate headers
     return dict(success = True, board = board )
Exemple #13
0
    def init(self):
        board = T3Game.reset([])
        cherrypy.session['board'] = board

        #json_out tools will take this and convert it to valid JSON and set appropriate headers
        return dict(success=True, board=board)