• Regolamento Macrocategoria DEV
    Prima di aprire un topic nella Macrocategoria DEV, è bene leggerne il suo regolamento. Sei un'azienda o un hosting/provider? Qui sono anche contenute informazioni per collaborare con Sciax2 ed ottenere l'accredito nella nostra community!

Problema Gioco Tris in Python

simran

Nuovo utente
Autore del topic
13 Aprile 2020
2
3
Miglior risposta
0
consegna per il 15, qualcuno può aiutarmi allego fino a dove sono arrivata e la consegna . link di python tutor..
Perfavore, Entra oppure Registrati per vedere i Link!


CONSEGNA:
# function to clear the screen
def cls():
os.system('cls' if os.name=='nt' else 'clear')

# drawBoard: print the current status of the board
def drawBoard(board):
pass

# createNewBoard: return a new empty board
# 1. Reset the board (NB: must be a square board)
# 2. return the new board
def createNewBoard(size):
pass

# chooseShapeForPlayer: map the player with his shape
# 1. Ask the player to choose a shape among the availables
def chooseShapeForPlayer(playerNumber):
pass

# selectSquare: given a board of size "n" ask the user to select a square between 1-n.
# 1. size: the size of the board
# 2. return the coordinate (x,y) of the selected square
def selectSquare(size):
selection = int(input("Select a square [1-"+ str(size**2) + "]: "))
if not 1 <= selection <= size**2:
raise ValueError
selection -= 1
return (selection // size, selection % size)

# updateBoard: update the board in selected position with the current player symbol
# 1. selection: the current selected square
# 2. currentPlayer: the current player
# 3. board: the board of the game
def updateBoard(selection, currentPlayer, board):
pass

# isDraw: return False if there are no moves, True otherwise
# board: board of the game
def isDraw(board):
pass

# isWin: return True if there is a winner, False otherwise
# board: board of the game
def isWin(board):
winner = None

# TODO: check rows


# TODO: check columns


# TODO: check diagonal


# TODO: check anti-diagonal --> reverse board rows and check diagonal


if winner is not None:
cls()
drawBoard(board)
print("The winner is: '" + winner + "''")
return True
else:
return isDraw(board)

def tryAgain(answer):
yes = set(['yes','y', 'ye', ''])
no = set(['no','n'])

while True:
choice = input(answer).lower()
if choice in yes:
return True
elif choice in no:
return False
else:
print("Please respond with 'yes' or 'no'");

# printStatistics: print the total scores of both players
def printStatistics():
pass

# startNewMatch:
# 1. Ask the players to choosa a shape
# 2. Create a new empty board of size n
# 3. Move and update the board
# 4. Choose the first player in a random way
# 5. while is not game over
# 5.a Draw the board updated
# 5.b Inform the player that is his turn and ask him to select a square.
# 5.c Update the board
# 5.d Check the status of the board (1. not finish, 2. no moves, 3. winner)
# 5.e Switch the player turn or ask for a new match.
def startNewGame():
pass


if name == "main":
print('~'*60)
print(' '*18 + "Welcome to Tic Tac Toe!" + ' '*18)
print('~'*60)
startNewGame()
 
Sposto nella sezione corretta, questa sezione è riservata alle presentazioni.