added main, should work
parent
b94b69ac2b
commit
88ec7439bb
@ -1,41 +1,66 @@
|
|||||||
board = [[" ", " ", " "],[" ", " ", " "],[" ", " ", " "]]
|
board = [[" ", " ", " "], [" ", " ", " "], [" ", " ", " "]]
|
||||||
player_marks = ["x", "y"]
|
player_marks = ["x", "y"]
|
||||||
|
|
||||||
def print_board(board):
|
|
||||||
print(f""" 1 2 3
|
def print_board():
|
||||||
|
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]}|
|
||||||
3 |{board[2][0]}|{board[2][1]}|{board[2][2]}|
|
3 |{board[2][0]}|{board[2][1]}|{board[2][2]}|
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
|
||||||
def player(x_or_y):
|
def player(x_or_y):
|
||||||
player_move = input("Zvol si radu a sloupec ")
|
player_move = input("Zvol si radu a sloupec ")
|
||||||
while length(player_move) != 3:
|
while 3 != len(player_move):
|
||||||
print("spatny pocet znaku")
|
print("spatny pocet znaku")
|
||||||
else:
|
player_move = input("Zvol si radu a sloupec ")
|
||||||
try:
|
else:
|
||||||
if board[int(player_move[0]) - 1][int(player_move[2]) - 1] == " ":
|
try:
|
||||||
board[int(player_move[0]) - 1][int(player_move[2]) - 1] = x_or_y
|
if board[int(player_move[0]) - 1][int(player_move[2]) - 1] == " ":
|
||||||
else:
|
board[int(player_move[0]) - 1][int(player_move[2]) - 1] = x_or_y
|
||||||
print("Moznost nelze vybrat")
|
else:
|
||||||
player_move = input("Zvol si radu a sloupec ")
|
print("Moznost nelze vybrat")
|
||||||
except:
|
player_move = input("Zvol si radu a sloupec ")
|
||||||
print("Moznost nelze vybrat")
|
except:
|
||||||
player_move = input("Zvol si radu a sloupec ")
|
print("Moznost nelze vybrat")
|
||||||
|
player_move = input("Zvol si radu a sloupec ")
|
||||||
|
|
||||||
|
|
||||||
def check_win():
|
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"Vyhral hrac {board[i][0]}")
|
||||||
return False
|
return False
|
||||||
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"Vyhral hrac {board[0][i]}")
|
||||||
return False
|
return False
|
||||||
if
|
if board[0][0] in player_marks and board[1][1] in player_marks and board[2][
|
||||||
|
2] in player_marks: # Kontrola diagonaly
|
||||||
|
print(f"Vyhral hrac {board[0][i]}") # z prava do leva
|
||||||
|
return False
|
||||||
|
elif board[0][2] in player_marks and board[1][1] in player_marks and board[2][
|
||||||
|
0] in player_marks: # Kontrola diagonaly
|
||||||
|
print(f"Vyhral hrac {board[0][i]}") # z leva do prava
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
x_or_y = "x"
|
x_or_y = "x"
|
||||||
player(x_or_y)
|
|
||||||
print_board(board)
|
rounds = 0
|
||||||
check_win()
|
|
||||||
|
|
||||||
|
def main(rounds):
|
||||||
|
while rounds < 9:
|
||||||
|
if rounds % 2 == 0:
|
||||||
|
x_or_y = "x"
|
||||||
|
else:
|
||||||
|
x_or_y = "o"
|
||||||
|
print_board()
|
||||||
|
player(x_or_y)
|
||||||
|
rounds += 1
|
||||||
|
if not check_win():
|
||||||
|
break
|
||||||
|
main(rounds)
|
Loading…
Reference in New Issue