Block Based AI Programming

    alterintel

    moderator
    Joined
    May 24, 2015
    Messages
    869
    Reaction score
    596
    • Likeable
    • Community Content - Bronze 2
    • Legacy Citizen 3
    Block Based AI Programming:

    But why block based programming? Scripting is so much more versatile and gives the player much more control?

    Well I would tend to agree, but after a discussion with Bench I learned that schema is trying to use as little metadata as possible because the amount of space for metadata is finite while the space allowed for blocks is theoretically unlimited. Scripting would be relegated to metadata, and therefore would limit a player to how much scripting would be possible. With this in mind I’ve come up with a way to allow for AI programming that only uses blocks and doesn’t use any metadata at all.

    I believe the current logic system can be expanded and used to program AI functions and behaviors. But in order to do this I would like to add 9 new Logic blocks. Basically there are blocks added to detect Target Range, Mass, Faction, Shields, etc... that can be used in conjunction with existing logic blocks.
    The number of Activated Activator Blocks linked to a Control Block would determine the exact function the Control Block would perform. So for example lets take a Thrust Control Block from below. If you Link 7 Activation Blocks (There are 7 possible functions) to a Thrust Control Block, and 4 of those activation blocks are activated (#4 is Strafe Right). When you activate the Thrust Control Block the ship will strafe right as long as the Thrust Control Block is activated. When you deactivate the Thrust Control Block, then the ship will stop Strafing Right, and begin drifting. Then to bring the ship to a stop, simply deactivate all but one of the linked activation blocks (#1 is All Stop), and then activate the Thrust Control Block again to bring the ship to a stop. Simple right?
    Thrust Control
    1. All Stop: While active will apply the brakes
    2. Forward
    3. Reverse
    4. Strafe Right
    5. Strafe Left
    6. Ascend
    7. Descend
    Rotation Control
    1. All Stop
    2. Roll Clock Wise: while active will roll the ship clockwise
    3. Roll Counter Clock Wise
    4. Yaw Right
    5. Yaw Left
    6. Pitch Up
    7. Pitch Down
    Alignment Control
    1. Center on Target: while active will center the ship to the target.
    2. Center on Galactic North
    Hot-bar Control
    1. Activate Hot-Bar Item #1: while active it’s like pressing the first Hot-bar button.
    2. Activate Hot-Bar Item #2
    3. Etc...
    Target Control
    1. Target Next: when activated it changes your target to the next one.
    2. Target Previous
    3. Target Closest
    4. Target Furthest
    5. Transmit Current Target to Fleet
    6. Target Received Target
    The Transmit and Receive Target functions would allow AI’s to cooperate in battle.

    Target Filter Type
    1. Missile: While active will only target Missiles
    2. Astronaut
    3. Ship
    4. Turret
    5. Docked Entity
    6. Asteroid
    7. Station
    8. Shop
    9. Planet
    10. Planet Part
    Target Filter Faction
    1. Friendly: While Active will only target Friendly
    2. Hostile
    3. Neutral
    4. Own Faction
    Target Filter Systems
    1. Power: While Active will only target power systems within targeted structure.
    2. Power Battery
    3. Engines
    4. Shields
    5. Structure only
    6. Armor
    Target Sensor Block
    1. Target Power: Returns the % of target’s Power remaining
    2. Target Shield: Returns the % of target’s Shields remaining
    3. Target Structure: Returns the % of target’s Structure remaining
    4. Target Armor: Returns the % of target’s Armor remaining
    5. Target Mass: Returns the target’s Mass per 10K
    6. Target Range: Returns the target’s Range per half sector
    The Target Sensor Block should be used in conjunction with the new Sensor block. So take the Target Sensor Block and link it to 6 activation blocks and then turn 2 of them on (#2 is Shields). Now link a Sensor Block to the Target Sensor Block. Now the Sensor Block will return the percentage of your target’s shields. So if your sensor block had 10 activation blocks linked and 3 of them were activated. Then the sensor block would return true if your target’s Shields were above 30% or false if your target’s shields were below 30%.

    The Mass and Range Readings would be special circumstances, and I’m not sure what would be the best way to return values. One idea would be that the Sensor block would go by the number of activated activation blocks linked. So for range: if the sensor block had 3 activated activation blocks linked then it would return true if your target was more than 1.5 sectors away.

    Also there is the concern of how much space these logic blocks will take up once your program is complete. How on earth will it fit in a drone? Well to this I say what about Resource-less, Mass-less, Invisible logic blocks? Or better yet I like Lukwan's idea:
    This sounds like a great way to incorporate CyberSpace into SM. A non-physical reality that is, in this case, housed by a single physical block: AI programming block (or whatever). Within this virtual area you can lay out your block-based programming scheme where the blocks are holographic (exist in another dimension). The AI Cyberspace-block will work perfectly until it takes damage or is destroyed (small explosion?). To prevent abuse there can be block-limits, high power-consumption or catastrophic failure (like ship goes haywire for 30 seconds if block is destroyed).
    When replying in this thread please only respond to the Original Idea of this Post. Please don’t start arguing the merits of script based programming, that is not what this thread is about. What is being discussed is the best way to go about creating a block based method of programming AI drones and ships.

    So…. What do you guys/gals think?
     
    Last edited:
    • Like
    Reactions: Thalanor and JinM
    Joined
    Jun 11, 2016
    Messages
    1,170
    Reaction score
    646
    Block Based AI Programming:


    Target Filter Type
    1. Missile: While active will only target Missiles
    2. Astronaut
    3. Ship
    4. Turret
    5. Docked Entity
    6. Asteroid
    7. Station
    8. Shop
    9. Planet
    10. Planet Part
    Target Filter Faction
    1. Friendly: While Active will only target Friendly
    2. Hostile
    3. Neutral
    4. Own Faction
    Target Filter Systems
    1. Power: While Active will only target power systems within targeted structure.
    2. Power Battery
    3. Engines
    4. Shields
    5. Structure only
    6. Armor
    Target Sensor Block
    1. Target Power: Returns the % of target’s Power remaining
    2. Target Shield: Returns the % of target’s Shields remaining
    3. Target Structure: Returns the % of target’s Structure remaining
    4. Target Armor: Returns the % of target’s Armor remaining
    5. Target Mass: Returns the % of target’s Mass per 10K
    6. Target Range: Returns the % of target’s Range per half sector
    You have no coordinates relative to ship or flagship or enemy. (for this special thing a metadata block could be used)

    Also you need a filter to detect how big and heavy an enemy enitity is. (How to switch between fighters or bigger flagships?)

    A every complicated and advanced idea, might not be fun for the average user but definetively something no other sandbox game will ever have in the comming...2 years? I think compared to other stuff this will be too much to programm compared to other more questioned features with less programming effort. Non the less I would like to see it. I love the idea of giving my ships some orders, and the depth you get from this is insane. Imagine having a bridge where you can give a quarter of your fleet the order to do a backflip (or fire its torpedo after flying to a certain distance near to the enemy carrier).
     
    • Like
    Reactions: alterintel

    alterintel

    moderator
    Joined
    May 24, 2015
    Messages
    869
    Reaction score
    596
    • Likeable
    • Community Content - Bronze 2
    • Legacy Citizen 3
    You have no coordinates relative to ship or flagship or enemy. (for this special thing a metadata block could be used)

    Also you need a filter to detect how big and heavy an enemy enitity is. (How to switch between fighters or bigger flagships?)

    A every complicated and advanced idea, might not be fun for the average user but definetively something no other sandbox game will ever have in the comming...2 years? I think compared to other stuff this will be too much to programm compared to other more questioned features with less programming effort. Non the less I would like to see it. I love the idea of giving my ships some orders, and the depth you get from this is insane. Imagine having a bridge where you can give a quarter of your fleet the order to do a backflip (or fire its torpedo after flying to a certain distance near to the enemy carrier).
    After adding the "Center on Target" function and "Target Sensor Block/Range", and "Target Sensor Block/Mass" I didn't think these functions would be neccessary, but adding another block for Target Bearing wouldn't be out of the question:

    Target Bearing Sensor
    1. Forward: Returns True if the target is forward
    2. Aft
    3. Starboard
    4. Port
    5. Above
    6. Below

    Thanks for the suggestion. :)
     
    Joined
    Feb 25, 2016
    Messages
    1,362
    Reaction score
    268
    I agree---this is too complex, and even from the little of it I read (I skimmed, okay?) it seems like you're making it a lengthy process to.....not really program an AI. You can't use blocks in this way to really give AI decent behaviors. There's always going to be millions of cases that you can't prepare for with this system. Also, it's gonna take up a ton of room for any sort of AI. You can't just throw that into a smaller vessel without losing something, be it combat capability or interior.

    So, on the whole, I'd have to say no. I'm more a fan of giving fleets additional commands and a menu of options for basic responses to threats. As in, if it's a mining fleet, it runs back to base (And preferably to some dockers there) when an enemy is spotted in-system, while combat fleets (With the appropriate settings on, of course) will respond to the threat and attempt to destroy it.
     

    alterintel

    moderator
    Joined
    May 24, 2015
    Messages
    869
    Reaction score
    596
    • Likeable
    • Community Content - Bronze 2
    • Legacy Citizen 3
    I agree---this is too complex, and even from the little of it I read (I skimmed, okay?) it seems like you're making it a lengthy process to.....not really program an AI. You can't use blocks in this way to really give AI decent behaviors. There's always going to be millions of cases that you can't prepare for with this system. Also, it's gonna take up a ton of room for any sort of AI. You can't just throw that into a smaller vessel without losing something, be it combat capability or interior.

    So, on the whole, I'd have to say no. I'm more a fan of giving fleets additional commands and a menu of options for basic responses to threats. As in, if it's a mining fleet, it runs back to base (And preferably to some dockers there) when an enemy is spotted in-system, while combat fleets (With the appropriate settings on, of course) will respond to the threat and attempt to destroy it.
    I to am worried about size of the program in blocks, but I didn't want to include my thoughts in the original post for fear that it was all ready too big. So my thoughts are something along the lines of getting resource free blocks, that are non-collidable and invisible, and mass-less. Not sure the best way of doing that. Maybe treat the program as an invisible docked entity?

    But Yes I totally agree there needs to be some way of getting programming into even the smallest of drones.

    Also as far as complexity... I'm under no illusion that Everybody will be able to program an AI. Even in real life, this is a huge challenge. I suggest that instead, people upload their programs to community content and share them, much like we do with other logic circuits.
     
    Joined
    Feb 25, 2016
    Messages
    1,362
    Reaction score
    268
    Yes, but why lock a potentially very important part of the game behind a wall that not everybody can/wants to get over?

    It's fine to provide the capability to use blocks for advanced programming (And I want to see blocks that can activate fleet commands) that is not necessary to access all the features of AI customizability. The block-based idea you present is OK, but really there needs to be a general-use setup where far fewer blocks are required...like a block that decides (Based on its state) whether this particular ship would rather run away than fight, or what range this ship would like to fight at, etc.
     
    • Like
    Reactions: alterintel

    Ithirahad

    Arana'Aethi
    Joined
    Nov 14, 2013
    Messages
    4,150
    Reaction score
    1,330
    • Purchased!
    • Top Forum Contributor
    • Legacy Citizen 8
    This will indeed take up too much space, and if you use invisible blocks, everyone will ask, "why didn't you just use metadata?"

    I wouldn't mind this general approach, but virtualized and made into a flowchart-like system within a UI.
     
    • Like
    Reactions: alterintel

    alterintel

    moderator
    Joined
    May 24, 2015
    Messages
    869
    Reaction score
    596
    • Likeable
    • Community Content - Bronze 2
    • Legacy Citizen 3
    Yes, but why lock a potentially very important part of the game behind a wall that not everybody can/wants to get over?

    It's fine to provide the capability to use blocks for advanced programming (And I want to see blocks that can activate fleet commands) that is not necessary to access all the features of AI customizability. The block-based idea you present is OK, but really there needs to be a general-use setup where far fewer blocks are required...like a block that decides (Based on its state) whether this particular ship would rather run away than fight, or what range this ship would like to fight at, etc.
    I worry that my in-ability to communicate this idea has made it sound more complicated then it actually is.
    I personally feel that a programming language with only 9 commands is pretty simple, but I also recognize that this may seem too complicated to average gamer. To this I can only iterate that this is probably the simplest "block" based programming you'll probably be able to achieve without menus and flow charts.

    I to agree that meta data would be the way to go. However given the finite space this seems as though it will be limiting as well?
     
    Joined
    Jun 11, 2016
    Messages
    1,170
    Reaction score
    646
    After adding the "Center on Target" function and "Target Sensor Block/Range", and "Target Sensor Block/Mass" I didn't think these functions would be neccessary, but adding another block for Target Bearing wouldn't be out of the question:

    Target Bearing Sensor
    1. Forward: Returns True if the target is forward
    2. Aft
    3. Starboard
    4. Port
    5. Above
    6. Below

    Thanks for the suggestion. :)
    No no sir. I talk about the ability to position your own ships relative to a certain entity, like your mothership, or the enemy mothership.

    So you have your own flagship, and tell you fighters to make a wall at the backbord side, because the flagship wants to fire with its broadside weapons.

    Or you tell your fighters to move 500m in front of your flagship and engage every enemy fighter wanting to pass through to your carrier.

    Thats only possible, if you have a block with metadata. Or a block that has like some sort of range setting from sectorspace(0,0.1,0.25,0.5,1,1,5,2,3). Or you just scratch your idea and think about a better fleet command system that does not need any ship configuration. Even though I am all in for commanding your stuff from your flagship and not from an extra hud. Feels more immersive this way.
     

    Lukwan

    Human
    Joined
    Oct 30, 2015
    Messages
    691
    Reaction score
    254
    So my thoughts are something along the lines of getting resource free blocks, that are non-collidable and invisible, and mass-less. Not sure the best way of doing that. Maybe treat the program as an invisible docked entity?
    This sounds like a great way to incorporate CyberSpace into SM. A non-physical reality that is, in this case, housed by a single physical block: AI programming block (or whatever). Within this virtual area you can lay out your block-based programming scheme where the blocks are holographic (exist in another dimension). The AI Cyberspace-block will work perfectly until it takes damage or is destroyed (small explosion?). To prevent abuse there can be block-limits, high power-consumption or catastrophic failure (like ship goes haywire for 30 seconds if block is destroyed).
     
    • Like
    Reactions: alterintel

    Napther

    Grumpy builder of Kaiju Design Initiative
    Joined
    Feb 7, 2015
    Messages
    192
    Reaction score
    180
    • Competition Winner - Small Fleets
    • Community Content - Bronze 2
    • Legacy Citizen 2
    I think some more basic, non-block based AI elements are better. Such as pressing R on the bobby will increments of sectors as "Close to this range to enemy" and another of "Keep enemies further away than" distance. Also potentially a "Aim at Smallest", "Aim at Average", and "Aim at largest" This will solve most of the issues with dumb AI and targetting, and allow heavy cruisers on AI mode to direct their heavy cannons at enemy cruisers and battleships rather than missing all the time a drone (Anti-drone is fighter and Destroyer's role of killing)
     
    • Like
    Reactions: Lukwan
    Joined
    Sep 18, 2014
    Messages
    621
    Reaction score
    448
    Personnaly i would look at a menu in the bobby, as said above, with theses kind of things :
    - target range
    - target type (astronauts, missiles and so on)
    - time between checks for another available target

    Can add a few things like the prefered mass you want to target.
     
    Joined
    Jan 25, 2015
    Messages
    964
    Reaction score
    225
    • Wired for Logic
    • Councillor 2 Gold
    • Legacy Citizen 5
    I actually brought this idea up at the last council/dev meeting (about 2/3 weeks ago) because block based programming is the simplest programming without actually it being programming. Most of the devs responded positively to the concept. This is me trying to be honest without making promises. There is no guaranteen about if something

    I worry that my in-ability to communicate this idea has made it sound more complicated then it actually is.
    I personally feel that a programming language with only 9 commands is pretty simple, but I also recognize that this may seem too complicated to average gamer. To this I can only iterate that this is probably the simplest "block" based programming you'll probably be able to achieve without menus and flow charts.

    I to agree that meta data would be the way to go. However given the finite space this seems as though it will be limiting as well?
    I have had that problem for 2 weeks now, whenever I try to explain something I just make it even more difficult.
     
    • Like
    Reactions: alterintel
    Joined
    Aug 23, 2016
    Messages
    758
    Reaction score
    129
    If programming is required to be competitive (or using other people's programming) against superior custom AI you're going to marginalise a lot of players who can't program (I'm not one of these people) or don't want to program in Starmade (I am one of these people).

    I want ship design (and pilot skill) to be the difference between winning and losing, not programming.

    I'd prefer a few settings in each Bobby block, or even simpler, a small selection of pre-made Bobby blocks for different roles/ship sizes.
     

    alterintel

    moderator
    Joined
    May 24, 2015
    Messages
    869
    Reaction score
    596
    • Likeable
    • Community Content - Bronze 2
    • Legacy Citizen 3
    Honestly, I would be surprised if the Bobby AI didn't get an overhaul in it's menu based programming, with more features and commands. In fact if they don't do this it would be a real shame, as there clearly seems to be a theme here.
    There's always going to be millions of cases that you can't prepare for with this system.
    I totally agree with the quote, however I think this quote is better applied to the "R" UI Menu of the Bobby AI block, that the masses seem to think will be better.

    I just hope that my in-ability to effectively communicate this idea hasn't made it too complicated, when in reality, this idea is really quite simple and elegant. Oh-well.
     

    Thalanor

    CEO Snataris Colonial Fleetyards
    Joined
    Sep 10, 2013
    Messages
    818
    Reaction score
    708
    • Master Builder Bronze
    • Thinking Positive
    • Legacy Citizen 3
    The proposal is in fact no more complex than other things starmade already has - like rail rotors and the like - and it would add a whole dimension of depth that is still optional, since a ship could have a "default" AI if no AI blocks are present on the entity, and for those who want to dive in deeper, a few simple blocks would be all the tools they need to go nuts. Emergent complexity, starmade is good at it - and this would make it a bit better at that even.
     
    • Like
    Reactions: alterintel
    Joined
    Jan 25, 2015
    Messages
    964
    Reaction score
    225
    • Wired for Logic
    • Councillor 2 Gold
    • Legacy Citizen 5
    If programming is required to be competitive (or using other people's programming) against superior custom AI you're going to marginalise a lot of players who can't program (I'm not one of these people) or don't want to program in Starmade (I am one of these people).

    I want ship design (and pilot skill) to be the difference between winning and losing, not programming.

    I'd prefer a few settings in each Bobby block, or even simpler, a small selection of pre-made Bobby blocks for different roles/ship sizes.
    The proposal is in fact no more complex than other things starmade already has - like rail rotors and the like - and it would add a whole dimension of depth that is still optional, since a ship could have a "default" AI if no AI blocks are present on the entity, and for those who want to dive in deeper, a few simple blocks would be all the tools they need to go nuts. Emergent complexity, starmade is good at it - and this would make it a bit better at that even.
    This is one of the reasons it was received positively. Programming requires a whole new chapter of knowledge. Block based AI would function similar to normal logic gates, if it was indeed semi-physical block based.
    If you want an example of block based AI in a menu:
    A simplistic version: Or a more advanced version that comes closer to real programming: Snap! (Build Your Own Blocks) 4.0 or Scratch Project Editor - Imagine, Program, Share
     
    • Like
    Reactions: alterintel

    alterintel

    moderator
    Joined
    May 24, 2015
    Messages
    869
    Reaction score
    596
    • Likeable
    • Community Content - Bronze 2
    • Legacy Citizen 3
    This is one of the reasons it was received positively. Programming requires a whole new chapter of knowledge. Block based AI would function similar to normal logic gates, if it was indeed semi-physical block based.
    If you want an example of block based AI in a menu:
    A simplistic version:
    Actually it's probably not a bad idea to have a GUI for block based programming, to make it easier to make the right links and so forth. But in the end, and behind the scenes the program could be stored as logic blocks that can still be manually configured if you wanted.
     

    Raisinbat

    Raging Troll
    Joined
    Dec 29, 2014
    Messages
    459
    Reaction score
    269
    If programming is required to be competitive (or using other people's programming) against superior custom AI you're going to marginalise a lot of players who can't program (I'm not one of these people) or don't want to program in Starmade (I am one of these people).

    I want ship design (and pilot skill) to be the difference between winning and losing, not programming.

    I'd prefer a few settings in each Bobby block, or even simpler, a small selection of pre-made Bobby blocks for different roles/ship sizes.
    I think basic ai stuff, like priority targetting and moving closer/retreating should be kept simple and not require any complicated nonsense, but things like carrier AI kind of requires some more advanced behaviors to make fighters viable.

    I had a similar idea to this but its not quite as complex; let me do a quick writeup:

    • Each entity can have multiple AI blocks.
    • Each AI blocks has a target field a destination field; the target field references an entity and the destination field targets a position in space
    • Each entity has its own target and destination fields; when the AI block is activated by logic, like a button, it will set the ship's target and destination to its own (If it doesn't have any nothing is transmitted). Having multiple AI blocks lets you set the ship to different targets and or positions.
    The "programming" comes in assigning ships and locations to the ai. I was thinking we could do something that's effectively like logic blocks but instead of a binary signal you're settting up a database querry. For the simplest setup you would need 2 basic blocks:

    • Select all in range (This returns a LIST of entities, so it can't be linked to the ai block directly)
    • Select random (Randomly selects a single entity from a LIST of entities)
    So you link it up like this :



    Meaning you slave the select random to the ai block, then slave the [select all] to the [select random] to form the query. You can slave any block that has "IN X" to any block with "OUT X". When you activate the ai block with logic it runs the query. The select all in range just refers to every entity in the navigation menu; this would probably end up targeting asteroids and allies so its not quite there. Maybe have select all as select all enemy or select all asteroids for mining vessels.

    I think one of the important parts to this is how simulation heavy the ai "scripting" ends up being; you can't have something that's scanning targets every single frame for every single ship and turret, that would be insane.

    For prioritizing targets you could do something like this:



    With more accurate selection lists like select highest/lowest and blocks for referencing what the highest/lowest thing is; like mass, distance and velocity (It's ultimately less blocks than having Select lowest mass, highest mass, lowest velocity etc and more easily expandable, like highest power capacity, cargo capacity, shield hp etc).

    I'm not sure how you would do something like select mass over X. Maybe a text block where you input the exact number, but idk.

    As for switching between targets it would work like this:



    SO this would select the closest missile as its target. If there were no missiles it would instead target a random enemy. (Same as 1. example) You activate the AI module and it selects the random target. If the list with missiles is empty, the empty list logic block becomes active and sends a logic signal to the other ai module, which selects a random non-missile target instead. Add a clock activating the first to re-target missiles.

    As for positioning, you'd have different maneuvers for ships like orbit, follow etc.

    1. example with positioning:



    Maybe position is the wrong word for it, its just assigning the ship some movement pattern, but hopefully you get what i mean. You use the same entity block to assign the target and the position so the ship orbits the ship it's targetting. If you have a friendly ship you can use the friendly ship as target and they'll act like defense drones orbiting that ship instead. (eg: adding a SELF block to refer to itself as an entity. Orbit self may be a problem, or just funny?) Can also have the ship follow an allied leader when there are no ships in range.

    Wireless interaction

    I think the current wireless blocks should work fine with the system; slave an entity block to wireless and transmit over it to another block that also takes entity. May cause problems with multiple input blocks, like a block that removes an entity from a list can take an entity and a list, but that's up to ship maker to fuck up.

    But yeah this is just a rough idea, and i'm not a programmer so who even knows if it works. Let me know if something makes no sense and i'll try to explain or we can declare idea terrible.


    There's obviously a lot of holes here, but i think this could be used as a fairly accessible way to do ai in starmade; it only takes a couple of blocks to make basic ai stuff and if you use the block texture to indicate what input and output types the blocks have it should be pretty intuitive to use as well.
     

    alterintel

    moderator
    Joined
    May 24, 2015
    Messages
    869
    Reaction score
    596
    • Likeable
    • Community Content - Bronze 2
    • Legacy Citizen 3
    In light of schema and Bench asking for suggestions on AI programming I thought I'd bump this thread.
    I think it would be easy to implement. But I would love to see these programming blocks in a virtual environment like Lukwan said in his post above:
    This sounds like a great way to incorporate CyberSpace into SM. A non-physical reality that is, in this case, housed by a single physical block: AI programming block (or whatever). Within this virtual area you can lay out your block-based programming scheme where the blocks are holographic (exist in another dimension). The AI Cyberspace-block will work perfectly until it takes damage or is destroyed (small explosion?). To prevent abuse there can be block-limits, high power-consumption or catastrophic failure (like ship goes haywire for 30 seconds if block is destroyed).