iamjarret / pystockfish

Implements an easy-to-use Engine class to integrates the Stockfish chess engine with Python
GNU General Public License v3.0
30 stars 13 forks source link

Match winner #12

Closed pafnucy closed 7 years ago

pafnucy commented 7 years ago

There is an issue with determining winner of match, iteration up to 200 moves makes winner 'disappear', as game state gets corrupted during blank moves.

from pystockfish import *
import re
score_regex = "score \w+ -?\d+"

e1 = Engine(depth=3)
e2 = Engine(depth=12)

m = Match(engines = {"e1": e1, "e2": e2})

info = []
inc = 0
while(m.move()): 
    _info = e1.bestmove()["info"]
    res = re.search(pattern = score_regex, string = _info)
    info.append("move " + str(inc) + "  " + _info[res.start():res.end()])
    inc = inc + 1

for line in info:
    print(line)

part of output:

move 46 score cp -616 move 47 score cp -656 move 48 score cp -656 move 49 score cp -751 move 50 score cp -751 move 51 score mate -3 move 52 score mate -3 move 53 score mate -2 move 54 score mate -2 move 55 score mate -1 move 56 score mate -1 move 57 score mate 0 move 58 score mate 0 ...

I'll attempt to fix it sometime soon and issue a pull request