コード例 #1
0
ファイル: scorePanel.py プロジェクト: stevexyz/pychess
    def game_changed(self, model, ply):
        if len(self.plot) + model.lowply > ply:
            return

        for i in range(len(self.plot) + model.lowply, ply):
            if i in model.scores:
                points = model.scores[i][1]
                points = points * -1 if i % 2 == 1 else points
            else:
                points = leval.evaluateComplete(
                    model.getBoardAtPly(i).board, WHITE)
            self.plot.addScore(points)

        if model.status == DRAW:
            points = 0
        elif model.status == WHITEWON:
            points = sys.maxsize
        elif model.status == BLACKWON:
            points = -sys.maxsize
        else:
            if ply in model.scores:
                points = model.scores[ply][1]
                points = points * -1 if ply % 2 == 1 else points
            else:
                points = leval.evaluateComplete(
                    model.getBoardAtPly(ply).board, WHITE)
        self.plot.addScore(points)

        # As shownChanged will normally be emitted just after game_changed -
        # if we are viewing the latest position - we can do the selection change
        # now, and thereby avoid redraw being called twice
        if self.plot.selected == ply - model.lowply - 1:
            self.plot.select(ply - model.lowply)
        self.plot.redraw()
コード例 #2
0
ファイル: scorePanel.py プロジェクト: CarbonFixer/pychess
    def game_changed(self, model, ply):
        if len(self.plot) + model.lowply > ply:
            return

        for i in range(len(self.plot) + model.lowply, ply):
            if i in model.scores:
                points = model.scores[i][1]
            else:
                points = leval.evaluateComplete(
                    model.getBoardAtPly(i).board, WHITE)
            self.plot.addScore(points)

        if model.status == DRAW:
            points = 0
        elif model.status == WHITEWON:
            points = sys.maxsize
        elif model.status == BLACKWON:
            points = -sys.maxsize
        else:
            if ply in model.scores:
                points = model.scores[ply][1]
            else:
                points = leval.evaluateComplete(
                    model.getBoardAtPly(ply).board, WHITE)
        self.plot.addScore(points)

        # As shownChanged will normally be emitted just after game_changed -
        # if we are viewing the latest position - we can do the selection change
        # now, and thereby avoid redraw being called twice
        if self.plot.selected == ply - model.lowply - 1:
            self.plot.select(ply - model.lowply)
        self.plot.redraw()

        # Uncomment this to debug eval function
        return

        board = model.boards[-1].board
        opboard = model.boards[-1].clone().board
        opboard.setColor(1 - opboard.color)
        material, phase = leval.evalMaterial(board)
        if board.color == WHITE:
            print("material", -material)
            e1 = leval.evalKingTropism(board)
            e2 = leval.evalKingTropism(opboard)
            print("evaluation: %d + %d = %d " % (e1, e2, e1 + e2))
            p1 = leval.evalPawnStructure(board, phase)
            p2 = leval.evalPawnStructure(opboard, phase)
            print("pawns: %d + %d = %d " % (p1, p2, p1 + p2))
            print("knights:", -leval.evalKnights(board))
            print("king:", -leval.evalKing(board, phase))
        else:
            print("material", material)
            print("evaluation:", leval.evalKingTropism(board))
            print("pawns:", leval.evalPawnStructure(board, phase))
            print("pawns2:", leval.evalPawnStructure(opboard, phase))
            print("pawns3:", leval.evalPawnStructure(board, phase) +
                  leval.evalPawnStructure(opboard, phase))
            print("knights:", leval.evalKnights(board))
            print("king:", leval.evalKing(board, phase))
        print("----------------------")
コード例 #3
0
ファイル: scorePanel.py プロジェクト: skytreader/pychess
    def game_changed(self, model, ply):
        if len(self.plot) + model.lowply > ply:
            return

        for i in range(len(self.plot) + model.lowply, ply):
            if i in model.scores:
                points = model.scores[i][1]
            else:
                points = leval.evaluateComplete(
                    model.getBoardAtPly(i).board, WHITE)
            self.plot.addScore(points)

        if model.status == DRAW:
            points = 0
        elif model.status == WHITEWON:
            points = sys.maxsize
        elif model.status == BLACKWON:
            points = -sys.maxsize
        else:
            if ply in model.scores:
                points = model.scores[ply][1]
            else:
                points = leval.evaluateComplete(
                    model.getBoardAtPly(ply).board, WHITE)
        self.plot.addScore(points)

        # As shownChanged will normally be emitted just after game_changed -
        # if we are viewing the latest position - we can do the selection change
        # now, and thereby avoid redraw being called twice
        if self.plot.selected == ply - model.lowply - 1:
            self.plot.select(ply - model.lowply)
        self.plot.redraw()

        # Uncomment this to debug eval function
        return

        board = model.boards[-1].board
        opboard = model.boards[-1].clone().board
        opboard.setColor(1 - opboard.color)
        material, phase = leval.evalMaterial(board)
        if board.color == WHITE:
            print("material", -material)
            e1 = leval.evalKingTropism(board)
            e2 = leval.evalKingTropism(opboard)
            print("evaluation: %d + %d = %d " % (e1, e2, e1 + e2))
            p1 = leval.evalPawnStructure(board, phase)
            p2 = leval.evalPawnStructure(opboard, phase)
            print("pawns: %d + %d = %d " % (p1, p2, p1 + p2))
            print("knights:", -leval.evalKnights(board))
            print("king:", -leval.evalKing(board, phase))
        else:
            print("material", material)
            print("evaluation:", leval.evalKingTropism(board))
            print("pawns:", leval.evalPawnStructure(board, phase))
            print("pawns2:", leval.evalPawnStructure(opboard, phase))
            print("pawns3:", leval.evalPawnStructure(board, phase) +
                  leval.evalPawnStructure(opboard, phase))
            print("knights:", leval.evalKnights(board))
            print("king:", leval.evalKing(board, phase))
        print("----------------------")
コード例 #4
0
ファイル: scorePanel.py プロジェクト: teacoffee2017/pychess
    def game_changed(self, model, ply):
        if len(self.plot) + model.lowply > ply:
            return

        for i in range(len(self.plot) + model.lowply, ply):
            if i in model.scores:
                points = model.scores[i][1]
                points = points * -1 if i % 2 == 1 else points
            else:
                points = leval.evaluateComplete(
                    model.getBoardAtPly(i).board, WHITE)
            self.plot.addScore(points)

        if model.status == DRAW:
            points = 0
        elif model.status == WHITEWON:
            points = sys.maxsize
        elif model.status == BLACKWON:
            points = -sys.maxsize
        else:
            if ply in model.scores:
                points = model.scores[ply][1]
                points = points * -1 if ply % 2 == 1 else points
            else:
                points = leval.evaluateComplete(
                    model.getBoardAtPly(ply).board, WHITE)
        self.plot.addScore(points)

        # As shownChanged will normally be emitted just after game_changed -
        # if we are viewing the latest position - we can do the selection change
        # now, and thereby avoid redraw being called twice
        if self.plot.selected == ply - model.lowply - 1:
            self.plot.select(ply - model.lowply)
        self.plot.redraw()
コード例 #5
0
def save(handle, model, position=None, flip=False):
    """Saves game to file in fen format"""

    color = model.boards[-1].color

    fen = model.boards[-1].asFen().split(" ")

    # First four parts of fen are the same in epd
    handle.write(" ".join(fen[:4]))

    ############################################################################
    # Repetition count                                                         #
    ############################################################################
    rep_count = model.boards[-1].board.repetitionCount()

    ############################################################################
    # Centipawn evaluation                                                     #
    ############################################################################
    if model.status == WHITEWON:
        if color == WHITE:
            ceval = 32766
        else:
            ceval = -32766
    elif model.status == BLACKWON:
        if color == WHITE:
            ceval = -32766
        else:
            ceval = 32766
    elif model.status == DRAW:
        ceval = 0
    else:
        ceval = evaluateComplete(model.boards[-1].board,
                                 model.boards[-1].color)

    ############################################################################
    # Opcodes                                                                  #
    ############################################################################
    opcodes = (
        ("fmvn", fen[5]),  # In fen full move number is the 6th field
        ("hmvc", fen[4]),  # In fen halfmove clock is the 5th field

        # Email and name of receiver and sender. We don't know the email.
        ("tcri", "?@?.? %s" % repr(model.players[color]).replace(";", "")),
        ("tcsi", "?@?.? %s" % repr(model.players[1 - color]).replace(";", "")),
        ("ce", ceval),
        ("rc", rep_count),
    )

    for key, value in opcodes:
        handle.write(" %s %s;" % (key, value))

    ############################################################################
    # Resign opcode                                                            #
    ############################################################################
    if model.status in (WHITEWON, BLACKWON) and model.reason == WON_RESIGN:
        handle.write(" resign;")

    print("", file=handle)
    handle.close()
コード例 #6
0
ファイル: epd.py プロジェクト: oldstylejoe/pychess-timed
def save(file, model, position=None):
    """Saves game to file in fen format"""

    color = model.boards[-1].color

    fen = model.boards[-1].asFen().split(" ")

    # First four parts of fen are the same in epd
    file.write(" ".join(fen[:4]))

    ############################################################################
    # Repetition count                                                         #
    ############################################################################
    rc = model.boards[-1].board.repetitionCount()

    ############################################################################
    # Centipawn evaluation                                                     #
    ############################################################################
    if model.status == WHITEWON:
        if color == WHITE:
            ce = 32766
        else:
            ce = -32766
    elif model.status == BLACKWON:
        if color == WHITE:
            ce = -32766
        else:
            ce = 32766
    elif model.status == DRAW:
        ce = 0
    else:
        ce = evaluateComplete(model.boards[-1].board, model.boards[-1].color)

    ############################################################################
    # Opcodes                                                                  #
    ############################################################################
    opcodes = (
        ("fmvn", fen[5]),  # In fen full move number is the 6th field
        ("hmvc", fen[4]),  # In fen halfmove clock is the 5th field
        # Email and name of reciever and sender. We don't know the email.
        ("tcri", "?@?.? %s" % repr(model.players[color]).replace(";", "")),
        ("tcsi", "?@?.? %s" % repr(model.players[1 - color]).replace(";", "")),
        ("ce", ce),
        ("rc", rc),
    )

    for key, value in opcodes:
        file.write(" %s %s;" % (key, value))

    ############################################################################
    # Resign opcode                                                            #
    ############################################################################
    if model.status in (WHITEWON, BLACKWON) and model.reason == WON_RESIGN:
        file.write(" resign;")

    print("", file=file)
    file.close()
コード例 #7
0
ファイル: eval.py プロジェクト: zuzak/pychess
 def test2(self):
     """Testing eval symmetry with startboard (BLACK)"""
     score = evaluateComplete(self.board, color=BLACK)
     self.assertEqual(score, 0)
コード例 #8
0
ファイル: eval.py プロジェクト: zuzak/pychess
 def test1(self):
     """Testing eval symmetry with startboard (WHITE)"""
     score = evaluateComplete(self.board, color=WHITE)
     self.assertEqual(score, 0)
コード例 #9
0
 def test3(self):
     """Testing eval symmetry between colors with balanced=False"""
     scorew = evaluateComplete(self.board, color=WHITE)
     scoreb = evaluateComplete(self.board, color=BLACK)
     self.assertEqual(scorew, scoreb)
コード例 #10
0
ファイル: eval.py プロジェクト: Alex-Linhares/pychess
 def test2(self):
     """Testing eval symmetry with startboard (BLACK)"""
     score = evaluateComplete(self.board, color=BLACK)
     self.assertEqual(score, 0)
コード例 #11
0
ファイル: eval.py プロジェクト: Alex-Linhares/pychess
 def test1(self):
     """Testing eval symmetry with startboard (WHITE)"""
     score = evaluateComplete(self.board, color=WHITE)
     self.assertEqual(score, 0)
コード例 #12
0
 def test3(self):
     """Testing eval symmetry between colors with balanced=False"""
     scorew = evaluateComplete(self.board, color=WHITE)
     scoreb = evaluateComplete(self.board, color=BLACK)
     self.assertEqual(scorew, scoreb)