-
Notifications
You must be signed in to change notification settings - Fork 1
/
tic_tac_toe game
91 lines (87 loc) · 2.87 KB
/
tic_tac_toe game
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
board={
'T1': ' ','T2':' ','T3':' ',
'M1': ' ','M2':' ','M3':' ',
'D1': ' ','D2':' ','D3':' ',
}
player = 1
total_move = 0
end_check = 0
def check():
if board['T1']== 'X' and board['T2'] == 'X' and board['T3'] == 'X':
print('player one won!!!')
return 1
if board['M1']== 'X' and board['M2'] == 'X' and board['M3'] == 'X':
print('player one won!!!')
return 1
if board['D1']=='X' and board['D2'] == 'X' and board['D3'] == 'X':
print('player one won!!!')
return 1
if board['T1']== 'X' and board['M2']== 'X' and board['D3']=='X':
print('player one won!!!')
return 1
if board['T1']== 'X' and board['M1']=='X' and board['D1']=='X':
print('player one won!!!')
return 1
if board['T2']=='X' and board['M2']=='X' and board['D2']=='X':
print('player one won!!!')
return 1
if board['T3']=='X' and board['M3']=='X' and board['D3']== 'X':
print('player one won!!!')
return 1
if board['T1']== 'O'and board['T2'] == 'O'and board['T3'] == 'O':
print('player one won!!!')
return 1
if board['M1']== 'O'and board['M2'] == 'O'and board['M3'] == 'O':
print('player one won!!!')
return 1
if board['D1']== 'O'and board['D2'] == 'O'and board['D3'] == 'O':
print('player one won!!!')
return 1
if board['T1']== 'O'and board['M'] == 'O'and board['D3']=='O':
print('player one won!!!')
return 1
if board['T1']== 'O'and board['M1']=='O'and board['D1']=='O':
print('player one won!!!')
return 1
if board['T2']=='O'and board['M2']=='O'and board['D2']=='O':
print('player one won!!!')
return 1
if board['T3']=='O'and board['M3']=='O'and board['D3']== 'O':
print('player one won!!!')
return 1
print('T1|T2|T3')
print('- +- +-')
print('M1|M2|M3')
print('- +- +-')
print('D1|D2|D3')
print('- +- +-')
while True:
print(board['T1']+'|'+board['T2']+'|'+board['T3'])
print('-+-+-')
print(board['M1']+'|'+board['M2']+'|'+board['M3'])
print('-+-+-')
print(board['D1']+'|'+board['D2']+'|'+board['D3'])
end_check = check()
if total_move ==9 or end_check ==1:
break
while True:
if player ==1:
p1_input = input('player one')
if p1_input.upper() in board and board[p1_input.upper()] == '':
board[p1_input.upper()]='X'
player = 2
break
else:
print('Please try again :(')
continue
else:
p2input = input('player two')
if p2input.upper() in board and board[p2input.upper()] == '':
board[p2input.upper()]='O'
player = 1
break
else:
print('Please try again :(')
continue
total_moves +=1
print()