forked from kanabe/tictactoe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
46 lines (40 loc) · 1.09 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
from print_instruction import print_instruction
from board import print_board
from input import get_input
from checkwin import check_win
from quitgame import quit_game
def main():
print_instruction()
board = []
for i in range(9):
board.append(-1)
win = False
move = 0
while not win:
print_board(board)
print "Turn number" + str(move+1)
if move % 2 == 0:
#this is the user
turn = 'X'
user = get_input(turn)
while board[user] != -1:
print "Invalid move! Cell already taken. Please try again.\n"
user = get_input(turn)
board[user] = 1
else:
#this will be the computer
turn = 'O'
comp=generate_o(board)#computer behaviour define
board[comp]=0
move += 1
if move > 4:
winner = check_win(board)
if winner != -1:
out = "The winner is"
out += "X" if winner == 1 else "O"
out += "=D"
quit_game(board,out)
elif move >= 9:
quit_game(board, "No winner :(")
if __name__== "__main__":
main()