예제 #1
0
파일: test.py 프로젝트: mekhami/sunfish
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)
예제 #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)
예제 #3
0
파일: test.py 프로젝트: mekhami/sunfish
 def test_san(self):
     pgn_file = os.path.join(os.path.dirname(__file__), 'tests/pgns.pgn')
     for line in open(pgn_file):
         msans = [msan for i, msan in enumerate(line.split()[:-1]) if i%3]
         pos = tools.parseFEN(tools.FEN_INITIAL)
         for i, msan in enumerate(msans):
             move = tools.parseSAN(pos, msan)
             if re.search('=[BNR]', msan):
                 # Sunfish doesn't support underpromotion
                 break
             msan_back = tools.renderSAN(pos, move)
             self.assertEqual(msan_back, msan,
                              "Sunfish didn't correctly reproduce the SAN move")
             pos = pos.move(move)
예제 #4
0
 def test_san(self):
     pgn_file = os.path.join(os.path.dirname(__file__), 'tests/pgns.pgn')
     for line in open(pgn_file):
         msans = [msan for i, msan in enumerate(line.split()[:-1]) if i % 3]
         pos = tools.parseFEN(tools.FEN_INITIAL)
         for i, msan in enumerate(msans):
             if re.search('=[BNR]', msan):
                 # Sunfish doesn't support underpromotion
                 break
             move = tools.parseSAN(pos, msan)
             msan_back = tools.renderSAN(pos, move)
             self.assertEqual(
                 msan_back, msan,
                 "Sunfish didn't correctly reproduce the SAN move")
             pos = pos.move(move)