Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

SPOOKEXE/computercraft-turtle-botnet

Repository files navigation

ComputerCraft Turtle BotNet

ComputerCraft Turtles that self-replicate by mining their own resources and crafting the necessary components for new turtles to be created.

After several turtles have been created, it starts another system which acts as a complex 'hive' mind that has leader-driven behavior. This will give turtles specific jobs, such as farming trees, mining resources, crafting materials, smelting resources, etc.

This only takes effect after a threshold of turtles have been replicated.

How It Works

For this implementation of the system, I have python handle the majority of the calculations, behaviors and procedures of the turtles.

For the turtles, I make them simply connect to the python webserver using websockets to pull the turtle's next job, and I keep state persistence inside the turtle for when they are chunk unloaded and loaded, as the turtle's virtual machine is reloaded, and parse the action then return the results.

The following high-level diagram shows this complete turtle-perspective process of it connecting to the python server.

Turtle-Perspective Flowchart

Here is a perspective of the server-side when the turtle connects to the python websocket: Python Server Turtle Flowchart

For the python backend, there is many pieces to the puzzle, so here is quick list of components:

  1. CORE COMPONENTS:

    • Websocket Wrapper
    • Behavior Tree System
    • Recipe Resolver
    • Asynchronous Operations
  2. EXTRA COMPONENTS:

    • 3D World Visualizer
    • Fully Serializable

And here is a version of the turtle behavior tree diagram for when the turtles are first starting off: Behavior Trees Flowchart

The HIVE behavior tree has not been implemented yet and will be in the future once this base system is complete and the turtles have the capacity to replicate.

...

...

Installation

Python

  1. Have any version of python 3 installed.
  2. Run pip install -r requirements.txt

ComputerCraft

  1. Install ComputerCraft or ComputerCraft:Tweaked; any version is supported that has websockets.

How To Use

Python

  1. View the installation section if you have not yet.
  2. Run the following script; python -> __init__.py

ComputerCraft

  1. In your Minecraft World Folder, allow websocket connections to your host in the World Folder -> serverconfig -> computercraft-server.toml file.

  2. In your turtle, place the following items inside the turtle inventory:

    Minimum Turtle Requirements

    Optionally you can also add any of these additional items to speed up the turtle process:

    Additional Items

    The final item, the chunk controller, allows the turtle to keep the chunk the turtle is in loaded, and is highly recommended if its available and you are able to craft it.

  3. Pick one of the following setup instructions depending on your circumstances:

    Singleplayer (World Folder):

    i. Copy turtle -> main -> startup.lua from this repository to your turtle folder. You can find the turtle folder in the minecraft world folder -> computercraft -> computer -> [TURTLE_ID] folder. If you need to find your turtle id, open the target turtle and run id.

    ii. Reboot the turtle with reboot.

    SinglePlayer & Multiplayer (Pastebin):

    i. Upload turtle -> main -> startup.lua from this repository to pastebin.

    ii. In the target turtle, use pastebin [URL_HERE] startup.lua, replacing [URL_HERE] with the pastebin url.

    iii. Reboot the turtle with reboot.

    Singleplayer & Multiplayer (Manual):

    i. Open the turtle -> main -> startup.lua file in this repository.

    ii. In the target turtle, type edit startup.lua.

    iii. Copy each line from the repository startup.lua individually into the computercraft editor.

    iv. Press CTRL/COMMAND and SAVE using the arrow keys and enter.

    v. Press CTRL/COMMAND and EXIT using the arrow keys and enter.

    vi. Reboot the turtle with reboot.

TODO

ComputerCraft

CORE MODULES
  • [✔️] Connect to python websocket
  • [✔️] Preset Actions
  • [✔️] Parse Actions

Python

CORE SYSTEMS
  • [✔️] Websocket Server
  • [✔️] Parse Incoming Server Requests
  • [✔️] Turtle State Persistence Data
  • [✔️] Behavior Tree Framework
  • [🚧] Save Turtle Current Behavior Tree & Cache Values (State Persistence)
  • [🚧] Turtle Behavior Trees
TURTLE BEHAVIOR TREES
  • [🚧] Initializer Tree
  • [❌] Main Loop Tree
  • [❌] Low Fuel Resolver Tree
  • [❌] Mine Resource Tree
  • [❌] Dig Tunnel Tree
  • [❌] Mine Ore Vein Tree
  • [❌] Craft Resource Tree
  • [❌] Farm Sapling Tree
  • [❌] Farm Sugar Cane
  • [❌] Procreate Tree
  • [❌] Stranded Behavior Tree
  • [❌] Help Stranded Behavior Tree
EXTRA SYSTEMS
  • [❌] 3D World Viewer
  • [❌] 3D World Pathfinding
  • [❌] Manual Turtle Controller
  • [❌] HIVE System when turtle count reaches >10 turtles?

✔️❌🚧

When testing you can utilize the following command to view and set the fuel to a specific value.

  • /data modify block [X] [Y] [Z] "Fuel" set value 0
  • /data get block [X] [Y] [Z]

Resources / Credits

99% of the code was done by me, @SPOOKEXE.

I used this particular resource to solve the turtle replication which is linked below; namely in the genesis function.

YouTube Video Thumbnail

Video: https://www.youtube.com/watch?v=MXYZufNQtdQ

Code: https://pastebin.com/YtvRxY9j

Another video resource I used as a 'goal' for the project was to visualize what the turtles see in a 3D space:

YouTube Video Thumbnail

Video: https://www.youtube.com/watch?v=pwKRbsDbxqc

Apart from the first reference for code, I did all the code from the ground up.

Other Documentation

https://www.computercraft.info/forums2/index.php?/topic/24574-optimization-and-micro-optimization/

About

Remake of the 'minecraft-turtle-botnet' that is re-built from the ground up for turtle state persistence and refactoring.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors