How do I Implement a extra turn option for example if Player X manages to get a strike in one board then next turn would still be player X's turn the same goes for player O the winner of the game would be decided on who wins the LAST board and if someone could help make a restart option it would be greatly appreciated.
#eerererer
import os
os.system('cls')
board = [' ' for x in range (27)]
ef inptLetter(letter, pos):
board[pos] = letter
def spaceIsFree(move):
print("spaceIsFree: " + board[move] == ' ')
return board[move] == ' '
def printBoard(board):
os.system('cls')
print(' | |' + ' | |' + ' | |')
print(' ' + board[0] + ' | ' + board[1] + ' | ' + board[2] +' '+ ' ' + board[9] + ' | ' + board[10] + ' | ' + board[11] +' ' + ' ' + board[18] + ' | ' + board[19] + ' | ' + board[20])
print(' | |' + ' | |' + ' | |')
print('-----------' + ' -----------' + ' -----------')
print(' | |' + ' | |' + ' | |')
print(' ' + board[3] + ' | ' + board[4] + ' | ' + board[5] +' '+ ' ' + board[12] + ' | ' + board[13] + ' | ' + board[14] +' '+ ' ' + board[21] + ' | ' + board[22] + ' | ' + board[23])
print(' | |' + ' | |' + ' | |' )
print('-----------' + ' -----------' + ' -----------')
print(' | |' + ' | |' + ' | |')
print(' ' + board[6] + ' | ' + board[7] + ' | ' + board[8] +' '+ ' ' + board[15] + ' | ' + board[16] + ' | ' + board[17] +' '+ ' ' + board[24] + ' | ' + board[25] + ' | ' + board[26])
print(' | |' + ' | |' + ' | |')
def Winner(t, le):
return (t[0] == le and t[1] == le and t[2] == le) or (t[3] == le and t[4] == le and t[5] == le) or (t[6] == le and t[7] == le and t[8] == le) or (t[0] ==le and t[3] == le and t[6] == le) or (t[1] == le and t[4] == le and t[7] == le) or (t[2] == le and t[5] == le and t[8] == le ) or (t[0] == le and t[4] == le and t[8] == le) or (t[9] == le and t[10] == le and t[11] == le) or (t[12] == le and t[13] == le and t[14] == le) or (t[12] == le and t[13] == le and t[14] == le) or (t[15] == le and t[16] == le and t[17] == le) or (t[9] == le and t[12] == le and t[15] == le) or (t[10] == le and t[13] == le and t[16] == le) or (t[11] == le and t[14] == le and t[17] == le) or (t[9] == le and t[13] == le and t[17] == le) or (t[11] == le and t[13] == le and t[15] == le)
def Player1Move():
run = True
while run:
move = input("select a tile sir to place an \'X\' (1-26): ")
try:
move = int(move)
if move > 0 and move < 27:
if spaceIsFree(move-1):
run = False
inptLetter('x', move)
else:
print("Please pick another tile mah dude")
else:
print("please pick a valid number")
except:
print("that aint a number fam cmon")
def Player2Move():
run = True
while run:
move = input("select a tile sir to place an \'O\' (1-26): ")
try:
move = int(move)
if move > 0 and move < 27 :
if spaceIsFree(move-1):
run = False
inptLetter('o', move)
else:
print("Please pick another tile mah dude")
else:
print("please pick a valid number")
except:
print("that aint a number fam cmon")
def isBoardFull(board):
if board.count(' ')> 0:
return False
else:
return True
def main():
print("welcome to tictactoe")
printBoard(board)
cont = True
winner = ''
while not(isBoardFull(board)) and cont:
if not(Winner(board, 'o')):
Player1Move()
printBoard(board)
else:
winner = 'o'
cont = False
if not(isBoardFull(board)) and cont:
if not(Winner(board, 'x')):
Player2Move()
printBoard(board)
else:
winner = 'x'
cont = False
if winner != '':
print('Winner is :' + winner)
elif isBoardFull(board):
print('Tie Game!')
main()
Comments
Post a Comment