Not logged inCSS-Forum
Forum CSS-Online Help Search Login
CSS-Shop Impressum Datenschutz
Up Topic Hauptforen / Schachprogrammierung / Python Programmierung
- - By Lothar Jung Date 2021-08-20 20:33 Edited 2021-08-20 20:42
Hier ein deutschsprachiges Tutorial:

https://readthedocs.org/projects/py-tutorial-de/downloads/pdf/python-3.3/

Hier ein deutschsprachiger Kurs:

https://www.python-kurs.eu/python3_entstehung_python.php
Parent - By Lothar Jung Date 2021-08-31 18:30 Edited 2021-08-31 18:37
Hier ein Python Schachprogramm Sunset in 111 Zeilen:

class Position(namedtuple('Position', 'board score wc bc ep kp')):
    def gen_moves(self):
        for i, p in enumerate(self.board):
            if not p.isupper(): continue
            for d in directions[p]:
                for j in count(i+d, d):
                    q = self.board[j]
                    if q.isspace() or q.isupper(): break
                    if p == 'P' and d in (N, N+N) and q != '.': break
                    if p == 'P' and d == N+N and (i < A1+N or self.board[i+N] != '.'): break
                    if p == 'P' and d in (N+W, N+E) and q == '.' \
                            and j not in (self.ep, self.kp, self.kp-1, self.kp+1): break
                    yield (i, j)
                    if p in 'PNK' or q.islower(): break
                    if i == A1 and self.board[j+E] == 'K' and self.wc[0]: yield (j+E, j+W)
                    if i == H1 and self.board[j+W] == 'K' and self.wc[1]: yield (j+W, j+E)
    def rotate(self):
        return Position(self.board[::-1].swapcase(), -self.score, self.bc, self.wc,
                        119-self.ep if self.ep else 0, 119-self.kp if self.kp else 0)
    def nullmove(self):
        return Position(self.board[::-1].swapcase(), -self.score, self.bc, self.wc, 0, 0)
    def move(self, move):
        i, j = move
        p, q = self.board, self.board[j]
        put = lambda board, i, p: board[:i] + p + board[i+1:]
        board = self.board
        wc, bc, ep, kp = self.wc, self.bc, 0, 0
        score = self.score + self.value(move)
        board = put(board, j, board)
        board = put(board, i, '.')
        if i == A1: wc = (False, wc[1])
        if i == H1: wc = (wc[0], False)
        if j == A8: bc = (bc[0], False)
        if j == H8: bc = (False, bc[1])
        if p == 'K':
            wc = (False, False)
            if abs(j-i) == 2:
                kp = (i+j)//2
                board = put(board, A1 if j < i else H1, '.')
                board = put(board, kp, 'R')
        if p == 'P':
            if A8 <= j <= H8: board = put(board, j, 'Q')
            if j - i == 2*N: ep = i + N
            if j == self.ep: board = put(board, j+S, '.')
        return Position(board, score, wc, bc, ep, kp).rotate()
    def value(self, move):
        i, j = move
        p, q = self.board, self.board[j]
        score = pst[p][j] - pst[p]
        if q.islower(): score += pst[q.upper()][119-j]
        if abs(j-self.kp) < 2: score += pst['K'][119-j]
        if p == 'K' and abs(i-j) == 2:
            score += pst['R'][(i+j)//2]
            score -= pst['R'][A1 if j < i else H1]
        if p == 'P':
            if A8 <= j <= H8: score += pst['Q'][j] - pst['P'][j]
            if j == self.ep: score += pst['P'][119-(j+S)]
        return score
Entry = namedtuple('Entry', 'lower upper')
class Searcher:
    def __init__(self):
        self.tp_score = {}
        self.tp_move = {}
        self.history = set()
    def bound(self, pos, gamma, depth, root=True):
        depth = max(depth, 0)
        if pos.score <= -MATE_LOWER: return -MATE_UPPER
        if not root and pos in self.history: return 0
        entry = self.tp_score.get((pos, depth, root), Entry(-MATE_UPPER, MATE_UPPER))
        if entry.lower >= gamma and (not root or self.tp_move.get(pos) is not None):
            return entry.lower
        if entry.upper < gamma: return entry.upper
        def moves():
            if depth > 0 and not root and any(c in pos.board for c in 'RBNQ'):
                yield None, -self.bound(pos.nullmove(), 1-gamma, depth-3, root=False)
            if depth == 0: yield None, pos.score
            killer = self.tp_move.get(pos)
            if killer and (depth > 0 or pos.value(killer) >= QS_LIMIT):
                yield killer, -self.bound(pos.move(killer), 1-gamma, depth-1, root=False)
            for move in sorted(pos.gen_moves(), key=pos.value, reverse=True):
                if depth > 0 or pos.value(move) >= QS_LIMIT:
                    yield move, -self.bound(pos.move(move), 1-gamma, depth-1, root=False)
        best = -MATE_UPPER
        for move, score in moves():
            best = max(best, score)
            if best >= gamma:
                if len(self.tp_move) > TABLE_SIZE: self.tp_move.clear()
                self.tp_move[pos] = move
                break
        if best < gamma and best < 0 and depth > 0:
            is_dead = lambda pos: any(pos.value(m) >= MATE_LOWER for m in pos.gen_moves())
            if all(is_dead(pos.move(m)) for m in pos.gen_moves()):
                in_check = is_dead(pos.nullmove())
                best = -MATE_UPPER if in_check else 0
        if len(self.tp_score) > TABLE_SIZE: self.tp_score.clear()
        if best >= gamma: self.tp_score[pos, depth, root] = Entry(best, entry.upper)
        if best < gamma: self.tp_score[pos, depth, root] = Entry(entry.lower, best)
        return best
    def search(self, pos, history=()):
        self.history = set(history)
        self.tp_score.clear()
        for depth in range(1, 1000):
            lower, upper = -MATE_UPPER, MATE_UPPER
            while lower < upper - EVAL_ROUGHNESS:
                gamma = (lower+upper+1)//2
                score = self.bound(pos, gamma, depth)
                if score >= gamma: lower = score
                if score < gamma: upper = score
            self.bound(pos, lower, depth)
            yield depth, self.tp_move.get(pos), self.tp_score.get((pos, depth, True)).lower


Hier Erläuterungen und Quellen:

https://www.chessprogramming.org/Sunfish

https://github.com/thomasahle/sunfish

https://www.pypy.org/
- By Lothar Jung Date 2021-08-31 20:43 Edited 2021-08-31 20:53
Hier ist eine ausgezeichnete Beschreibung des Programms „Sunfish“ :

http://www.itu.dk/people/thdy/papers/sunfish.pdf
- By Lothar Jung Date 2021-09-01 17:30
Hier ein TechRadar Artikel über Python IDEs:

https://www.techradar.com/best/best-ide-for-python
- By Lothar Jung Date 2021-09-03 14:32 Edited 2021-09-03 14:35
Pychess  - a chess client for Linux/Windows:

https://github.com/pychess/pychess

Hier die Installation für Windowsversion:

https://github.com/pychess/pychess/releases/download/1.0.3/PyChess-1.0.3-mingw.msi
- - By Lothar Jung Date 2021-09-03 14:40
Hier alle Python-Projekte die mit Schach zu tun haben:

https://github.com/search?q=Python+chess
Parent - - By Benno Hartwig Date 2021-09-04 00:18
"2,328 repository results"
Parent - By Lothar Jung Date 2021-09-04 09:40
Das ist nur Gesamtzahl.
Die Projekte die überwiegend oder ganz Python verwenden, kann man rausfiltern.
- - By Lothar Jung Date 2021-09-03 16:34 Edited 2021-09-03 16:36
Hier eine Python Chess Library:

python-chess is a chess library for Python, with move generation, move validation, and support for common formats.

https://python-chess.readthedocs.io/en/latest/
Parent - By Lothar Jung Date 2021-09-12 15:53
Hier eine Veröffentlichung über die Entwicklung eines einfachen Schachprogramms in Python:

https://www.theseus.fi/bitstream/handle/10024/502571/Developing%20Chess%20Engine.pdf?sequence=2
- By Lothar Jung Date 2021-09-14 08:39
Hier ein Heise-Artikel zum Einsatz von Python im Bereich Data Science:

https://www.heise.de/hintergrund/Data-Science-stellt-sich-in-den-Dienst-der-Mathematik-6161436.html?seite=all
- By Lothar Jung Date 2021-09-19 18:05 Edited 2021-09-19 18:10 Upvotes 1
badgyal von Dietrich Kappe:

Simple pytorch net evaluator with Bad Gyal 8 and Mean Girl 8 net included.

https://github.com/dkappe/badgyal

Bad Gyal Data:

https://github.com/dkappe/leela-chess-weights/wiki/Bad-Gyal-Data
- - By Lothar Jung Date 2021-09-19 19:43
Hier eine neue Version von Dark Queen:

https://www.dropbox.com/s/75wn6x2h0xnmvpe/DarkQueen_V2.0?dl=0
Parent - - By Peter Martan Date 2021-09-19 19:56 Edited 2021-09-19 19:59
Was ist das?

Edit: Schon einen weiteren Hinweis gefunden:

http://www.talkchess.com/forum3/viewtopic.php?t=72319

Der Link ist allerdings von 2019
?
Parent - - By Lothar Jung Date 2021-09-19 20:20
Sorry, falscher Thread. Gehört zu Lc0. Nicht zu Python.

Dark Queen is a net that is trained on the available Lichess games database.

Lothar
Parent - - By Peter Martan Date 2021-09-19 20:41
Ok, hast du außer dem Download- Link noch einen zur Netzbeschreibung?
Ich glaube den Namen Dark Queen zu kennen, aber dass das schon 2 Jahre her ist, dass 2.0 rauskam, hast du auch gesehen, ja?
Parent - By Lothar Jung Date 2021-09-19 21:20 Edited 2021-09-19 21:23
Ja, DQ ist aus 2019.

Hier ein post auf Discord von D. Kappe zu DQ:

« Depends on the net. Bad Gyal was lichess plus sf10 policy and q. Maddex did start out with some ccrl, but Ender was self and adversarial play from the beginning using bender. With the exception of distilled and boost networks, none of them used leela’s data.
I’ve made 2.1M games of Bad Gyal data publicly available. I think it’s being used as a part of Dark Queen training. »

Lothar
Up Topic Hauptforen / Schachprogrammierung / Python Programmierung

Powered by mwForum 2.29.3 © 1999-2014 Markus Wichitill