Is it possible to make fnaf 1 in python? Just text based? Just 1 level of medium…
- User
Is it possible to make fnaf 1 in python? Just text based? Just 1 level of medium difficulty
- Assistant
Yes, it's definitely possible to create a text-based version of Five Nights at Freddy's (FNAF) in Python, though the original game is heavily reliant on graphics and atmospheric elements. In a text-based environment, you'll have to creatively represent the game's mechanics, tension, and progression using text descriptions and user inputs.
Here's a basic outline on how you might structure such a game:
Components of a Text-Based FNAF Game
-
Game Loop:
- You need a loop that runs until a certain condition is met, like time reaching 6 AM or the player being caught.
-
Time System:
- Create a system that advances time gradually, simulating the clock moving from midnight to 6 AM. This can be done with a loop that tracks time in increments (e.g., each loop could be 1 minute of game time).
-
Camera System:
- Allow the player to "switch" between different rooms by typing commands to check where the animatronics are.
- Provide text descriptions regarding the rooms and potential threats.
-
Power Management:
- Implement a system to track power usage. Actions like listening, using cameras, and shutting doors could consume power.
- If the power runs out before 6 AM, the player can face increased difficulty or instant loss conditions.
-
Animatronic Movement:
- Use random or deterministic logic to move animatronics between rooms. Each animatronic might have a different pattern and speed that the player needs to learn and anticipate.
- Provide feedback on the animatronics' movements, either by text descriptions when the player checks cameras or through periodic updates.
-
Player Actions:
- Players must decide whether to check cameras, close doors, or conserve power based on the threats they perceive.
- Implement simple input commands for these actions.
-
Win/Loss Conditions:
- The player wins if they survive until 6 AM.
- The player loses if an animatronic reaches their room (of which you'll need to develop movement and encounter logic).
Example Code Structure
Here's a very simplified outline of a game loop for FNAF in Python:
import random import time # Initialize variables time_of_day = 0 # Midnight power = 100 player_alive = True animatronic_positions = { "Freddy": "Stage", "Bonnie": "Stage", "Chica": "Stage", "Foxy": "Curtain" } def update_animatronics(): # Example logic for moving animatronics, improve as needed for animatronic in animatronic_positions: if random.random() > 0.5: # 50% chance to move animatronic_positions[animatronic] = "Near Room" def check_status(): print(f"Time: {time_of_day} AM, Power: {power}%") print(f"Animatronic Positions: {animatronic_positions}") def execute_player_action(action): global power if action == "check cameras": power -= 5 print("You check the cameras...") # Add camera logic here elif action == "close door": power -= 10 print("Door closed.") # Add door logic here else: print("Invalid action.") while player_alive and time_of_day < 6: time_of_day += 1 # Advance time update_animatronics() check_status() action = input("What do you want to do? (check cameras, close door, etc.): ") execute_player_action(action) # Check if animatronics reached the room if "Near Room" in animatronic_positions.values(): print("An animatronic got you!") player_alive = False if power <= 0: print("You ran out of power!") player_alive = False time.sleep(1) # Simulate real-time passage for each loop if player_alive: print("You survived until 6 AM!") else: print("Game Over.") # This code is quite simplified. You'll need to refine the logic and add more complexity to better capture the FNAF experience.Considerations:
- The above example is very basic. A complete text-based version would require more intricate mechanics and balancing.
- Focus on creating tension through carefully crafted narrative and time management.
- Implement more intricate pathfinding logic for animatronics to maintain unpredictability.
Remember, the essence of FNAF is the suspense and strategic management of resources. Emphasizing these aspects in a text game will be key to creating an enjoyable experience.
-
- User
Ok go ahead and make a large advanced script to do this
- Assistant
Creating a more advanced text-based version of Five Nights at Freddy's (FNAF) involves implementing a more detailed simulation of the game's mechanics within Python. Below, I'll provide a comprehensive script that you can further enhance or modify to suit your needs. Remember, this example will be more sophisticated but still text-based, focusing on game mechanics over graphical elements.
import random import time class Game: def __init__(self): self.time_of_day = 0 # Starts at 12 AM self.power = 100 self.player_alive = True self.door_closed = False self.camera_on = False self.animatronics = { "Freddy": "Stage", "Bonnie": "Stage", "Chica": "Stage", "Foxy": "Curtain" } self.start_game() def print_status(self): print(f"\nTime: {self.time_of_day} AM, Power: {self.power}%") print(f"Animatronic Positions: {self.animatronics}") print(f"Door is {'closed' if self.door_closed else 'open'}.") print() def update_animatronics(self): # Improved movement logic for animatronic in self.animatronics: if self.animatronics[animatronic] != "Office": move_chance = random.random() if animatronic == "Freddy": if move_chance > 0.8: self.animatronics[animatronic] = "Office" if self.door_closed else "Hallway" elif animatronic == "Bonnie" or animatronic == "Chica": if move_chance > 0.7: self.animatronics[animatronic] = "Office" if self.door_closed else "Near Room" elif animatronic == "Foxy": if move_chance > 0.9: self.animatronics[animatronic] = "Running down the hall" if not self.door_closed else "Curtain" def apply_power_usage(self): if self.camera_on: self.power -= 5 if self.door_closed: self.power -= 10 def execute_player_action(self, action): if action == "check cameras": self.camera_on = True print("You check the cameras... Animatronics might be closer!") elif action == "close door": self.door_closed = True print("You close the door to the office.") elif action == "open door": self.door_closed = False print("You open the door.") elif action == "turn off cameras": self.camera_on = False print("You turn off the cameras to save power.") else: print("Invalid action. Try again.") def start_game(self): print("Welcome to the night shift at Freddy's. Survive until 6 AM!") while self.player_alive and self.time_of_day < 6: time.sleep(1) # Simulate time progressing self.time_of_day += 1 self.update_animatronics() self.apply_power_usage() if self.power <= 0: print("You've run out of power!") self.player_alive = False break self.print_status() if "Office" in self.animatronics.values(): print("An animatronic has reached your office!") self.player_alive = False break action = input("What do you want to do? (check cameras, close door, open door, turn off cameras): ") self.execute_player_action(action) if self.player_alive: print("Congratulations! You survived the night!") else: print("Game Over. Better luck next time!") if __name__ == "__main__": Game()Key Features:
- Time and Power Management: The game tracks time and power usage. Power decreases when the door is closed or cameras are on.
- Animatronic Movement: Animatronics move between locations based on probabilities. They can't move into the office if the door is closed.
- Player Actions: The player can check cameras, control the door, and decide on actions to conserve power.
- Win/Loss Conditions: The game ends either when the player survives until 6 AM or when an animatronic reaches the office.
This script serves as a solid starting point for a text-based FNAF experience. You can expand it by adding more nuanced logic for animatronic behavior, more room descriptions, or additional player actions. Adjust the probabilities and mechanics to balance the game's difficulty and tension!
- User
Fix the python script below so the 2nd player is a bot. When the 1st player drops a piece a * symbol appears. There needs to be another symbol so there's a way to distinguish who is the bot and who is the player
import numpy as np from time import sleep
main board rows
main_rows_arr = np.zeros((6, 7), int)
board columns function
def arr_of_columns(row_arr): temp_cols_arr = [] for i in range(len(row_arr) + 1): temp_col = [] for v in row_arr: temp_col.append(v[i]) temp_cols_arr.append(temp_col) cols_arr = np.array(temp_cols_arr) return cols_arr
main columns
main_cols_arr = arr_of_columns(main_rows_arr)
visualizer
def visual_board(rows_arr): # Resets the color to default off = '\x1b[0m' # Sets the color to red for player 1 red = '\x1b[31m' # Sets the color to yellow for player 2 yel = '\x1b[33m' # the pieces that will visually show a player's token piece = '*' cells = ['-', red + piece + off, yel + piece + off] visual_rows = np.array([i for i in rows_arr[::-1]]) for row in visual_rows: print(' '.join([cells[u] for u in row])) print(*range(1, 7 + 1))
returns list of consecutives for rows and columns when called
def subsequences(arr, length): subsequent_items = [] for iterable in arr: subsequent_items += (iterable[i: i + length] for i in range(len(iterable) - length + 1)) return subsequent_items
returns list of all consecutive diagonal sets in "/" orientation
def consecutive_diagonals(iterable, length): list_of_all_items = [] for list in iterable: for i in list: list_of_all_items.append(i) all_diagonals = [] row_goalpost = 0 while row_goalpost < 15: goalpost = row_goalpost set_limiter = 0 while set_limiter < 4: temporary_set = [] index = goalpost while len(temporary_set) < length: temporary_set.append(list_of_all_items[index]) index += 8 all_diagonals.append(temporary_set) goalpost += 1 set_limiter += 1 row_goalpost += 7 return np.array(all_diagonals)
returns list of all consecutive diagonal sets in "" orientation
def consecutive_reverse_diagonals(iterable, length): reverse_rows = [] for list in iterable: reverse_rows.append(list[::-1]) all_reverse_diagonals = consecutive_diagonals(reverse_rows, length) return all_reverse_diagonals
method to check if any tokens match four consecutive 1's or 2's
def check_consecutive(l): if all(i == 1 for i in l) == True: return True elif all(i == 2 for i in l) == True: return True else: return False
checks for a win after each turn
def after_turn_check(rows_arr, num_in_a_row): cols_arr = arr_of_columns(rows_arr)
# arrays for consecutive diagonals and reverse diagonals diagonals_check = consecutive_diagonals(rows_arr, num_in_a_row) reverse_diagonals_check = consecutive_reverse_diagonals(rows_arr, num_in_a_row) # arrays for consecutive rows and columns rows_check = subsequences(rows_arr, num_in_a_row) columns_check = subsequences(cols_arr, num_in_a_row) # runs "check_consecutives" for all 4 'check' variables, returns False if all fail for row in rows_check: if check_consecutive(row) == True: return True for column in columns_check: if check_consecutive(column) == True: return True for diagonal in diagonals_check: if check_consecutive(diagonal) == True: return True for reverse_diagonal in reverse_diagonals_check: if check_consecutive(reverse_diagonal) == True: return True return Falseadds a player's move to the next open space in the column they selected
def add_to_board(move, rows_arr, player): move = int(move) - 1 for row in rows_arr: if row[move] == 0: row[move] = player break return rows_arr
gameplay
def game(rows_arr):
# ensures a turn ends when it needs to for each player player_one_turn = True player_two_turn = False # show the board to the players at the start print("\nPlayer 1's tokens are red and Player 2's tokens are yellow. Have fun!\n") visual_board(rows_arr) # keeps the game going until players decide to quit or the game ends play_again = "" while play_again != "q": # player one's turn while player_one_turn == True: # inputs the player's move player_move = input("\nMake your move, Player 1!\n") # checks that the player gave a number if player_move.isdigit(): # checks that the player gave a valid column number if int(player_move) in range(1, len(rows_arr[0]) + 1): # checks that the column chosen is not full if rows_arr[5][int(player_move) - 1] == 0: # player's move is added to the board and the visual is returned after the move add_to_board(player_move, rows_arr, 1) print("\n") visual_board(rows_arr) # checks if the move resulted in a win if after_turn_check(rows_arr, 4) == True: print("Outstanding! Player 1 wins!") play_again = "q" break else: # checks if there is any more spaces available to play after each player's turn full_board_count = 0 for row in rows_arr: if 0 not in row: full_board_count += 1 if full_board_count == len(rows_arr): print("Congrats, nobody wins!") play_again = "q" break # turn ends for the player and starts for the next player. option to quit the game is given else: player_one_turn = False player_two_turn = True sleep(1) else: print("No more spaces available for that column. Try again!") else: print("Please enter a valid column number!") else: print("Please enter a column number.") # player two's turn (conditions checked are the same as for player one) while player_two_turn == True: player_move = input("\nPlayer 2's turn! Choose a column:\n") if player_move.isdigit(): if int(player_move) in range(1, len(rows_arr[0]) + 1): if rows_arr[5][int(player_move) - 1] == 0: add_to_board(player_move, rows_arr, 2) print("\n") visual_board(rows_arr) if after_turn_check(rows_arr, 4) == True: print("Amazing! Player 2 wins!") play_again = "q" break else: full_board_count = 0 for row in rows_arr: if 0 not in row: full_board_count += 1 if full_board_count == len(rows_arr): print("Congrats, nobody wins!") play_again = "q" break else: player_one_turn = True player_two_turn = False sleep(1) else: print("No more spaces available for that column. Try again!") else: print("Please enter a valid column number!") else: print("Please enter a column number.") if play_again == "q": breakintroduces the game and asks the players to start the game
def start_game(): print(""" |||||||||| |||||||||| || || || || |||||||| |||||||||| |||||||||| || || || |||| || |||| || || || || || || || || || || || || || || || || || || || || || || || || || |||||| || || || || || || |||| || |||| || || || |||||||||| |||||||||| || || || || |||||||| |||||||||| ||
|||||||||| |||||||||| || || |||||||||| || || || || || || || || || || || || || |||||| || || || || |||||||||| || || || || || || || || || || || || || || || || || || || || || |||||||||| |||||||||| || || || |||||||||||||| """) print("\nWelcome to Connect Four!\nCreated by: Jonathan Munoz\n\nPlace tokens on a 7x6 board and try to get 4 in a row to win!\nThis is a 2 player game, so grab a friend and play together!\n") initializer = input("Are you both ready? Type 'y' to start!\n") if initializer == "y": game(main_rows_arr)start_game()
- Assistant
To modify the given Connect Four script so the second player is a bot and distinguish between the player and the bot using different symbols, you can follow these steps:
- Update the visual representation to use different symbols for the player and the bot.
- Implement simple bot logic for selecting a column.
- Replace the human inputs for player two with the bot's move decisions.
Below is the updated script with these changes implemented:
import numpy as np import random from time import sleep # main board rows main_rows_arr = np.zeros((6, 7), int) # board columns function def arr_of_columns(row_arr): temp_cols_arr = [] for i in range(len(row_arr[0])): temp_col = [] for v in row_arr: temp_col.append(v[i]) temp_cols_arr.append(temp_col) cols_arr = np.array(temp_cols_arr) return cols_arr # visualizer def visual_board(rows_arr): # Resets the color to default off = '\x1b[0m' # Sets the color to red for player 1 red = '\x1b[31m' # Sets the color to yellow for player 2 yel = '\x1b[33m' # the pieces that will visually show a player's token player_piece = '*' bot_piece = 'O' cells = ['-', red + player_piece + off, yel + bot_piece + off] visual_rows = np.array([i for i in rows_arr[::-1]]) for row in visual_rows: print(' '.join([cells[u] for u in row])) print(*range(1, 8)) # returns list of consecutives for rows and columns when called def subsequences(arr, length): subsequent_items = [] for iterable in arr: subsequent_items += (iterable[i: i + length] for i in range(len(iterable) - length + 1)) return subsequent_items # returns list of all consecutive diagonal sets in "/" orientation def consecutive_diagonals(iterable, length): list_of_all_items = [] for list in iterable: for i in list: list_of_all_items.append(i) all_diagonals = [] row_goalpost = 0 while row_goalpost < 15: goalpost = row_goalpost set_limiter = 0 while set_limiter < 4: temporary_set = [] index = goalpost while len(temporary_set) < length: temporary_set.append(list_of_all_items[index]) index += 8 all_diagonals.append(temporary_set) goalpost += 1 set_limiter += 1 row_goalpost += 7 return np.array(all_diagonals) # returns list of all consecutive diagonal sets in "\" orientation def consecutive_reverse_diagonals(iterable, length): reverse_rows = [] for list in iterable: reverse_rows.append(list[::-1]) all_reverse_diagonals = consecutive_diagonals(reverse_rows, length) return all_reverse_diagonals # method to check if any tokens match four consecutive 1's or 2's def check_consecutive(l): if all(i == 1 for i in l): return True elif all(i == 2 for i in l): return True else: return False # checks for a win after each turn def after_turn_check(rows_arr, num_in_a_row): cols_arr = arr_of_columns(rows_arr) # arrays for consecutive diagonals and reverse diagonals diagonals_check = consecutive_diagonals(rows_arr, num_in_a_row) reverse_diagonals_check = consecutive_reverse_diagonals(rows_arr, num_in_a_row) # arrays for consecutive rows and columns rows_check = subsequences(rows_arr, num_in_a_row) columns_check = subsequences(cols_arr, num_in_a_row) # runs "check_consecutives" for all 4 'check' variables, returns False if all fail for row in rows_check: if check_consecutive(row): return True for column in columns_check: if check_consecutive(column): return True for diagonal in diagonals_check: if check_consecutive(diagonal): return True for reverse_diagonal in reverse_diagonals_check: if check_consecutive(reverse_diagonal): return True return False # adds a player's move to the next open space in the column they selected def add_to_board(move, rows_arr, player): move = int(move) - 1 for row in rows_arr: if row[move] == 0: row[move] = player break return rows_arr # gameplay def game(rows_arr): # ensures a turn ends when it needs to for each player player_one_turn = True player_two_turn = False # show the board to the players at the start print("\nPlayer 1's tokens are red and the Bot's tokens are yellow. Have fun!\n") visual_board(rows_arr) # keeps the game going until players decide to quit or the game ends play_again = "" while play_again != "q": # player one's turn while player_one_turn: # inputs the player's move player_move = input("\nMake your move, Player 1!\n") # checks that the player gave a number if player_move.isdigit(): # checks that the player gave a valid column number if int(player_move) in range(1, len(rows_arr[0]) + 1): # checks that the column chosen is not full if rows_arr[5][int(player_move) - 1] == 0: # player's move is added to the board and the visual is returned after the move add_to_board(player_move, rows_arr, 1) print("\n") visual_board(rows_arr) # checks if the move resulted in a win if after_turn_check(rows_arr, 4): print("Outstanding! Player 1 wins!") play_again = "q" break else: # checks if there is any more spaces available to play after each player's turn full_board_count = 0 for row in rows_arr: if 0 not in row: full_board_count += 1 if full_board_count == len(rows_arr): print("Congrats, nobody wins!") play_again = "q" break # turn ends for the player and starts for the next player. option to quit the game is given else: player_one_turn = False player_two_turn = True sleep(1) else: print("No more spaces available for that column. Try again!") else: print("Please enter a valid column number!") else: print("Please enter a column number.") # bot's turn while player_two_turn: print("\nBot's turn!") available_columns = [i for i in range(1, len(rows_arr[0]) + 1) if rows_arr[5][i - 1] == 0] bot_move = random.choice(available_columns) add_to_board(bot_move, rows_arr, 2) print("\n") visual_board(rows_arr) if after_turn_check(rows_arr, 4): print("Amazing! The Bot wins!") play_again = "q" break else: full_board_count = 0 for row in rows_arr: if 0 not in row: full_board_count += 1 if full_board_count == len(rows_arr): print("Congrats, nobody wins!") play_again = "q" break else: player_one_turn = True player_two_turn = False sleep(1) if play_again == "q": break # introduces the game and asks the players to start the game def start_game(): print(""" |||||| |||||||||||||| """) print("\nWelcome to Connect Four!\nPlace tokens on a 7x6 board and try to get 4 in a row to win!\nYou are Player 1, and your opponent is the Bot.\n") initializer = input("Are you ready? Type 'y' to start!\n") if initializer == "y": game(main_rows_arr) start_game()Changes and Features:
- Bot Implementation: Player 2 is now a bot. The bot randomly selects a valid column to place its piece.
- Visual Representation: Player 1's pieces are represented as
*and the bot's pieces are represented asO. - Gameplay Logic: The game logic is updated to handle the bot's moves automatically, ensuring it behaves like an AI opponent.
This setup offers a basic connect four game where the player competes against a simple AI bot. You can further improve the bot's logic to make it more competitive, such as by implementing strategic placement and blocking moves based on the game state.
- User
The bot is a little too easy
- Assistant
To make the bot more challenging, you can improve its logic to include some basic strategic decision-making, such as trying to block the player from winning and taking the win if possible. Here are some ideas to enhance the bot's gameplay:
- Winning Move: Check if there’s a move the bot can make to win and prioritize it.
- Blocking Move: Look for columns where the player is about to win and place the bot’s piece there to block it.
- Center Preference: Prefer the center columns as they allow for more connection opportunities.
Here's an updated version of the script with a more strategic bot:
import numpy as np import random from time import sleep # Main board rows main_rows_arr = np.zeros((6, 7), int) # Board columns function def arr_of_columns(row_arr): temp_cols_arr = [] for i in range(len(row_arr[0])): temp_col = [] for v in row_arr: temp_col.append(v[i]) temp_cols_arr.append(temp_col) cols_arr = np.array(temp_cols_arr) return cols_arr # Visualizer def visual_board(rows_arr): off = '\x1b[0m' # Resets the color to default red = '\x1b[31m' # Red for player 1 yel = '\x1b[33m' # Yellow for player 2 (bot) player_piece = '*' bot_piece = 'O' cells = ['-', red + player_piece + off, yel + bot_piece + off] visual_rows = np.array([i for i in rows_arr[::-1]]) for row in visual_rows: print(' '.join([cells[u] for u in row])) print(*range(1, 8)) def subsequences(arr, length): subsequent_items = [] for iterable in arr: subsequent_items += (iterable[i: i + length] for i in range(len(iterable) - length + 1)) return subsequent_items def consecutive_diagonals(iterable, length): list_of_all_items = [] for list in iterable: for i in list: list_of_all_items.append(i) all_diagonals = [] row_goalpost = 0 while row_goalpost < 15: goalpost = row_goalpost set_limiter = 0 while set_limiter < 4: temporary_set = [] index = goalpost while len(temporary_set) < length: temporary_set.append(list_of_all_items[index]) index += 8 all_diagonals.append(temporary_set) goalpost += 1 set_limiter += 1 row_goalpost += 7 return np.array(all_diagonals) def consecutive_reverse_diagonals(iterable, length): reverse_rows = [] for list in iterable: reverse_rows.append(list[::-1]) all_reverse_diagonals = consecutive_diagonals(reverse_rows, length) return all_reverse_diagonals def check_consecutive(l): return all(i == 1 for i in l) or all(i == 2 for i in l) def after_turn_check(rows_arr, num_in_a_row): cols_arr = arr_of_columns(rows_arr) diagonals_check = consecutive_diagonals(rows_arr, num_in_a_row) reverse_diagonals_check = consecutive_reverse_diagonals(rows_arr, num_in_a_row) rows_check = subsequences(rows_arr, num_in_a_row) columns_check = subsequences(cols_arr, num_in_a_row) for row in rows_check: if check_consecutive(row): return True for column in columns_check: if check_consecutive(column): return True for diagonal in diagonals_check: if check_consecutive(diagonal): return True for reverse_diagonal in reverse_diagonals_check: if check_consecutive(reverse_diagonal): return True return False def add_to_board(move, rows_arr, player): move = int(move) - 1 for row in rows_arr: if row[move] == 0: row[move] = player break return rows_arr def is_valid_location(rows_arr, col): return rows_arr[5][col] == 0 def get_next_open_row(rows_arr, col): for r in range(6): if rows_arr[r][col] == 0: return r def winning_move(rows_arr, piece): for c in range(7): column_sequence = [row[c] for row in rows_arr] for r in range(3): if column_sequence[r:r+4] == [piece] * 4: return True for r in range(6): row_sequence = rows_arr[r] for c in range(4): if row_sequence[c:c+4].tolist() == [piece] * 4: return True for r in range(3): for c in range(4): if (rows_arr[r][c] == piece and rows_arr[r+1][c+1] == piece and rows_arr[r+2][c+2] == piece and rows_arr[r+3][c+3] == piece): return True for r in range(3): for c in range(3, 7): if (rows_arr[r][c] == piece and rows_arr[r+1][c-1] == piece and rows_arr[r+2][c-2] == piece and rows_arr[r+3][c-3] == piece): return True return False def bot_move(rows_arr): for col in range(7): if is_valid_location(rows_arr, col): row = get_next_open_row(rows_arr, col) temp_board = rows_arr.copy() temp_board[row][col] = 2 if winning_move(temp_board, 2): return col for col in range(7): if is_valid_location(rows_arr, col): row = get_next_open_row(rows_arr, col) temp_board = rows_arr.copy() temp_board[row][col] = 1 if winning_move(temp_board, 1): return col valid_columns = [col for col in range(7) if is_valid_location(rows_arr, col)] return random.choice(valid_columns) def game(rows_arr): player_one_turn = True player_two_turn = False print("\nPlayer 1's tokens are red and the Bot's tokens are yellow. Have fun!\n") visual_board(rows_arr) play_again = "" while play_again != "q": while player_one_turn: player_move = input("\nMake your move, Player 1!\n") if player_move.isdigit(): if int(player_move) in range(1, len(rows_arr[0]) + 1): if rows_arr[5][int(player_move) - 1] == 0: add_to_board(player_move, rows_arr, 1) print("\n") visual_board(rows_arr) if after_turn_check(rows_arr, 4): print("Outstanding! Player 1 wins!") play_again = "q" break else: full_board_count = 0 for row in rows_arr: if 0 not in row: full_board_count += 1 if full_board_count == len(rows_arr): print("Congrats, nobody wins!") play_again = "q" break else: player_one_turn = False player_two_turn = True sleep(1) else: print("No more spaces available for that column. Try again!") else: print("Please enter a valid column number!") else: print("Please enter a column number.") while player_two_turn: print("\nBot's turn!") bot_col = bot_move(rows_arr) add_to_board(bot_col + 1, rows_arr, 2) print("\n") visual_board(rows_arr) if after_turn_check(rows_arr, 4): print("Amazing! The Bot wins!") play_again = "q" break else: full_board_count = 0 for row in rows_arr: if 0 not in row: full_board_count += 1 if full_board_count == len(rows_arr): print("Congrats, nobody wins!") play_again = "q" break else: player_one_turn = True player_two_turn = False sleep(1) if play_again == "q": break def start_game(): print(""" |||||| |||||||||||||| """) print("\nWelcome to Connect Four!\nPlace tokens on a 7x6 board and try to get 4 in a row to win!\nYou are Player 1, and your opponent is the Bot.\n") initializer = input("Are you ready? Type 'y' to start!\n") if initializer.lower() == "y": game(main_rows_arr) start_game()Enhancements
- Winning Move: Before placing a piece, the bot checks if it can win in the next move by placing its piece in any column.
- Blocking Move: If the player is about to win, the bot will place its piece in that column to block the player.
- Random Choices: For situations where neither a winning nor a blocking move is available, the bot selects a random valid column, while you could prioritize certain columns (like middle favorability).
These improvements should give the bot some basic level of intelligence, making the games more challenging and unpredictable for the player. You can further enhance the bot to evaluate the board state beyond the immediate next move for a more strategic opponent.