TIC-TAC-TOE
ravan's dream is to win the tic-tac-toe champions to accomplish this,the practices alone at home to learn the strategies in the game your task is to identify the cell where ravan should place his 3rd piece so that be wins the game Assume that each cell in the tic-tac-toe board is marked with number as shown in the table below
tic tac toe
0 1 2
3 4 5
6 7 8
input:
the 1st line of input contains two space-separated integers represetation the cells where ravan has placed his 1st two piece
i/P:
0 1
o/P: 2
i/p: 0 3
o/p:6
while True:
s = input('Please, input two cells (numbers from 0 to 8) => ').strip()
if s.find(' ') != -1:
s = s.split()
if len(s) == 2 and len(s[0]) == 1 and len(s[1]) == 1 and s[0].isdigit() == True and s[1].isdigit() == True:
break
else:
print('Please, input two numbers from 0 - 8 inclusive')
else:
print('Please, input two numbers from 0 - 8 inclusive')
first, second = int(s[0]), int(s[1])
if second - first == 1 and second != 2 and second != 5 and second != 8:
print(second + 1)
elif second - first == 1 and (second == 2 or second == 5 or second == 8):
print(first - 1)
elif second - first == 3 and second != 6 and second != 7 and second != 8:
print(second + 3)
elif second - first == 3 and (second == 6 or second == 7 or second == 8):
print(first - 3)
elif second - first == 2:
print(second - 1)
elif second - first == 6:
print(second - 3)
Comments
Leave a comment