Esempio n. 1
0
                    else:
                        player_turn = False
                        AI_turn = True

    # --- Game logic should go here
    # If user presses start - make sure that all the board pieces are in the correct place, then start game
    if not setup:
        if AI_turn:

            # Q LEARNING AI:
            # Update message box:
            message = "AI's turn"
            color_message_box()
            update_message_box(message)
            sunken_ships = player.get_sunken_ships()
            row, col = AI.Q_Learning_AI(last_AI_attack, sunken_ships)
            player.suffer_attack(row, col)
            # Check for sunken ships:
            player.check_sunken_ships()
            last_AI_attack = player.get_state(row, col)
            # Update display:
            board_array = player.get_board()
            update_AI_grid(board_array)

            # Check if AI wins:
            if player.check_loss():
                AI_win = True
                carryOn = False

            # Update turn: If last turn was a hit or sink, go again
            if last_AI_attack == Cell.HIT or last_AI_attack == Cell.SUNK: