Esempio n. 1
0
def launch_match(request, game_id=None, number_of_bots=None):

    if not game_id:
        game = None
    else:
        game = Game.objects.get(id=game_id)

    if number_of_bots:
        number_of_bots = int(number_of_bots)
    bot_form = None
    game_form = None
    bot = None

    if request.method == 'POST':

        if 'game_form' in request.POST:
            game_form = GameSelectForm(request.POST, prefix='game')
            if game_form.is_valid():
                game = game_form.cleaned_data['game_field']
                number_of_bots = int(game_form.cleaned_data['number_of_bots'])
                bot_form = BotSelectForm(game=game,
                                         number_of_bots=number_of_bots,
                                         prefix='bot')

        if 'bot_form' in request.POST:
            bot_form = BotSelectForm(request.POST,
                                     game=game,
                                     number_of_bots=number_of_bots,
                                     prefix='bot')
            if bot_form.is_valid():
                bots = []
                for i in range(number_of_bots):
                    bots.append(bot_form.cleaned_data['bot_field%d' % (i + 1)])
                    launch_single_match(game, bots)
                    return redirect('/')

    if not game_form:
        game_form = GameSelectForm(prefix='game')

    if game and not bot_form:
        bot_form = BotSelectForm(game=game,
                                 number_of_bots=number_of_bots,
                                 prefix='bot')

    if game:
        game_id = game.id

    return render_to_response('gaming/launch_match.html', {
        'game_form': game_form,
        'bot_form': bot_form,
        'game_id': game_id,
        'number_of_bots': number_of_bots,
    },
                              context_instance=RequestContext(request))
Esempio n. 2
0
def launch_match(request, game_id=None, number_of_bots=None):
    """
        Launches match for the selected game, with selected bots.
    """

    if not game_id:
        game = None
    else:
        game = Game.objects.get(id=game_id)

    if number_of_bots:
        number_of_bots = int(number_of_bots)
    bot_form = None
    game_form = None
    bot = None

    if request.method == 'POST':

        # handle game selection form
        if 'game_form' in request.POST:
            game_form = GameSelectForm(request.POST, prefix='game')
            if game_form.is_valid():
                game = game_form.cleaned_data['game_field']
                number_of_bots=int(game_form.cleaned_data['number_of_bots'])
                bot_form = BotsSelectForm(game=game, number_of_bots=number_of_bots, prefix='bot')

        # handle bot selection form
        if 'bot_form' in request.POST:
            bot_form = BotsSelectForm(request.POST, game=game, number_of_bots=number_of_bots, prefix='bot')
            if bot_form.is_valid():
                bots = []
                for i in range(number_of_bots):
                    bots.append(bot_form.cleaned_data['bot_field%d' % (i+1)])
                launch_single_match(game, bots)
                return redirect('/')

    if not game_form:
        game_form = GameSelectForm(prefix='game')

    if game and not bot_form:
        bot_form = BotsSelectForm(game=game, number_of_bots=number_of_bots, prefix='bot')

    if game:
        game_id = game.id

    return render_to_response('gaming/launch_match.html',
            {
                'game_form':game_form,
                'bot_form':bot_form,
                'game_id':game_id,
                'number_of_bots':number_of_bots,
            },
            context_instance=RequestContext(request)
        )
Esempio n. 3
0
def testing(request):
    """
        View responsible for displaying form to upload Bots to test.\n
        Using provided form User can upload one or two Bot's source codes.
        In case of uploading two source codes system performs a Match between these two Bots. If User uploads only one source code, then 
        system performs Match against default Bot.
    """
    if request.method == 'POST':
        form = MayContestSendBotForTest(request.POST, request.FILES)
        if not form.is_valid():
            return render_to_response('may_contest/testing.html',
                    {
                        'form': form,
                    },
                    context_instance=RequestContext(request))
        else:
            # Handle a bot
            (exit_status, logs, bot) = create_bot_from_request(request, get_may_game(), testing=True)
            if exit_status != 0:
                return render_to_response('error.html',
                        {
                            'error_details': logs,
                        },
                        context_instance = RequestContext(request))

            # Check is user uploaded also an opponent
            # If so - handle it
            if 'opponent_source' in request.FILES:
                (exit_status, logs, opp) = create_bot_from_request(request, get_may_game(), bot_field='opponent_source', testing=True)
                if exit_status != 0:
                    # error occured
                    return render_to_response('error.html',
                            {
                                'error_details': logs,
                            },
                            context_instance = RequestContext(request))
            # otherwise - use default bot as an opponent
            else: 
                opp = get_default_may_contest_bot()
            
            launch_single_match(get_may_game(), [bot, opp])
            
            return HttpResponseRedirect('/testing/uploaded/')

    else:
        form = MayContestSendBotForTest()
        return render_to_response('may_contest/testing.html',
            {
                'form': form,
                'judge_path': settings.MAY_CONTEST_EXAMPLE_JUDGE_PATH,
                'bot_path': settings.MAY_CONTEST_EXAMPLE_BOT_PATH,
                'judge_manual_path': settings.MAY_CONTEST_JUDGE_MANUAL_PATH,
            },
            context_instance=RequestContext(request))