-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
72 lines (65 loc) · 2.57 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from board import Board
from player import FactoryofPlayers
from game import Game
from sys import argv
from UndoRedo import Caretaker
class Santorini:
"""Santorini is the driver class for the game.
It is responsible for initializing the game, executing the game loop,
and terminating the game.
"""
def __init__(self, white_type, blue_type, undo_redo, display):
"""Initialize the game."""
self._board = Board()
self._players = []
self._players.append(FactoryofPlayers().initiate_player(self._board, "white", white_type))
self._players.append(FactoryofPlayers().initiate_player(self._board, "blue", blue_type))
self._state = Game(self._board, self._players)
self._undo_redo = undo_redo
self._display = True if display == "on" else False
self._caretaker = Caretaker(self._state)
def __call__(self):
while not self._state.game_state_end_check():
print(self._state.current_game_state(self._display))
if self._undo_redo == "on":
chooseMove = input("undo, redo, or next\n")
if chooseMove == "next":
self._state._cur_player.player_move(self._state, self._display)
self._caretaker.save(self._state)
elif chooseMove == "undo":
back_state = self._caretaker.undo()
if back_state != None:
self._state = back_state
self._state.set_current_turn(back_state.turn_counter)
elif chooseMove == "redo":
next_state = self._caretaker.redo()
if next_state is not None:
self._state = next_state
else:
self._state._cur_player.player_move(self._state, self._display)
print(self._state.current_game_state(self._display))
print(self._state.winner + " has won")
if __name__ == '__main__':
try:
white_type = str(argv[1])
except IndexError:
white_type = "human"
try:
blue_type = str(argv[2])
except IndexError:
blue_type = "human"
try:
undo_redo = str(argv[3])
except IndexError:
undo_redo = "off"
try:
display = str(argv[4])
except IndexError:
display = "off"
newGame = Santorini(white_type, blue_type, undo_redo, display)
newGame()
again = input("Play again?\n")
while again == "yes":
newGame = Santorini(white_type, blue_type, undo_redo, display)
newGame()
again = input("Play again?\n")