Page 1 of 1

Creating Minetest Battle Bots using Blockly

PostPosted: Mon Nov 18, 2013 00:11
by Neuromancer
I just realized that if we are successful in implementing Blockly for Minetest modding, that this would allow players with little to no programming experience to program battle bots that would be able to make offensive and defensive moves, mine resources, craft tools and weapons, build bunkers and fight battles.

Then we could have battles and competitions on servers to see who could program the most powerful battle bots, or spawn armies of these bots to fight wars, build castles, whatever.

PostPosted: Mon Nov 18, 2013 04:33
by hoodedice
Neuromancer wrote:I just realized that if we are successful in implementing Blockly for Minetest modding, that this would allow players with little to no programming experience to program battle bots that would be able to make offensive and defensive moves, mine resources, craft tools and weapons, build bunkers and fight battles.

Then we could have battles and competitions on servers to see who could program the most powerful battle bots, or spawn armies of these bots to fight wars, build castles, whatever.


Cue giant server lag because nooby programmers weren't optimizing their code. OR in the heat of battle and pressure from parents like Neuro (joke) they created bots with over 5000 lines of code. Blocks.

PostPosted: Sat Nov 30, 2013 22:10
by like2omg
hoodedice wrote:Cue giant server lag because nooby programmers weren't optimizing their code. OR in the heat of battle and pressure from parents like Neuro (joke) they created bots with over 5000 lines of code. Blocks.


The way to solve that is by making a custom interpreter so, for example, infinite loops can just error out instead (see Minecraft mod ComputerCraft (shall be called CC from now on)). Telling Lua to execute custom Lua might be hard (I don't know, I'm not a Lua expert... nowhere close) although if set up correctly, allow a certain amount of commands and if it doesn't yield, error out.
That could be accomplished like in CC:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
-- Start a timer that will last n seconds
os.startTimer(n)
-- Wait (non-blocking) for the specific event called "timer"
os.pullEvent("timer")


Another way to accomplish would be to allow only one command per server tick / amount of real time (whichever is larger, or some other factor) per "battle bot" (which still would require a complex setup of a Lua engine)...
If we can have/find C/C++ code to emulate Lua, things should be a bit quicker / more reliable (hopefully).

Notes to consider if implementing it:
  • Keeping track of position in code
  • Keeping track of variable values
  • Handling errors the clean way (sanity checks in "battle bot" lua code to prevent major errors)

.. Sorry if this is going nowhere, as I do know CC is a modification for a Java game (Minecraft) and Java is totally different than a mix of C/C++/Lua. I was just trying to do my best with giving ideas.

P.S. Yes, CC does cause lag on servers in Minecraft which is one of the reasons a lot of servers had that mod banned in (what is now) Tekkit Classic (Minecraft modpack).

PostPosted: Thu Jan 23, 2014 15:52
by HALtheWise
Blockly does have an optional feature that is an "infinite loop counter" that is inserted inside every loop. It is usually used as a hard limit (10,000 loops) before a solution "fails", but it could also be used to throttle the loop to some reasonable speed. Additionally, we could do what CC does, and implement a slight delay with each call to a function. Though anyone writing raw code themselves can, of course, get around these restrictions, they should help with blockly-generated code.

Another possible method is to implement the entire user-supplied code as an onTick(worldState) function that we can simply terminate if it doesn't finish in time.

PostPosted: Thu Jan 23, 2014 16:32
by aldobr
Is anyone now really optimizing mods ?

PostPosted: Thu Jan 23, 2014 17:54
by rubenwardy
Lol.

I do optimize my own, but probably not enough.

PostPosted: Thu Jan 23, 2014 18:02
by hoodedice
aldobr wrote:Is anyone now really optimizing mods ?


They don't, but they should. I might, when I release them