示例#1
0
def html_board(match, switch, movesrc, movedst):
    fmtboard = fill_fmtboard(match, switch)
    htmldata = "<table id='board' matchid='" + str(match.id) + "' movecnt='" + str(match.count) + "'>"
    htmldata += "<tr id='board-letters1'><td>&nbsp;</td>"
    if(switch == 0):
        for i in range(8):
            htmldata += "<td>" + chr(i + ord('A')) + "</td>"
    else:
        for i in range(8):
            htmldata += "<td>" + chr(ord('H') - i) + "</td>"
    htmldata += "<td>&nbsp;</td></tr>"
    for row in fmtboard:
        htmldata += "<tr><td class='board-label'>" + str(row[0][1])[1] + "</td>"
        for col in row:
            if(col[1] == movesrc or col[1] == movedst):
                htmldata += "<td id='" + str(col[1]) + "' class='hint' value='" + str(col[0]) + "'>"
            else:
                htmldata += "<td id='" + str(col[1]) + "' value='" + str(col[0]) + "'>"

            if(col[0] == 0):
                htmldata += "&nbsp;"
            else:
                piece = helper.reverse_lookup(Match.PIECES, col[0])
                htmldata += "<img src='" + "/static/img/" + piece + ".png'>"
            htmldata += "</td>"
        htmldata += "<td class='board-label'>" + str(row[0][1])[1] + "</td></tr>"
    htmldata += "<tr id='board-letters2'><td>&nbsp;</td>"
    if(switch == 0):
        for i in range(8):
            htmldata += "<td>" + chr(i + ord('A')) + "</td>"
    else:
        for i in range(8):
            htmldata += "<td>" + chr(ord('H') - i) + "</td>"
    htmldata += "<td>&nbsp;</td></tr></table>"
    return htmldata
示例#2
0
def prnt_board(match):
    print("------------------------------------------------------")
    for i in range(7, -1, -1):
        for j in range(8):
            piece = match.readfield(j, i)
            print(helper.reverse_lookup(Match.PIECES, piece) + " ", end="")
        print("")
    print("------------------------------------------------------")
示例#3
0
def do_move(request, matchid):
    context = RequestContext(request)
    if request.method == 'POST':
        match = get_object_or_404(Match, pk=matchid)
        movesrc = request.POST['move_src']
        movedst = request.POST['move_dst']
        prompiece = request.POST['prom_piece']
        switch = request.POST['switch']
        if(match.next_color_human()):
            if(len(movesrc) > 0 and len(movedst) > 0 and len(prompiece) > 0):
                srcx,srcy = Match.koord_to_index(movesrc)
                dstx,dsty = Match.koord_to_index(movedst)
                prom_piece = match.PIECES[prompiece]
                flag, msg = rules.is_move_valid(match, srcx, srcy, dstx, dsty, prom_piece)
                status = rules.game_status(match)
                if(flag == True and status == Match.STATUS['open']):
                    move = match.do_move(srcx, srcy, dstx, dsty, prom_piece)
                    move.save()
                    match.save()
                    calc_move_for_immanuel(match)
                    fmtmsg = "<p class='ok'>" + rules.ERROR_MSGS[msg] + "</p>"
                else:
                    fmtmsg = "<p class='error'>" + rules.ERROR_MSGS[msg] + "</p>"
            else:
                fmtmsg = "<p class='error'>Zug-Format ist ungültig.</p>"
        else:
            fmtmsg = "<p class='error'>Farbe ist nicht am Zug.</p>"

        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]

        status = rules.game_status(match)
        if(status != Match.STATUS['open']):
            fmtmsg = "<p class='error'>" + helper.reverse_lookup(Match.STATUS, status) + "</p>"

        if(int(switch) == 0):
            rangeobj = range(8)
        else:
            rangeobj = range(7, -1, -1)

        candidate = ""

        return render(request, 'kate/match.html', { 'match': match, 'board': fmtboard, 'switch': switch, 'movesrc': movesrc, 'movedst': movedst, 'moves': moves, 'comments': comments, 'msg': fmtmsg, 'range': rangeobj, 'candidate': candidate } )
    else:
        return HttpResponseRedirect(reverse('kate:match', args=(matchid, switch)))
示例#4
0
def prnt_moves(match):
    count = 1
    print("------------------------------------------------------")
    for move in match.move_list[1:]:
        print(str(count) + ": " + 
              Match.index_to_koord(move.srcx, move.srcy) + " " +
              Match.index_to_koord(move.dstx, move.dsty) + " " +
              helper.reverse_lookup(Match.PIECES, move.prom_piece))
        count += 1
    print("------------------------------------------------------")
示例#5
0
def prnt_move(msg, move):
    print(msg + 
        Match.index_to_koord(move.srcx, move.srcy) + " " +
        Match.index_to_koord(move.dstx, move.dsty) + " " +
        helper.reverse_lookup(Match.PIECES, move.prom_piece), end="")
示例#6
0
def imgsrc(value):
    piece = helper.reverse_lookup(Match.PIECES, value)
    return "img/" + piece + ".png"
示例#7
0
def matchlevel(level):
    return helper.reverse_lookup(Match.LEVEL, level)
示例#8
0
 def format_move(self):
     if(self.move_type == self.TYPES['standard']):
         if(self.captured_piece == 0):
             hyphen = "-"
         else:
             hyphen = "x"
         fmtmove = Match.index_to_koord(self.srcx, self.srcy) + hyphen + Match.index_to_koord(self.dstx, self.dsty)
         return fmtmove
     elif(self.move_type == self.TYPES['short_castling']):
         return "0-0"
     elif(self.move_type == self.TYPES['long_castling']):
         return "0-0-0"
     elif(self.move_type == self.TYPES['promotion']):
         if(self.captured_piece == 0):
             hyphen = "-"
         else:
             hyphen = "x"
         fmtmove= Match.index_to_koord(self.srcx, self.srcy) + hyphen + Match.index_to_koord(self.dstx, self.dsty) + " " + helper.reverse_lookup(Match.PIECES, self.prom_piece)
         return fmtmove
     else:
         fmtmove= Match.index_to_koord(self.srcx, self.srcy) + "x" + Match.index_to_koord(self.dstx, self.dsty) + " e.p."
         return fmtmove