def fenToBoardMap(fen): [fenA, fenB] = fen.split(' | ') mapping = {} mapping['boardA'] = CrazyLogic.fenToBoardMap(fenA) mapping['boardB'] = CrazyLogic.fenToBoardMap(fenB) return mapping
def __init__(self, parent, pieceWidth=48, pieceHeight=48): Tkinter.Frame.__init__(self, parent) self.parent = parent self.boardMap = CrazyLogic.fenToBoardMap(Common.initCrazyFEN) self.cb = CrazyBoard(self) self.cb.setBoardMap(self.boardMap) self.cb.draw() self.cb.pack() self.b = Tkinter.Button(self, text="flip", command=self.flipIt) self.b.pack() self.moveEntry = Tkinter.Entry(self) self.moveEntry.pack() self.execMove = Tkinter.Button(self, text="execute move", command=self.executeMove) self.execMove.pack() self.fenEntry = Tkinter.Entry(self) self.fenEntry.pack() self.loadFen = Tkinter.Button(self, text="load fen", command=self.loadFen) self.loadFen.pack()
def genCards(currentLine, depth): if depth == 12: return #-------- # get the branches totalBranches = getTotalBranches(g_curs, currentLine) possibleNextPly = getPossibleNextPly(g_curs, currentLine) # calculate the popularity of each candidate move possibleNextPlyPopularity = {} for candidate in possibleNextPly: cTotalBranches = 1.0 * getTotalBranches(curs, currentLine + [candidate]) possibleNextPlyPopularity[candidate] = (cTotalBranches / totalBranches) * 100 # sort the possibilities possibleNextPly = sorted(possibleNextPly, key=lambda x: possibleNextPlyPopularity[x], reverse=True) # and filter the bad ones possibleNextPly = filter(lambda x: possibleNextPlyPopularity[x] >= 10.0, possibleNextPly) #-------- # play the moves to get the board state boardMap = CrazyLogic.fenToBoardMap(Common.initCrazyFEN) for move in currentLine: boardMap = CrazyLogic.nextStateInternal(boardMap, move, 0, 1) # draw the board, get the html # if black to play, flip board so we see from black's angle doFlip = len(currentLine) % 2 html = '' html += boardMapToHtml(boardMap, doFlip) html = re.sub('\n', '', html) html = re.sub('\.\/images\/', '', html) # draw the answers html += ';' for index, thing in enumerate(possibleNextPly): html += ("%s (%.02f%%)" % (possibleNextPly[index], possibleNextPlyPopularity[possibleNextPly[index]])) html += '<br />' # draw the line html += '<br />' html += '(line here is: ' + ','.join(currentLine) + ')' print html #-------- # now recur for ply in possibleNextPly: genCards(currentLine + [ply], depth + 1)
def loadFen(self): whatFen = self.fenEntry.get() print "Loading fen: " + whatFen self.boardMap = CrazyLogic.fenToBoardMap(whatFen) self.cb.setBoardMap(self.boardMap) self.cb.draw()
conn = sqlite3.connect("MineMissedMates.db") curs = conn.cursor() bpgns = curs.execute("select position, mate from data where mate != ''") for rowIdx, row in enumerate(bpgns.fetchall()): (bfen, line) = map(lambda x: str(x), row) m = re.match('^(.*?) ', line) if not m: raise Exception("WTF? can't get first move from %s" % line) hint = m.group(1) boardMap = CrazyLogic.fenToBoardMap(bfen) flipped = 0 if boardMap['activePlayer'] == 'b': flipped = 1 html = GenTools.boardMapToHtml(boardMap, flipped, imgPath) html += "<h2>Puzzle %d</h2>\n" % rowIdx html += "<hr>\n" if anki: html = re.sub('\n', '', html) html = '%s;figure it out?' % html puzzleArray.append(html)