problema con 3 en raya en python3
Publicado por BL4D3 (1 intervención) el 01/07/2022 00:16:23
buenos dias hoy estoy un poco frustrado y me vendria bien su ayuda si me periten escribire mi codigo el cual me dice que gano alguien sin ser eso verdad y no lo comprendo gracias
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
tablon1 = [' ', ' ', ' ']
tablon2 = [' ', ' ', ' ']
tablon3 = [' ', ' ', ' ']
name = input('1º player name: ')
name2 = input('2º player name: ')
print(4 * ' ' + '1' + 4 * ' ' + '2' + 4 * ' ' + '3')
print('1', tablon1)
print('2', tablon2)
print('3', tablon3)
print(20 * '-')
while True:
# PLAYER 1
Y = int(input(f'{name} escoga la coordenada vertical: '))
X = int(input(f'{name} escoga la coordenada horizontal: ')) - 1
if Y == 1:
tablon1.pop(X)
tablon1.insert(X, 'X')
if Y == 2:
tablon2.pop(X)
tablon2.insert(X, 'X')
if Y == 3:
tablon3.pop(X)
tablon3.insert(X, 'X')
print(4 * ' ' + '1' + 4 * ' ' + '2' + 4 * ' ' + '3')
print('1', tablon1)
print('2', tablon2)
print('3', tablon3)
print(20 * '-')
#________________________________________________#
# PLAYER 2
Y = int(input(f'{name2} escoga la coordenada vertical: '))
X = int(input(f'{name2} escoga la coordenada horizontal: ')) - 1
if Y == 1:
tablon1.pop(X)
tablon1.insert(X, 'O')
if Y == 2:
tablon2.pop(X)
tablon2.insert(X, 'O')
if Y == 3:
tablon3.pop(X)
tablon3.insert(X, 'O')
print(4 * ' ' + '1' + 4 * ' ' + '2' + 4 * ' ' + '3')
print('1', tablon1)
print('2', tablon2)
print('3', tablon3)
print(20 * '-')
# formas de ganar:
# 1º
if tablon1[0] and tablon1[1] and tablon1[2] == 'X':
print(f'{name} ¡¡Ganaste!!')
exit()
elif tablon1[0] and tablon1[1] and tablon1[2] == 'O':
print(f'{name2} ¡¡Ganaste!!')
exit()
if tablon2[0] and tablon2[1] and tablon2[2] == 'X':
print(f'{name} ¡¡Ganaste!!')
exit()
elif tablon2[0] and tablon2[1] and tablon2[2] == 'O':
print(f'{name2} ¡¡Ganaste!!')
exit()
if tablon3[0] and tablon3[1] and tablon3[2] == 'X':
print(f'{name} ¡¡Ganaste!!')
exit()
elif tablon3[0] and tablon3[1] and tablon3[2] == 'O':
print(f'{name2} ¡¡Ganaste!!')
exit()
#2º
if tablon1[0] and tablon2[0] and tablon3[0] == 'X':
print(f'{name} ¡¡Ganaste!!')
exit()
elif tablon1[0] and tablon2[0] and tablon3[0] == 'O':
print(f'{name2} ¡¡Ganaste!!')
exit()
if tablon1[1] and tablon2[1] and tablon3[1] == 'X':
print(f'{name} ¡¡Ganaste!!')
exit()
elif tablon1[1] and tablon2[1] and tablon3[1] == 'O':
print(f'{name2} ¡¡Ganaste!!')
exit()
if tablon1[2] and tablon2[2] and tablon3[2] == 'X':
print(f'{name} ¡¡Ganaste!!')
exit()
elif tablon1[2] and tablon2[2] and tablon3[2] == 'O':
print(f'{name2} ¡¡Ganaste!!')
exit()
#3º
if tablon1[0] and tablon2[1] and tablon3[2] == 'X':
print(f'{name} ¡¡Ganaste!!')
exit()
elif tablon1[0] and tablon2[1] and tablon3[2] == 'O':
print(f'{name2} ¡¡Ganaste!!')
exit()
if tablon1[2] and tablon2[1] and tablon3[0] == 'X':
print(f'{name} ¡¡Ganaste!!')
exit()
elif tablon1[2] and tablon2[1] and tablon3[0] == 'O':
print(f'{name2} ¡¡Ganaste!!')
exit()
Valora esta pregunta


0