Created
February 18, 2023 14:36
-
-
Save horstjens/fea93d70b14a154474cc052b61301856 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
player1 = "Spieler1" | |
player2 = "Spieler2" | |
def display(): | |
for y, line in enumerate(board): | |
print(f"{line[0]}|{line[1]}|{line[2]}") | |
if y < 2: | |
print("-+-+-") | |
def is_valid(char): | |
if char.lower() == "quit": | |
return True | |
if len(char) != 1: | |
return False | |
if char not in "123456789": | |
return False | |
for line in board: | |
for number in line: | |
if char == number: | |
return True | |
return False | |
board =[["1","2","3"], | |
["4","5","6"], | |
["7","8","9"]] | |
turn_number = 1 | |
display() | |
while turn_number < 10: | |
if turn_number % 2 == 0: | |
player = player2 | |
char = "o" | |
else: | |
player = player1 | |
char = "x" | |
print(f"Runde {turn_number}:") | |
while True: | |
answer = input(f"Dein Spielzug {player}? (1-9) oder 'quit' >>>") | |
if is_valid(answer): | |
break | |
if answer == "quit": | |
break | |
# ---- answer is correct ----- | |
# ----- update board ---- | |
for y, line in enumerate(board): | |
for x, text in enumerate(line): | |
if text == answer: | |
board[y][x] = char | |
# ----- print board ---- | |
display() | |
# ------ | |
turn_number += 1 | |
print("Danke fürs Spielen") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment