|
|
@ -2,7 +2,7 @@ board = [[" ", " ", " "], [" ", " ", " "], [" ", " ", " "]]
|
|
|
|
player_marks = ["x", "y"]
|
|
|
|
player_marks = ["x", "y"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def print_board():
|
|
|
|
def print_board(): # Funkce vytiskne pole v momentálním stavu hry
|
|
|
|
print(f""" 1 2 3
|
|
|
|
print(f""" 1 2 3
|
|
|
|
1 |{board[0][0]}|{board[0][1]}|{board[0][2]}|
|
|
|
|
1 |{board[0][0]}|{board[0][1]}|{board[0][2]}|
|
|
|
|
2 |{board[1][0]}|{board[1][1]}|{board[1][2]}|
|
|
|
|
2 |{board[1][0]}|{board[1][1]}|{board[1][2]}|
|
|
|
@ -10,41 +10,40 @@ def print_board():
|
|
|
|
""")
|
|
|
|
""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def player(x_or_y):
|
|
|
|
def player(x_or_y): # Input hráče, ve stylu X_Y souřadnice, mělo by mít 3 charaktery a to čísla od 1 do 3
|
|
|
|
player_move = input("Zvol si radu a sloupec ")
|
|
|
|
player_move = input("Zvol si řadu a sloupec ")
|
|
|
|
while 3 != len(player_move):
|
|
|
|
while 3 != len(player_move): # Zda-li má hráč 3 charaktery
|
|
|
|
print("spatny pocet znaku")
|
|
|
|
print("špatný počet znaků")
|
|
|
|
player_move = input("Zvol si radu a sloupec ")
|
|
|
|
player_move = input("Zvol si řadu a sloupec ")
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
if board[int(player_move[0]) - 1][int(player_move[2]) - 1] == " ":
|
|
|
|
if board[int(player_move[0]) - 1][int(player_move[2]) - 1] == " ": # Funguje jen pokud je pole prázdné
|
|
|
|
board[int(player_move[0]) - 1][int(player_move[2]) - 1] = x_or_y
|
|
|
|
board[int(player_move[0]) - 1][int(player_move[2]) - 1] = x_or_y
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
print("Moznost nelze vybrat")
|
|
|
|
print("Možnost nelze vybrat")
|
|
|
|
player_move = input("Zvol si radu a sloupec ")
|
|
|
|
player_move = input("Zvol si řadu a sloupec ")
|
|
|
|
except:
|
|
|
|
except:
|
|
|
|
print("Moznost nelze vybrat")
|
|
|
|
print("Možnost nelze vybrat")
|
|
|
|
player_move = input("Zvol si radu a sloupec ")
|
|
|
|
player_move = input("Zvol si řadu a sloupec ")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def check_win(): # Kontrola, jestli některý z hráčů nevyhrál kolo
|
|
|
|
def check_win():
|
|
|
|
|
|
|
|
for i in range(3): # Kontrola sloupcu
|
|
|
|
for i in range(3): # Kontrola sloupcu
|
|
|
|
if board[i][0] in player_marks and board[i][1] in player_marks and board[i][2] in player_marks:
|
|
|
|
if board[i][0] in player_marks and board[i][1] in player_marks and board[i][2] in player_marks:
|
|
|
|
print(f"Vyhral hrac {board[i][0]}")
|
|
|
|
print(f"Vyhrál hráč {board[i][0]}")
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
for i in range(3): # Kontrola rad
|
|
|
|
for i in range(3): # Kontrola rad
|
|
|
|
if board[0][i] in player_marks and board[1][i] in player_marks and board[2][i] in player_marks:
|
|
|
|
if board[0][i] in player_marks and board[1][i] in player_marks and board[2][i] in player_marks:
|
|
|
|
print(f"Vyhral hrac {board[0][i]}")
|
|
|
|
print(f"Vyhrál hráč {board[0][i]}")
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
if board[0][0] in player_marks and board[1][1] in player_marks and board[2][
|
|
|
|
if board[0][0] in player_marks and board[1][1] in player_marks and board[2][
|
|
|
|
2] in player_marks: # Kontrola diagonaly
|
|
|
|
2] in player_marks: # Kontrola diagonaly
|
|
|
|
print(f"Vyhral hrac {board[0][i]}") # z prava do leva
|
|
|
|
print(f"Vyhrál hráč {board[0][i]}") # z prava do leva
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
elif board[0][2] in player_marks and board[1][1] in player_marks and board[2][
|
|
|
|
elif board[0][2] in player_marks and board[1][1] in player_marks and board[2][
|
|
|
|
0] in player_marks: # Kontrola diagonaly
|
|
|
|
0] in player_marks: # Kontrola diagonaly
|
|
|
|
print(f"Vyhral hrac {board[0][i]}") # z leva do prava
|
|
|
|
print(f"Vyhrál hráč {board[0][i]}") # z leva do prava
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
x_or_y = "x"
|
|
|
|
x_or_y = "x"
|
|
|
@ -52,15 +51,18 @@ x_or_y = "x"
|
|
|
|
rounds = 0
|
|
|
|
rounds = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main(rounds):
|
|
|
|
def main(rounds): # Funkce, která skládá celý kód dohromady
|
|
|
|
while rounds < 9:
|
|
|
|
print_board()
|
|
|
|
if rounds % 2 == 0:
|
|
|
|
while rounds < 9: # Pokud bude mít hra víc jak 9 kol, vše bude zaplněné, remíza
|
|
|
|
|
|
|
|
if rounds % 2 == 0: # Změní se buď na "x" nebo "o" podle momentálního kola
|
|
|
|
x_or_y = "x"
|
|
|
|
x_or_y = "x"
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
x_or_y = "o"
|
|
|
|
x_or_y = "o"
|
|
|
|
print_board()
|
|
|
|
|
|
|
|
player(x_or_y)
|
|
|
|
player(x_or_y)
|
|
|
|
|
|
|
|
print_board()
|
|
|
|
rounds += 1
|
|
|
|
rounds += 1
|
|
|
|
if not check_win():
|
|
|
|
if check_win():
|
|
|
|
break
|
|
|
|
break
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
print("Je to remíza")
|
|
|
|
main(rounds)
|
|
|
|
main(rounds)
|