samedi 16 mars 2019

Print statement not printing from if statement

Sorry I know this is going to seem very stupid, I'm new to coding and have been working on this tic tac toe program in Python (I know much of the code is probably redundant and could be solved more efficiently) for practice, my issue is that my newgame and player2 methods, if statement blocks aren't printing at all and when I format them, the if and elif statements are both printed, I think it's an indentation issue but beautify didn't fix it either, any help please? P.S I know it's still extremely unfinished lmao

    playercount = 0
game = [[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]]

print("Player 1 is X Player 2 is O")
if playercount == 0:
    playercount += 1


def whosgo():
    mod = playercount % 2
    if mod > 0:
        print("it's player 1's turn")
    else:
        print("it's player 2's turn, O's")


def createboard():
    tcolumns = "    |   " * 2
    print(tcolumns)
    rows = " ---------------"
    print(rows)
    print(tcolumns)
    print(rows)
    print(tcolumns)


def newgame():
    playercount = 0
    row = input("what row do you want to go in? ")
    column = input("and what column? ")
    rows = " ---------------"
    tcolumns = "    |   " * 2
    if row == 1 and column == 1:
        print("  X |       |    ")
        print(rows)
        print(tcolumns)
        print(rows)
        print(tcolumns)
        playercount += 1
        game.insert(0, game[1])
    elif row == 2 and column == 2:
        print("  X |   O   |    ")
        print(rows)
        print("    |   X   |    ")
        print(rows)
        print(tcolumns)
        playercount += 1


def player2():
    print("it's player 2's turn")
    playercount = 1
    row = input("what row do you want to go in? ")
    column = input("and what column? ")
    if row == 1 and column == 2:
        game.insert(1, game[2])
        tcolumns = "    |   " * 2
        print("  X |   O   |    ")
        rows = " ---------------"
        print(rows)
        print(tcolumns)
        print(rows)
        print(tcolumns)
        playercount += 1
    elif row == 2 and column == 2:
        game.insert(1, game[2])
        tcolumns = "    |   " * 2
        print("  O |      |    ")
        rows = " ---------------"
        print(rows)
        print(tcolumns)
        print(rows)
        print(tcolumns)
        playercount += 1
    # print(playercount)


def whowon():
    winner_is_2 = [[2, 2, 0],
                   [2, 1, 0],
                   [2, 1, 1]]

    winner_is_2d = [[2, 2, 2],
                    [2, 1, 0],
                    [0, 1, 1]]

    winner_is_1 = [[1, 2, 0],
                   [2, 1, 0],
                   [2, 1, 1]]
    no_winner = [[1, 2, 0],
                 [2, 1, 0],
                 [2, 1, 2]]

    also_no_winner = [[1, 2, 0],
                      [2, 1, 0],
                      [2, 1, 0]]
    if game == winner_is_2:
        print("congrats X wins!!")
    elif game == winner_is_2d:
        print("congrats X wins!")
    elif game == winner_is_1:
        print("congrats O wins!!")
    elif no_winner == game:
        print("it's a tie!!")
    elif also_no_winner == game:
        print("it's a tie!!")
    while game != winner_is_2 and game != winner_is_2d and game != winner_is_1 and game != no_winner and game != also_no_winner:
        whosgo()
        newgame()
        player2()


createboard()
whowon()

Aucun commentaire:

Enregistrer un commentaire