You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
2.6 KiB
Python

5 years ago
pisk = [[" ", " ", " "],
[" ", " ", " "],
[" ", " ", " "]]
player = 'x'
5 years ago
def print_board(pisk): # beres board jako argument - super
5 years ago
5 years ago
for x in pisk: # sice se ti tam dela jedna cara navic ale je to elegantni
# takze super
5 years ago
print(f'{x[0]} | {x[1]} | {x[2]}')
print('--+---+--')
def check():
5 years ago
for i in range(3): # pouzivas cykly, taky fajn protoze si zjednodussujes praci
5 years ago
if pisk[i][0] == pisk[i][1] and pisk[i][1] == pisk[i][2] and pisk[i][1] != ' ':
print('Player ' + player + ' is the winner!!!')
return True
for i in range(3):
if pisk[0][i] == pisk[1][i] and pisk[1][i] == pisk[2][i] and pisk[1][i] != ' ':
print('Player ' + player + ' is the winner!!!')
return True
5 years ago
for i in range(1): # range(1).. hmm, tady to nesedi, vysral bych se na loop
# kdybys delal cykly cyklu a mel misto `1` nejakou promennou pak pohoda
5 years ago
if pisk[i][i] == pisk[i + 1][i + 1] and pisk[i + 1][i + 1] == pisk[i + 2][i + 2] and pisk[i + 1][i + 1] != ' ':
print('Player ' + player + ' is the winner!!!')
return True
5 years ago
for i in range(1):
5 years ago
if pisk[i][i + 2] == pisk[i + 1][i + 1] and pisk[i + 1][i + 1] == pisk[i + 2][i] and pisk[i + 1][i + 1] != ' ':
print('Player ' + player + ' is the winner!!!')
return True
5 years ago
if pisk[0][0] != ' ' and pisk[0][1] != ' ' and pisk[0][2] != ' ' and pisk[1][0] != ' ' and pisk[1][1] != ' ' and pisk[1][2] != ' ' and pisk[2][0] != ' ' and pisk[2][1] != ' ' and pisk[2][2] != ' ': # husty, ale slo by to vymyslet lip
print('Draw') # printy - chytrejsi je vracet to co se ma vytisknout jako string
# lepsi zvyk protoze printy jsou vedlejsi efekty
5 years ago
return True
return False
while True:
print_board(pisk)
5 years ago
print('Now plays player ' + player) # "now plays player" lol
5 years ago
print('Enter coordinates: ')
r = input('Row (0,1,2):')
c = input('Column(0,1,2): ')
if r == '0' or r == '1' or r == '2' and c == '0' or c == '1' or c == '2':
if pisk[int(r)][int(c)] == ' ':
pisk[int(r)][int(c)] = player
5 years ago
if check(): # chezky ze sis uvedomil ze `check` vraci bool
5 years ago
break
5 years ago
if player == 'x': # jde udelat chytreji, ale to jeste neumite
5 years ago
player = 'o'
5 years ago
elif player == 'o': # zbytecnej elif, staci else
5 years ago
player = 'x'
else:
5 years ago
print('Kill yourself! That position is already taken!') # lol nice
5 years ago
else:
print('Wrong input you idiot!')
print('End of the game')
5 years ago
# jinak vsechno funguje - super