File size: 1,865 Bytes
7d23b62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
44
45
46
47
48
49
50
51
52
53
54
55
import os
import sys

sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from .board import Board
from .minmax import vct, cache_hits, minmax
from .eval import FIVE, FOUR, performance


class Game():
    def __init__(self, firstRole=1):
        self.board = Board(8, firstRole)
        self.steps = []
        self.step = 0
        self.enableVCT = True  # 是否开启算杀, 算杀会在某些leaf节点加深搜索, 但是不一定会增加搜索时间

    def human_input(self):
        x, y = map(int, input('Your move: ').split())
        return x, y

    def start_play(self, human_first=False):
        if not human_first:
            while not self.board.isGameOver():
                print(self.board.display())
                if self.step % 2 == 1:
                    x, y = self.human_input()
                    while not self.board.put(x, y):
                        x, y = self.human_input()
                else:
                    score = minmax(self.board, 1, 4, enableVCT=self.enableVCT)
                    print(score)
                    x, y = score[1]
                    print("move at", x, y)
                    self.board.put(x, y)
                self.step += 1
        else:
            while not self.board.isGameOver():
                print(self.board.display())
                if self.step % 2 == 0:
                    x, y = self.human_input()
                    while not self.board.put(x, y):
                        x, y = self.human_input()
                else:
                    score = minmax(self.board, -1, 4, enableVCT=self.enableVCT)
                    print(score)
                    x, y = score[1]
                    self.board.put(x, y)
                self.step += 1
        print(self.board.display())


if __name__ == '__main__':
    game = Game()
    game.start_play(True)