-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·47 lines (39 loc) · 943 Bytes
/
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import player
import util
import human
player1 = player.Player(1)
player2 = human.Player(2)
turn = 1
game_state = [0, 0, 0, 0, 0, 0, 0, 0, 0 ]
while True:
# show game state
print(game_state[0], game_state[1], game_state[2])
print(game_state[3], game_state[4], game_state[5])
print(game_state[6], game_state[7], game_state[8])
print()
# check win
win = util.check_win(game_state)
if win:
print('Player', win, 'wins!')
break
pos = -1
# player's turn
if turn == 1:
pos = player1.take_turn()
if pos == -1:
break
player2.update_state(pos)
game_state[pos] = 1
turn = 2;
pass
# opponent's turn
else:
pos = player2.take_turn()
if pos == -1:
break
game_state[pos] = 2
player1.update_state(pos)
turn = 1;
pass