Esempio n. 1
0
def findbest(f, times):
    pos = tools.parseFEN(tools.FEN_INITIAL)
    searcher = sunfish.Searcher()

    print('Printing best move after seconds', times)
    print('-'*60)
    totalpoints = 0
    totaltests = 0
    for line in f:
        fen, opts = tools.parseEPD(line, opt_dict=True)
        if type(opts) != dict or ('am' not in opts and 'bm' not in opts):
            print("Line didn't have am/bm in opts", line, opts)
            continue
        pos = tools.parseFEN(fen)
        # am -> avoid move; bm -> best move
        am = tools.parseSAN(pos,opts['am']) if 'am' in opts else None
        bm = tools.parseSAN(pos,opts['bm']) if 'bm' in opts else None
        print('Looking for am/bm', opts.get('am'), opts.get('bm'))
        points = 0
        print(opts.get('id','unnamed'), end=' ', flush=True)
        for t in times:
            move, _ = searcher.search(pos, t)
            mark = tools.renderSAN(pos,move)
            if am and move != am or bm and move == bm:
                mark += '(1)'
                points += 1
            else:
                mark += '(0)'
            print(mark, end=' ', flush=True)
            totaltests += 1
        print(points)
        totalpoints += points
    print('-'*60)
    print('Total Points: %d/%d', totalpoints, totaltests)
Esempio n. 2
0
def findbest(f, times):
    pos = tools.parseFEN(tools.FEN_INITIAL)
    searcher = sunfish.Searcher()

    print('Printing best move after seconds', times)
    print('-' * 60)
    totalpoints = 0
    totaltests = 0
    for line in f:
        fen, opts = tools.parseEPD(line, opt_dict=True)
        if type(opts) != dict or ('am' not in opts and 'bm' not in opts):
            print("Line didn't have am/bm in opts", line, opts)
            continue
        pos = tools.parseFEN(fen)
        # am -> avoid move; bm -> best move
        am = tools.parseSAN(pos, opts['am']) if 'am' in opts else None
        bm = tools.parseSAN(pos, opts['bm']) if 'bm' in opts else None
        print('Looking for am/bm', opts.get('am'), opts.get('bm'))
        points = 0
        print(opts.get('id', 'unnamed'), end=' ', flush=True)
        for t in times:
            move, _, _ = tools.search(searcher, pos, t)
            mark = tools.renderSAN(pos, move)
            if am and move != am or bm and move == bm:
                mark += '(1)'
                points += 1
            else:
                mark += '(0)'
            print(mark, end=' ', flush=True)
            totaltests += 1
        print(points)
        totalpoints += points
    print('-' * 60)
    print('Total Points: %d/%d', totalpoints, totaltests)
Esempio n. 3
0
 def setUp(self):
     # We don't bother about closing files, since they are just part of the test
     warnings.simplefilter("ignore", ResourceWarning)
     self.perft_file = os.path.join(os.path.dirname(__file__),
                                    'tests/queen.fen')
     test_trees = [
         tools.expand_position(tools.parseFEN(tools.parseEPD(line)[0]))
         for line in open(self.perft_file)
     ]
     self.positions = list(
         itertools.chain(
             *[tools.flatten_tree(tree, depth=2) for tree in test_trees]))
Esempio n. 4
0
 def setUp(self):
     # We don't bother about closing files, since they are just part of the test
     warnings.simplefilter("ignore", ResourceWarning)
     self.perft_file = os.path.join(os.path.dirname(__file__), 'tests/queen.fen')
     test_trees = [tools.expand_position(tools.parseFEN(tools.parseEPD(line)[0])) for line in open(self.perft_file)]
     self.positions = list(itertools.chain(*[tools.flatten_tree(tree, depth=2) for tree in test_trees]))