Python while() loop won't end

Viewed 41

I'm programing a game where the turns alternate between 2 players. I have a while loop set to terminate whenever the bool gameOn == false. But it doesn't seem to do that. The turns keep repeating forever.

Anyway, here's the code

def main():

gameOn = True

while (gameOn == True):
    
    # P1's turn
    if (gameOn == True):
        p1Choice = int(input("P1 move: "))
        write(1, p1Choice)
        if (checkHorz() == False):
            gameOn = False
            print("Player 1 wins!!")
        
    
    # P2's turn
    if (gameOn == True):
        p2Choice = int(input("P2 move: "))
        write(2, p2Choice)
        if (checkHorz() == False):
            gameOn = False
            print("Player 2 wins!!")
        
main()

edit: here's the code of the function checkHorz(). Sorry it's not pretty

def checkHorz():
for i in range (1, 8, 1):
    if (row1[i] == row1[i + 1] == row1[i + 2] == row1[i + 3] and row1[i] != "e"):
        return False
    if (row2[i] == row2[i + 1] == row2[i + 2] == row2[i + 3] and row2[i] != "e"):
        return False
    if (row3[i] == row3[i + 1] == row3[i + 2] == row3[i + 3] and row3[i] != "e"):
        return False
    if (row4[i] == row4[i + 1] == row4[i + 2] == row4[i + 3] and row4[i] != "e"):
        return False
    if (row1[i] == row5[i + 1] == row5[i + 2] == row5[i + 3] and row5[i] != "e"):
        return False
    if (row1[i] == row6[i + 1] == row6[i + 2] == row6[i + 3] and row6[i] != "e"):
        return False
    else:
        return True

Sorry if my code is trash I just learned Python a month ago

0 Answers
Related