-
Notifications
You must be signed in to change notification settings - Fork 0
/
tic-tac-toe_dabana.py
59 lines (47 loc) · 1.57 KB
/
tic-tac-toe_dabana.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
# -*- coding: utf-8 -*-
# DEFINE GLOBAL VARIABLES
board = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
endofgame = 0
players = ['A', 'B']
cntr = 0
# DEFINE FUNCTIONS
# Print out the board
def print_board():
for i1, i2, i3 in board:
print '%s|%s|%s' % (i1, i2, i3)
# Check for the end of game conditions and outputs winner
def checkendofgame():
for i1, i2, i3 in board:
endofgame == 1
# Main function
while endofgame == 0:
coords = [1, 1]
input_status = False
while not input_status:
print 'Hey player %s! Where do you want to place your token? (for exemple: left, center)' % (players[cntr % 2])
posish = raw_input()
if len(posish.split()) == 2:
[i1, i2] = posish.split()
# Lets assume the player entered correct stings
input_status = True
player = 'B'
cntr += 1
elif len(posish.split()) <> 2:
print 'Hey player %s! Are you stupid or what?' % (players[cntr % 2])
continue
if i1 == 'left' or i2 == 'left':
coords[0] = 0
if i1 == 'right' or i2 == 'right':
coords[0] = 2
if i1 == 'up' or i2 == 'up':
coords[1] = 0
if i1 == 'down' or i2 == 'down':
coords[1] = 2
# Update and print board
if board[coords[1]][coords[0]] == 0:
board[coords[1]][coords[0]] = players[(cntr - 1) % 2]
print_board()
else:
cntr -= 1
print 'Hey player %s! Are you stupid or what?' % (players[cntr % 2])
input_status = False