Exemple #1
0
def human_move(request):
    """
    AJAX view used to determine if human's move has won
    """
    board, mark = logic.construct_board(request)
    win = logic.check_for_win(board, mark)
    return json_response(json.dumps({'is_winner': win}))
Exemple #2
0
def computer_move(request):
    """
    AJAX view used to calculate computer player's next move
    """
    board, mark = logic.construct_board(request)
    position, win = logic.determine_computer_move(board, mark)
    board[position] = mark if position != -1 else board[position]
    draw = not win and (position == -1 or ' ' not in board)
    return json_response(json.dumps(
                                    {'position': position,
                                     'is_winner': win,
                                     'is_draw': draw}
                                    ))