-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
47 lines (39 loc) · 1.63 KB
/
main.py
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
from board import Board
from agents.minimax_ai import MinimaxAI
from agents.human import Human
from displays import BlankDisplay, GUIDisplay
from base import Color
class Game:
def __init__(self, p1, p2, board, display, max_turns):
self.p1, self.p2 = p1, p2
self.board = board
self.display = display
self.display.set_board(self.board.board)
self.display.render()
self.over = False
self.max_turns = max_turns
def run(self):
for _ in range(self.max_turns):
if self.over:
break
player = self.p1 if self.board.turn == Color.WHITE else self.p2
move = player.get_move(self.board)
if move is not None:
self.board = self.board.make_move(move)
self.display.set_board(self.board.board)
self.display.render()
self.display.terminate()
def start_game(player_1_type, player_2_type, no_gui, max_turn=300):
if player_1_type == 'Human' and no_gui:
raise ValueError("Cannot play without GUI if player 1 is Human")
if player_2_type == 'Human' and no_gui:
raise ValueError("Cannot play without GUI if player 2 is Human")
board = Board()
display = BlankDisplay() if no_gui else GUIDisplay(board.board)
player_1 = Human(display) if player_1_type == 'Human' else MinimaxAI(5)
player_2 = Human(display) if player_2_type == 'Human' else MinimaxAI(3)
return Game(player_1, player_2, board, display, max_turn)
if __name__ == '__main__':
# game = start_game('Human', 'AI', False, 400)
game = start_game('AI', 'AI', False, 150)
game.run()