0

My problem is, after calling the function check_win in the gameloop, even though the function evaluates false(I've checked so this is the case), I assign this false value to gamePlaying inside the loop, however the game loop gamePlaying conditional still evaluates true and keeps going.

def check_win(): #function checks for three in a row across, down, and diagonals
        for x in range (0, 3) :
            y = x*3
            if (board[y] == board[(y + 1)] and board[y] == board[(y + 2)]):
                gamePlaying = False
            else:
                gamePlaying = True
            if (board[x] == board[(x + 3)] and board[x] == board[(x + 6)]):
                gamePlaying = False
            else:
                gamePlaying = True
            if((board[0] == board[4] and board[0] == board[8]) or 
                (board[2] == board[4] and board[4] == board[6])):
                gamePlaying = False
            else:
                gamePlaying = True
        return(gamePlaying)

    currentPlayer = [first_player,second_player] #creates list to iterate over turns
    gamePlaying = True #bool for gameloop

    while gamePlaying: #main game loop
        for i in currentPlayer: #iterates over current player to switch turns

            draw_board()
            place_move = int(input(first_move + ' what is your move? ')) #inputs then places move for first_player
            board[place_move] = first_player
            gamePlaying = check_win() #should take bool output of check_win and store to cont or end gameloop

            draw_board()
            place_move = int(input(second_move + ' what is your move? ')) #inputs then places move for second_player
            board[place_move] = second_player
            gamePlaying = Check_win() #should take bool output of check_win and store to cont or end gameloop
ata
  • 3,398
  • 5
  • 20
  • 31

1 Answers1

0

The issue is that you are using if statements when you mean to use elif. See the docs.

However, what you probably want to do is return False at those points since that would allow the function to exit early and you would have to worry that gamePlaying gets set back to True by later if statements.

Zev
  • 3,423
  • 1
  • 20
  • 41