Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- os.system("cls")
- board = [" ", " ", " ", " ", " ", " "," ", " ", " ", " "]
- space1 = " " #20 merkkiä
- space2 = " " #10 merkkiä
- space3 = " " #3 merkkiä
- def display_game(board):
- print("Tässä tilanne" + space2 + "Tässä ohje valintaan")
- print(space3 + board[7] + "|" + board[8] + "|" + board[9] + space1 + "7|8|9")
- print(space3 + board[4] + "|" + board[5] + "|" + board[6] + space1 + "4|5|6")
- print(space3 + board[1] + "|" + board[2] + "|" + board[3] + space1 + "1|2|3")
- #check_winner()
- def sijainnin_valinta(board):
- choice = "Wrong"
- while choice not in ["1", "2", "3", "4", "5", "6", "7", "8", "9"]:
- choice = input("Valitse sijainti (1,2,3,4,5,6,7,8,9): ")
- if choice not in ["1", "2", "3", "4", "5", "6", "7", "8", "9"]:
- print("Väärä valinta!")
- elif board[int(choice)] == "X" or board[int(choice)] == "O":
- choice = "Wrong"
- print("Varattu ruutu!")
- return int(choice)
- def valinnan_muutos(board, sijainti, phase):
- if phase%2 == 0:
- board[sijainti] = "O"
- else:
- board[sijainti] = "X"
- return board
- def gameon_choice():
- choice = "Wrong"
- while choice not in ["K", "E"]:
- choice = input("Haluatko jatkaa pelaamista K/E): ")
- if choice not in ["K", "E"]:
- print("Väärä valinta!")
- if choice == "K":
- return True
- else:
- return False
- def pelimoottori(board):
- game_on = True #peli jatkuu niin kauan kuin tämä on True
- game_won = " "
- phase = 1 #pariton tarkoittaa pelaajan 1 vuoroa, parillinen pelaajan 2 vuoroa
- while game_on: #peli-silmukka, joka jatkuu kunnes game_on saa arvon False
- os.system("cls")
- display_game(board)
- sijainti = sijainnin_valinta(board)
- board = valinnan_muutos(board, sijainti, phase)
- phase += 1
- os.system("cls")
- display_game(board)
- game_won = check_winner()
- if game_won != " ":
- win(game_won)
- game_on = False
- if phase == 10:
- print("tasuri!")
- game_on = gameon_choice()
- if game_on == True:
- board = nollaa_board()
- else:
- return
- def check_winner():
- winner = " "
- if board[7] == board[8] == board[9] == "X":
- winner == "X"
- if board[7] == board[8] == board[9] == "O":
- winner == "O"
- if board[5] == "X":
- winner == "X"
- return winner
- def win(game_won):
- input("jee")
- print(f"Game won by player {game_won}!!!")
- def nollaa_board():
- return [" ", " ", " ", " ", " ", " "," ", " ", " ", " "]
- pelimoottori(board)
- game_on = gameon_choice()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement