New functions and fixes
__author__ = 'Zeirison'
import sys
enemy = int(input("Please choose the opponent \n (1 - Human, 2 - Computer):"))
field = ["_", "_", "_", "_", "_", "_", "_", "_", "_"]
def section_check(a):
return field[a - 1] == "_"
def win_check(a):
for i in range(0, 7, 3):
if field[i] == a and field[i + 1] == a and field[i + 2] == a:
return 1
for i in range(0, 3, 1):
if field[i] == a and field[i + 3] == a and field[i + 6] == a:
return 1
if field[0] == a and field[4] == a and field[8] == a:
return 1
if field[2] == a and field[4] == a and field[6] == a:
return 1
return 0
def status_check(a, b=""):
return {
0: "Game proceeds.",
1: "The player '" + b + "' won!",
2: "The " + b + " won!",
3: "Draw!"
}.get(a)
def game():
global status
hod = 0
opp = "Human"
status = status_check(0)
field.append(" --> Status: ")
field.append(status)
field.append(" --> Opponent: %s" % opp)
for i in range(9):
if hod == 0:
zn = "X"
hod = 1
else:
zn = "0"
hod = 0
check = False
while not check:
num = int(input("To put " + zn + " in a section: "))
check = section_check(num)
if not check:
print("This section is already occupied!")
field[num - 1] = zn
print(zn)
if i == 8:
status[10] = status_check(3, zn)
else:
field[10] = status_check(win_check(zn), zn)
edit = "|{0}|{1}|{2}|{9}{10}" \
"\n|{3}|{4}|{5}|{11}" \
"\n|{6}|{7}|{8}|".format(*field)
print(edit)
if win_check(zn) == 1:
break
game()