コード例 #1
0
ファイル: views.py プロジェクト: richardtraindl/immanuel
def create(request):
    context = RequestContext(request)
    if(request.method == 'POST'):
        match = Match()

        match.white_player = request.POST['white_player']
        if(request.POST.get('white_player_human')):
            match.white_player_human = True
        else:
            match.white_player_human = False

        match.black_player = request.POST['black_player']
        if(request.POST.get('black_player_human')):
            match.black_player_human = True
        else:
            match.black_player_human = False

        levellist = request.POST.getlist('level')
        match.level = Match.LEVEL[levellist[0]]

        if(len(match.white_player) > 0 and len(match.black_player) > 0):
            match.setboardbase()
            match.save()
            calc_move_for_immanuel(match)
            return HttpResponseRedirect(reverse('kate:match', args=(match.id,)))
    return render(request, 'kate/new.html', { 'white_player': match.white_player, 'white_player_human': match.white_player_human, 'black_player': match.black_player, 'black_player_human': match.black_player_human } )
コード例 #2
0
ファイル: views.py プロジェクト: richardtraindl/immanuel
def match(request, matchid=None, switch=0):
    context = RequestContext(request)
    if(matchid == None):
        match = Match(white_player=None, black_player=None)
        match.setboardbase()
    else:
        match = Match.objects.get(id=matchid)

    lastmove = Move.objects.filter(match_id=match.id).order_by("count").last()
    if(lastmove):
        movesrc = Match.index_to_koord(lastmove.srcx, lastmove.srcy)
        movedst = Match.index_to_koord(lastmove.dstx, lastmove.dsty)
    else:
        movesrc = ''
        movedst = ''

    fmtboard = fill_fmtboard(match, int(switch))

    moves = []
    currmove = Move.objects.filter(match_id=match.id).order_by("count").last()
    if(currmove != None):
        if(currmove.count % 2 == 0):
            limit = 22
        else:
            limit = 21
        qmoves = Move.objects.filter(match_id=match.id).order_by("-count")[:limit]
        for qmove in reversed(qmoves):
            moves.append(qmove)

    comments = Comment.objects.filter(match_id=match.id).order_by("created_at").reverse()[:3]
    fmtmsg = "<p class='ok'></p>"
    if(int(switch) == 0):
        rangeobj = range(8)
    else:
        rangeobj = range(7, -1, -1)

    return render(request, 'kate/match.html', { 'match': match, 'board': fmtboard, 'switch': switch, 'movesrc': movesrc, 'movedst': movedst, 'moves': moves, 'comments': comments, 'msg': fmtmsg, 'range': rangeobj } )