def readCvv(fileName, encoding): h = open(unicode(fileName), 'r') contents = "\n".join([x.strip() for x in h.readlines()]) contents = unicode(contents.decode(encoding)) h.close() entries = [] for chunk in contents.split("\n\n"): lines = chunk.strip().split("\n") if len(lines) < 2: continue # removing Dg[x]=new Array line lines = lines[1:] # removing trailing semicolon lines[-1] = lines[-1][:-1] # changing brackets to square brackets: chunk = ''.join(lines) chunk = '[' + chunk[1:-1] + ']' e = yaml.load(chunk) # creating yacpdb-like entry entry = {} board = model.Board() imitators = [] for i in xrange(64): code = e[i>>3][i%8] if code: if code == 20: imitators.append(model.idxToAlgebraic(i)) else: board.add(fancyCodeToPiece(code), i) entry['algebraic'] = board.toAlgebraic() if e[8][0] != '': entry['authors'] = [e[8][0]] if e[9][0] != '': entry['source'] = e[9][0] if e[10][0] != '': entry['solution'] = "\n".join(e[10][0].split('\\n')) extra = e[11][0].split('\\n') stip_cond = extra[0].split(' ') entry['stipulation'] = stip_cond[0] entry['options'] = [] if len(imitators): entry['options'].append('Imitator ' + ''.join(imitators)) if len(stip_cond) > 1: entry['options'].extend(parseConditions(stip_cond[1:])) if len(extra) > 1: entry['twins'] = parseTwins(extra[1:]) entries.append(entry) return entries
def readCvv(fileName, encoding): h = open(unicode(fileName), 'r') contents = "\n".join([x.strip() for x in h.readlines()]) contents = unicode(contents.decode(encoding)) h.close() entries = [] for chunk in contents.split("\n\n"): lines = chunk.strip().split("\n") if len(lines) < 2: continue # removing Dg[x]=new Array line lines = lines[1:] # removing trailing semicolon lines[-1] = lines[-1][:-1] # changing brackets to square brackets: chunk = ''.join(lines) chunk = '[' + chunk[1:-1] + ']' e = yaml.load(chunk) # creating yacpdb-like entry entry = {} board = model.Board() imitators = [] for i in xrange(64): code = e[i >> 3][i % 8] if code: if code == 20: imitators.append(model.idxToAlgebraic(i)) else: board.add(fancyCodeToPiece(code), i) entry['algebraic'] = board.toAlgebraic() if e[8][0] != '': entry['authors'] = [e[8][0]] if e[9][0] != '': entry['source'] = e[9][0] if e[10][0] != '': entry['solution'] = "\n".join(e[10][0].split('\\n')) extra = e[11][0].split('\\n') stip_cond = extra[0].split(' ') entry['stipulation'] = stip_cond[0] entry['options'] = [] if len(imitators): entry['options'].append('Imitator ' + ''.join(imitators)) if len(stip_cond) > 1: entry['options'].extend(parseConditions(stip_cond[1:])) if len(extra) > 1: entry['twins'] = parseTwins(extra[1:]) entries.append(entry) return entries
def assertSemantics(self, b): err = None if b.board[self.departure] is None: err = "Departure from empty square " + model.idxToAlgebraic( self.departure) elif b.board[ self. arrival] is not None and self.capture == -1 and self.arrival != self.departure: err = "Arrival square " + model.idxToAlgebraic( self.arrival) + " is occupied but no capture is specified" elif b.board[ self. arrival] is not None and self.capture != self.arrival and self.arrival != self.departure: err = "Arrival square " + model.idxToAlgebraic(self.arrival) + \ " is occupied but capture is specified at " + model.idxToAlgebraic(self.capture) elif self.capture != -1 and b.board[self.capture] is None: err = "Capture at empty square " + model.idxToAlgebraic( self.capture) # todo: rebirth, recolorings if err is not None: raise Exception("Semantic error at depth %d: %s" % (self.depth, err))
def dump(self, level): s = " " * level + '->' + self.piece + model.idxToAlgebraic( self.square) + "\n" for tn in self.branches: s += tn.dump(level + 1) return s
def dump(self, level): s = " " * level + '->' + self.piece + model.idxToAlgebraic(self.square) + "\n" for tn in self.branches: s += tn.dump(level + 1) return s
def __str__(self): return "%s%s-%s " % (self.departant.name, model.idxToAlgebraic(self.departure), model.idxToAlgebraic(self.arrival))