ThomasMarx
New Coder
playerx = input("Insert player 1 username: ")
playery = input("Insert player 2 username: ")
board = [["1,1", "1,2", "1,3"], ["2,1", "2,2", "2,3"], ["3,1", "3,2", "3,3"]]
def printBoard(board):
print(board[0][0] + '|' + board[0][1] + '|' + board[0][2])
print(' - + - + -')
print(board[1][0] + '|' + board[1][1] + '|' + board[1][2])
print(' - + - + -')
print(board[2][0] + '|' + board[2][1] + '|' + board[2][2])
gamenum = 1
while gamenum < 10:
printBoard(board)
playerx1 = int(input("what row? "))
playerx2 = int(input("Which space in that row? "))
if gamenum == 1 or 3 or 5 or 7 or 9:
if board[playerx1 - 1][playerx2 - 1] == "X" or board[playerx1 - 1][playerx2 - 1] == "O":
print("There is already something here. You just lost your turn, " + playerx)
continue
else:
board[playerx1 - 1][playerx2 - 1] = "X"
gamenum = gamenum + 1
printBoard(board)
playery1 = int(input("what row? "))
playery2 = int(input("What space in that row? "))
if gamenum == 2 or 4 or 6 or 8:
if board[playery1 - 1][playery2 - 1] == "X" or board[playery1 - 1] == "O":
print("There is already something here. You just lost your turn, " + playery)
continue
else:
board[playery1 - 1][playery2 - 1] = "O"
gamenum = gamenum + 1
if board[0][0] and board[0][1] and board[0][2] == "X":
gamenum = 100
print(playerx + " Wins!")
if board[0][0] and board [0][1] and board [0][2] == "O":
gamenum = 100
print(playery + " Wins!")
i have it so where my code will check the top line and it seemingly works, however, i feel like doing this for every win option would be tedious and unoptimized, is there a better way to do this?
playery = input("Insert player 2 username: ")
board = [["1,1", "1,2", "1,3"], ["2,1", "2,2", "2,3"], ["3,1", "3,2", "3,3"]]
def printBoard(board):
print(board[0][0] + '|' + board[0][1] + '|' + board[0][2])
print(' - + - + -')
print(board[1][0] + '|' + board[1][1] + '|' + board[1][2])
print(' - + - + -')
print(board[2][0] + '|' + board[2][1] + '|' + board[2][2])
gamenum = 1
while gamenum < 10:
printBoard(board)
playerx1 = int(input("what row? "))
playerx2 = int(input("Which space in that row? "))
if gamenum == 1 or 3 or 5 or 7 or 9:
if board[playerx1 - 1][playerx2 - 1] == "X" or board[playerx1 - 1][playerx2 - 1] == "O":
print("There is already something here. You just lost your turn, " + playerx)
continue
else:
board[playerx1 - 1][playerx2 - 1] = "X"
gamenum = gamenum + 1
printBoard(board)
playery1 = int(input("what row? "))
playery2 = int(input("What space in that row? "))
if gamenum == 2 or 4 or 6 or 8:
if board[playery1 - 1][playery2 - 1] == "X" or board[playery1 - 1] == "O":
print("There is already something here. You just lost your turn, " + playery)
continue
else:
board[playery1 - 1][playery2 - 1] = "O"
gamenum = gamenum + 1
if board[0][0] and board[0][1] and board[0][2] == "X":
gamenum = 100
print(playerx + " Wins!")
if board[0][0] and board [0][1] and board [0][2] == "O":
gamenum = 100
print(playery + " Wins!")
i have it so where my code will check the top line and it seemingly works, however, i feel like doing this for every win option would be tedious and unoptimized, is there a better way to do this?