File size: 1,176 Bytes
ec04e24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8454f02
 
 
 
ec04e24
 
8454f02
 
 
ec04e24
 
 
 
8454f02
ec04e24
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from othello import Game, AlphaBetaBot
import tqdm


def run_match(bot1, bot2):
    game = Game.default()
    while not game.state.ended:
        bot = bot1 if game.state.player == "B" else bot2
        pos = bot.find_move(game)
        if pos >= 0:
            game.make_move(pos)
        else:
            game.pass_move()
    w, b = game.state.white_score, game.state.black_score
    return 1 if b > w else 2 if w > b else 0


def run_matches(bot1, bot2, n):
    cnts = [0, 0, 0]
    for _ in tqdm.tqdm(range(n)):
        result = run_match(bot1, bot2)
        cnts[result] += 1
    return cnts


def _str(bot):
    return f"AlphaBetaBot({bot.depth}, {bot.exhaustive_depth})"


if __name__ == "__main__":
    for i in range(2, 10):
        bot1 = AlphaBetaBot(i, 14)
        bot2 = AlphaBetaBot(i + 1, 14)
        print(f"{_str(bot1)} vs {_str(bot2)})")
        draw, win, lost = run_matches(bot1, bot2, 10)
        print(f"Win: {win} | Draw: {draw} | Lost: {lost}")
        print("----")

        print(f"{_str(bot2)} vs {_str(bot1)})")
        draw, win, lost = run_matches(bot2, bot1, 10)
        print(f"Win: {win} | Draw: {draw} | Lost: {lost}")
        print("----")