def fetch_match(request): context = RequestContext(request) matchid = request.GET['matchid'] movecnt = request.GET['movecnt'] switchflag = request.GET['switchflag'] match = Match.objects.get(id=matchid) if(match == None): data = "§§" else: lastmove = Move.objects.filter(match_id=match.id).order_by("count").last() if(lastmove != None): movesrc = Match.index_to_koord(lastmove.srcx, lastmove.srcy) movedst = Match.index_to_koord(lastmove.dstx, lastmove.dsty) if(int(movecnt) == match.count): data = "§" else: data = html_board(match, int(switchflag), movesrc, movedst) + "§" + html_moves(match) thread = Match.get_active_thread(match) if(thread and not thread.candidate_srcx): data += "§<p>thread found with matchid: " + str(thread.match.id) + "</p>" elif(thread and thread.candidate_srcx): data += "§<p>move candidate: " data += Match.index_to_koord(thread.candidate_srcx, thread.candidate_srcy) + "-" + Match.index_to_koord(thread.candidate_dstx, thread.candidate_dsty) data += "</p>" else: data += "§" return HttpResponse(data)
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("------------------------------------------------------")
def retrieve_move(match): if(match.count == 0): omoves = OpeningMove.objects.filter(movecnt=1) if(omoves): idx = random.randint(0, len(omoves) - 1) x1, y1 = Match.koord_to_index(omoves[idx].src) x2, y2 = Match.koord_to_index(omoves[idx].dst) gmove = calc.GenMove(x1, y1, x2, y2, Match.PIECES['blk']) print("------------ opening move found! --------------") return gmove else: print("############ No opening move found ############") return None lastmove = Move.objects.get(match_id=match.id, count=match.count) movesrc = Match.index_to_koord(lastmove.srcx, lastmove.srcy) movedst = Match.index_to_koord(lastmove.dstx, lastmove.dsty) prev_omoves = OpeningMove.objects.filter(movecnt=match.count, src=movesrc, dst=movedst) prev_list = list(prev_omoves) for prev_omove in prev_omoves: previous = prev_omove.previous while(previous): try: move = Move.objects.get(match_id=match.id, count=previous.movecnt) except Move.DoesNotExist: print("---------None---------") return None prevsrc = Match.index_to_koord(move.srcx, move.srcy) prevdst = Match.index_to_koord(move.dstx, move.dsty) if(previous.src != prevsrc or previous.dst != prevdst): prev_list.remove(prev_omove) break previous = previous.previous if(prev_list): previous = prev_list[0] omoves = OpeningMove.objects.filter(movecnt=match.count + 1, previous_id=previous.id) if(omoves): idx = random.randint(0, len(omoves) - 1) x1, y1 = Match.koord_to_index(omoves[idx].src) x2, y2 = Match.koord_to_index(omoves[idx].dst) gmove = calc.GenMove(x1, y1, x2, y2, Match.PIECES['blk']) print("------------ opening move found! --------------") return gmove else: print("############ 1: No opening move found! ###############") return None else: print("############ 2: No opening move found! ###############") return None
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 } )
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="")