Skip to content
The Chat Archive
o1-preview-2024-09-12· OpenAI WildChat-4.8M (AI2)

Write a Bitburner-esque Python command line game. You will have control of a "server" as…

  1. User

    Write a Bitburner-esque Python command line game. You will have control of a "server" as the player and can connect to adjacent servers after scanning. Once you connect to them, you can gain control over them with a command. Then, you can run a command to steal money, or to grow the existing money, or to make it so you get more money next time you steal money. Design this game and give me the code. Thanks!

  2. Assistant

    Sure! I'll help you create a simplified version of a Bitburner-like command-line game in Python. The game will allow the player to:

    • Scan and discover adjacent servers.
    • Connect to discovered servers.
    • Gain control over servers.
    • Perform actions like stealing money, growing money, and increasing money gains.

    Below is the complete code for the game, along with comments to explain how everything works.

    import random
    
    class Server:
        def __init__(self, name, money, security_level, neighbors):
            self.name = name
            self.money = money
            self.security_level = security_level
            self.neighbors = neighbors  # List of adjacent server names
            self.controlled = False
    
        def __str__(self):
            return f"Server {self.name}: Money=${self.money}, Security Level={self.security_level}, Controlled={self.controlled}"
    
    class Game:
        def __init__(self):
            self.servers = {}
            self.current_server = 'home'
            self.player_controlled_servers = {'home'}
            self.init_servers()
            self.run_game()
    
        def init_servers(self):
            # Initialize servers with some preset data
            self.servers['home'] = Server('home', 0, 0, ['server1', 'server2'])
            self.servers['server1'] = Server('server1', 500, 5, ['home', 'server3'])
            self.servers['server2'] = Server('server2', 800, 10, ['home'])
            self.servers['server3'] = Server('server3', 1500, 15, ['server1', 'server4'])
            self.servers['server4'] = Server('server4', 3000, 20, ['server3'])
            # You can add more servers as needed
    
        def run_game(self):
            print("Welcome to the Bitburner-esque Hacking Game!")
            print("Type 'help' to see a list of commands.\n")
            while True:
                command = input(f"{self.current_server}> ").strip().lower()
                if command == 'help':
                    self.print_help()
                elif command == 'scan':
                    self.scan()
                elif command.startswith('connect'):
                    self.connect(command)
                elif command == 'serverinfo':
                    self.server_info()
                elif command == 'hack':
                    self.hack()
                elif command == 'grow':
                    self.grow()
                elif command == 'weaken':
                    self.weaken()
                elif command == 'list':
                    self.list_servers()
                elif command == 'exit':
                    print("Exiting the game.")
                    break
                else:
                    print("Unknown command. Type 'help' to see available commands.")
    
        def print_help(self):
            print("""
    Available commands:
    - help: Show this help message.
    - scan: Scan for adjacent servers.
    - connect <servername>: Connect to a server.
    - serverinfo: Get info about the current server.
    - hack: Attempt to steal money from the server.
    - grow: Increase the server's money.
    - weaken: Reduce the server's security level.
    - list: List servers you control.
    - exit: Exit the game.
    """)
    
        def scan(self):
            server = self.servers[self.current_server]
            print("Adjacent servers:")
            for neighbor in server.neighbors:
                print(f"- {neighbor}")
    
        def connect(self, command):
            parts = command.split()
            if len(parts) != 2:
                print("Usage: connect <servername>")
                return
            target_server = parts[1]
            if target_server in self.servers[self.current_server].neighbors:
                self.current_server = target_server
                print(f"Connected to {target_server}.")
            else:
                print(f"Cannot connect to {target_server}. It is not adjacent to {self.current_server}.")
    
        def server_info(self):
            server = self.servers[self.current_server]
            print(server)
    
        def hack(self):
            server = self.servers[self.current_server]
            if server.controlled:
                stolen_money = int(server.money * 0.1)
                server.money -= stolen_money
                print(f"You hacked {server.name} and stole ${stolen_money}!")
            else:
                success_chance = max(0, 50 - server.security_level)
                if random.randint(1, 100) <= success_chance:
                    server.controlled = True
                    self.player_controlled_servers.add(server.name)
                    print(f"You gained control over {server.name}!")
                else:
                    print(f"Hack failed! Security level is too high.")
    
        def grow(self):
            server = self.servers[self.current_server]
            if server.controlled:
                increase = int(server.money * 0.2)
                server.money += increase
                print(f"Server money increased by ${increase}!")
            else:
                print(f"You need to gain control over {server.name} to grow its money.")
    
        def weaken(self):
            server = self.servers[self.current_server]
            reduction = 5
            server.security_level = max(0, server.security_level - reduction)
            print(f"Reduced security level of {server.name} by {reduction} points.")
    
        def list_servers(self):
            print("Servers you control:")
            for server_name in self.player_controlled_servers:
                print(f"- {server_name}")
    
    if __name__ == "__main__":
        Game()
    

    Explanation of the Game Mechanics

    • Servers: Each server is represented by an instance of the Server class. It has a name, amount of money, security level, list of neighboring servers, and a controlled status.

    • Player Actions:

      • scan: Lists adjacent servers to the current server.
      • connect <servername>: Connects to an adjacent server.
      • serverinfo: Displays information about the current server.
      • hack:
        • If you have not gained control over the server yet, you attempt to hack it.
        • The success chance of hacking is based on the server's security level.
        • If successful, you gain control of the server.
        • If already controlled, you steal 10% of its money.
      • grow: Increases the server's money by 20%, but you need to control the server first.
      • weaken: Reduces the server's security level by a fixed amount, making hacking easier.
      • list: Lists all servers under your control.
      • exit: Exits the game.
    • Game Flow: The game runs in a loop, taking commands from the player and executing them.

    • Starting Point: The player starts at the 'home' server.

    • Security Level: Represents how difficult it is to hack a server. You can reduce it using the weaken command.

    • Controlled Servers: Servers that you've hacked successfully and have control over.

    How to Run the Game

    1. Copy the code into a file named bitburner_game.py.

    2. Open a terminal and navigate to the directory containing the file.

    3. Run the game using the command:

      python bitburner_game.py
      
    4. Follow the prompts in the command line to play the game.

    Possible Extensions

    This is a basic framework, and you can extend the game by:

    • Adding more servers with different properties.
    • Implementing a player money system to keep track of total earnings.
    • Adding more actions, like scripting automated tasks.
    • Introducing a hacking skill level that increases with successful hacks.
    • Creating an experience system where certain actions give experience points.

    Enjoy playing the game and feel free to expand upon it!

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.