Beispiel #1
0
def calculateOrthoGlobally():
    i = 0
    for e in dao.allEntries():
        dao.ixr_updateEntryOrtho(e["id"], not model.hasFairyElements(e))
        i += 1
        if i % 10000 == 0:
            print(i)
Beispiel #2
0
def validate(entry, propagate_exceptions=True):

    r = {'success': False, "errors": []}

    if not "solution" in entry or entry["solution"].strip() == "":
        r["errors"].append("No solution")
        return r

    if not "algebraic" in entry:
        r["errors"].append("No position")
        return r

    if not "stipulation" in entry:
        r["errors"].append("No stipulation")
        return r

    if not validateStipulation(entry["stipulation"], r):
        return r

    try:
        solution = parser.parse(entry["solution"], debug=0)
        b = model.Board()
        b.fromAlgebraic(entry["algebraic"])
        b.stm = b.getStmByStipulation(entry["stipulation"])
        solution.traverse(b, SemanticValidationVisitor())
    except Exception as ex:
        if propagate_exceptions:
            raise ex
        r["errors"].append(str(ex))
        return r

    return {'success': True, 'orthodox': not model.hasFairyElements(entry)}
Beispiel #3
0
def calculateOrthoGlobally():
    i = 0
    for e in dao.allEntries():
        dao.ixr_updateEntryOrtho(e["id"], not model.hasFairyElements(e))
        i += 1
        if i % 10000 == 0:
            print i
Beispiel #4
0
 def checkCurrentEntry(self):
     if model.hasFairyElements(self.Mainframe.model.cur()):
         return None
     m = CHESTSTIPULATION.match(self.Mainframe.model.cur()['stipulation'])
     if not m:
         return None
     retval = {
         'type-of-play':m.group(1), #                                                '', s or h
         'goal':m.group(2), #                                                        # or =
         'full-moves': int(m.group(3)) + [1, 0][m.group(4) is None], #               integer
         'side-to-play':['b', 'w'][(m.group(1) == 'h') != (m.group(4) is None)]} #   w or b
     return retval
Beispiel #5
0
 def checkCurrentEntry(self):
     if model.hasFairyElements(self.Mainframe.model.cur()):
         return None
     m = CHESTSTIPULATION.match(self.Mainframe.model.cur()['stipulation'])
     if not m:
         return None
     retval = {
         'type-of-play': m.group(1),  # '', s or h
         'goal': m.group(2),  # or =
         # integer
         'full-moves': int(m.group(3)) + [1, 0][m.group(4) is None],
         'side-to-play': ['b', 'w'][(m.group(1) == 'h') != (m.group(4) is None)]}  # w or b
     return retval
Beispiel #6
0
def validate(entry, propagate_exceptions=True):

    try:
        jsonschema.validate(instance=entry, schema=json_schema)
        validateStipulation(entry["stipulation"])
        solution = parser.parse(entry["solution"], debug=0)
        b = model.Board()
        b.fromAlgebraic(entry["algebraic"])
        b.stm = b.getStmByStipulation(entry["stipulation"])
        solution.traverse(b, SemanticValidationVisitor())
    except (jsonschema.ValidationError, StipulationError) as ex:
        if propagate_exceptions:
            raise ex
        return {'success': False, "errors": [ex.message]}
    except Exception as ex:
        if propagate_exceptions:
            raise ex
        return {'success': False, "errors": [str(ex)]}

    return {'success': True, 'orthodox': not model.hasFairyElements(entry)}
Beispiel #7
0
 def isApplicable(self, entry):
     matches = model.RE_COMMON_STIPULATION.match(entry['stipulation'])
     if not (matches and matches.group("aim") == "#"
             and matches.group("play").lower() == "h"):
         return False  # not a helpmate
     return not model.hasFairyElements(entry)
Beispiel #8
0
def hasFairyElements(current):
    if model.hasFairyElements(current):
        # print current['options']
        return True
    return False
Beispiel #9
0
    def onModelChanged(self):
        e = self.Mainframe.model.cur()
        brd = self.Mainframe.model.board
        # TODO #2: translate messages
        # self.input.setText(self.Mainframe.model.board.toFen() + " " + self.Mainframe.model.cur()['stipulation'])
        if not CHESTSTIPULATION.match(e['stipulation'].lower()):
            self.input.setText('Stipulation is not supported by Chest')
            self.btnRun.setEnabled(False)
            return

        if not isOrthodox(brd.toFen()):
            self.input.setText('Chest can only solve orthodox problems')
            self.btnRun.setEnabled(False)
            return

        if model.hasFairyElements(e):
            self.input.setText("Chest doesn't support fairy elements")
            self.btnRun.setEnabled(False)
            return

        self.btnRun.setEnabled(True)
        input_str = "LE\nf " + brd.toFen().replace("S", "N").replace("s", "n") + "\n"
        # input_str += "cws\ncwl\ncbs\ncbl\n" #castling

        option = checkOption(e, 'NoCastling')
        if str(
                brd.board[56]) == 'white rook' and str(
                brd.board[60]) == 'white king':
            if not option or 'a1' not in option:
                input_str += 'cwl\n'
        if str(
                brd.board[63]) == 'white rook' and str(
                brd.board[60]) == 'white king':
            if not option or 'h1' not in option:
                input_str += 'cws\n'
        if str(
                brd.board[0]) == 'black rook' and str(
                brd.board[4]) == 'black king':
            if not option or 'a8' not in option:
                input_str += 'cbl\n'
        if str(
                brd.board[7]) == 'black rook' and str(
                brd.board[4]) == 'black king':
            if not option or 'h8' not in option:
                input_str += 'cbs\n'

        option = checkOption(e, 'EnPassant')

        if option:
            aux = option.replace('EnPassant ', '')
            enp = 'e' + aux[0] + ('4' if aux[1] == '3' else '5')
            # print enp
            input_str += enp + "\n"

        # stip preparing
        # better to wrap into a method?
        stip, stipulation, move = e['stipulation'].lower(), {}, 'w'
        if '#' in stip:
            stipulation = stip.split('#')
            if stipulation[0] != '':
                input_str += "j" + stipulation[0] + "\n"
        elif '=' in stip:
            stipulation = stip.split('=')
            if stipulation[0] != '':
                input_str += "j" + stipulation[0].upper() + "\n"
            else:
                stipulation[0] = 'O'

        if stipulation[0] == 'h' or stipulation[0] == 'H':
            if '.' in stipulation[1]:
                self.input.setText('Chest cant solve helpmates with halfmoves')
                return
            else:
                move = 'b'
        input_str += "z" + stipulation[1] + move + "\n"

        self.input.setText(input_str)
Beispiel #10
0
    def onModelChanged(self):
        e = self.Mainframe.model.cur()
        brd = self.Mainframe.model.board
        # TODO #2: translate messages
        # self.input.setText(self.Mainframe.model.board.toFen() + " " + self.Mainframe.model.cur()['stipulation'])
        if not CHESTSTIPULATION.match(e['stipulation'].lower()):
            self.input.setText('Stipulation is not supported by Chest')
            self.btnRun.setEnabled(False)
            return

        if not isOrthodox(brd.toFen()):
            self.input.setText('Chest can only solve orthodox problems')
            self.btnRun.setEnabled(False)
            return

        if model.hasFairyElements(e):
            self.input.setText("Chest doesn't support fairy elements")
            self.btnRun.setEnabled(False)
            return

        self.btnRun.setEnabled(True)
        input_str = "LE\nf " + brd.toFen().replace("S", "N").replace("s", "n") + "\n"
        # input_str += "cws\ncwl\ncbs\ncbl\n" #castling

        option = checkOption(e, 'NoCastling')
        if str(
                brd.board[56]) == 'white rook' and str(
                brd.board[60]) == 'white king':
            if not option or 'a1' not in option:
                input_str += 'cwl\n'
        if str(
                brd.board[63]) == 'white rook' and str(
                brd.board[60]) == 'white king':
            if not option or 'h1' not in option:
                input_str += 'cws\n'
        if str(
                brd.board[0]) == 'black rook' and str(
                brd.board[4]) == 'black king':
            if not option or 'a8' not in option:
                input_str += 'cbl\n'
        if str(
                brd.board[7]) == 'black rook' and str(
                brd.board[4]) == 'black king':
            if not option or 'h8' not in option:
                input_str += 'cbs\n'

        option = checkOption(e, 'EnPassant')

        if option:
            aux = option.replace('EnPassant ', '')
            enp = 'e' + aux[0] + ('4' if aux[1] == '3' else '5')
            # print enp
            input_str += enp + "\n"

        # stip preparing
        # better to wrap into a method?
        stip, stipulation, move = e['stipulation'].lower(), {}, 'w'
        if '#' in stip:
            stipulation = stip.split('#')
            if stipulation[0] != '':
                input_str += "j" + stipulation[0] + "\n"
        elif '=' in stip:
            stipulation = stip.split('=')
            if stipulation[0] != '':
                input_str += "j" + stipulation[0].upper() + "\n"
            else:
                stipulation[0] = 'O'

        if stipulation[0] == 'h' or stipulation[0] == 'H':
            if '.' in stipulation[1]:
                self.input.setText('Chest cant solve helpmates with halfmoves')
                return
            else:
                move = 'b'
        input_str += "z" + stipulation[1] + move + "\n"

        self.input.setText(input_str)
Beispiel #11
0
 def isApplicable(self, entry):
     matches = model.RE_COMMON_STIPULATION.match(entry['stipulation'])
     if not (matches and matches.group("aim") == "#" and matches.group("play").lower() == "h"):
         return False # not a helpmate
     return not model.hasFairyElements(entry)
Beispiel #12
0
 def analyze(self, entry, solution, board, acc):
     matches = model.RE_COMMON_STIPULATION.match(entry['stipulation'])
     if not matches or matches.group("aim") not in "#=" or model.hasFairyElements(entry):
         return
     aim = matches.group("aim")
Beispiel #13
0
def hasFairyElements(current):
    if model.hasFairyElements(current):
        # print current['options']
        return True
    return False
Beispiel #14
0
 def analyze(self, entry, solution, board, acc):
     matches = model.RE_COMMON_STIPULATION.match(entry['stipulation'])
     if not matches or matches.group(
             "aim") not in "#=" or model.hasFairyElements(entry):
         return
     aim = matches.group("aim")