Architecture of node design is important part to make your bot flexible and easy scalable for adding new features and cover more scenarios. There are two primary patterns each of them has pros and cons. Let’s dive deeper into it.
Linear Pattern
The most simple and intuitive pattern. Execution flow goes forward from left to right and has logical end in the Exit Success or Exit Error nodes.
Pros: simple, works good for a small logic peace.
Cons: bad for complex logic constructions, can do single task, do nothing else until complete it.
Let’s discuss this linear sequence:
- undock
- jump to asteroid belt
- approach asteroid
- activate mining strip
- wait until asteroid is gone or inventory is full
- dock
Let’s imagine that in the moment of waiting until asteroid is gone or inventory became full emergency situation happens. Let it be neutral in null-sec system. Bot should immediately cancel current sequence and get docked. Intuitively we simple change validation rule from:
- wait until asteroid is gone or inventory is full
- wait until asteroid is gone or inventory is full or neutral is detected
But neutral can appears in any moment. That means it can enter into a system when bot was in a middle of approaching asteroid. Or to the moment of undocking, jumping, etc. That will be tons of duplicated logic at the canvas and spaghetti of nodes. To avoid that, take a look at Recycle Pattern below.
Recycle Pattern
This is scalable pattern. Core principle in this pattern – do not use Exit nodes. That will force execution flow to comeback to the Start node when it stuck in node without forward execution flow connection. This small trick forces execution flow to go over and over again, through all logic parts. That means logic parts will be executed again and again. That is perfect to make continues validation of bunch of rules. In the same time it avoids nodes duplications on a canvas.
Exit node could be used only in specific cases such as need to shutdown bot because game server is going to shutdown.
Good to know
Pros: reusing all logic on canvas, complex logic looks cleaner, works good for anything.
Cons: it needs mind-shift, need to recognize where a bot is now, what it is doing or just did.
Because each time the node executions begins from Start, need to add logic for understanding where is the bot now, in space or docked, has low health or doesn’t… That is needed for executing right actions, if health is low – go dock, if at asteroid belt – lock asteroid, if already locked – activate mining lasers.
- dangerous condition?
- yes: docked?
- yes: wait 10 seconds
- no: dock
- yes: docked?
- at station?
- yes: unload cargo and undock
- no: at asteroid belt?
- yes: is asteroid locked?
- yes: is strip miner active?
- yes: is cargo full?
- yes: dock
- no: —-
- yes: is cargo full?
- no: is close enough to an asteroid?
- yes: lock it
- no: approach
- yes: is strip miner active?
- no: jump to asteroid belt
- yes: is asteroid locked?
This is very flexible way to create bots, any time you can add new branch into the flow with new rules validation without suffering. Of course it is much more complex at first look. But this is solid basement for complex logics.
Ratting bot as an example
- check execution duration
- set variable value to False if execution time is reached, set True if doesn’t
- close annoying dialogs if that appears
- close Neocom if that is opened
- validate “Station Path” input, it has to be valid, in other case bot will not be able to dock in emergency case. So need to avoid even start.
- check if ship is docked
- docked: check execution limit reached
- docked: check server going to shutdown
- docked + execution limit reached OR server is going to shutdown: play voice message and send text message and stop (Exit) the execution
- docked: check user wants to check neutrals
- docked: check neutrals and split the flow into to ways
- docked + neutrals detected: send message, play voice message, await long period of time, because neutrals are detected in system
- docked + no neutrals: repair ship, undock
No sense to describe each single node. That is full view of Ratting bot. It repeats through all the nodes over and over again and doing it very fast. There are a lot of other validations, such as: inventory window open, health status, drones status, locked targets check, neutrals, etc.