robotopia-x / todo

:warning: DEPRECATED - projects will be now tracked on organization level
https://github.com/orgs/robotopia-x/projects/2
The Unlicense
1 stars 0 forks source link

Add subroutines for bot programms #14

Closed paulsonnentag closed 7 years ago

paulsonnentag commented 7 years ago

How esper.js works

I just looked at the feautures which seemed usefull for my problem. Here is my basic understanding of how esper.js works:

Current implementation

An simple robot program could look like this:


robot.onMarker = function (marker) {
  // do something with marker
}

while (true) {
  robot.move('FORWARD')
  robot.move('FORWARD')
  robot.move('FORWARD')
  robot.move('FORWARD')
  robot.rotate('LEFT')
}

If this program is executed an esper engine is created which runs the code. When an event is triggered a fork of the engine is created which has just the call to the event handler as a code. The robot runtime switches then to the forked engine and executes it until it terminates. Then the robot runtime returns to the main engine.

const subEngine = engine.fork()

subEngine.load('robot.onMarker({x: 0, y: 6})')

...

I've changed the api a little bit so its more friendly if you write it by hand.

TODO

Original idea

Main routine and event routine are stored separately with each of them running in their own esper.js interpreter. If an event is triggered the robot runtime switches to esper runtime of the event and executes it until it terminates. Then it switches back to the main runtime

Disadvantages:

Open for discussion:

paulsonnentag commented 7 years ago

In my opinion we should discard any events if the bot program has already received an event or is currently executing an event routine

timgrossmann commented 7 years ago

In my opinion we should discard any events if the bot program has already received an event or is currently executing an event routine

I think this would be the best approach, too...
Another idea is, that events get a priority which determines how important they are.
I'm thinking about a case where a marker for "resources" is dropped and after that one of "help me fight" is dropped.

perguth commented 7 years ago

I could imagine such a case (ignoring technical probs of the issue for now):

// code: go find ressources!
game.on('ressourceFound', e => {
  // code: mine and bring home!
})
game.on('enemyDiscovered', e => {
  // since we want to run away, we ignore `ressourceFound` events:
  game.removeListener('ressourceFound') 
  // since we're running away, we're now looking for allies:
  game.on('allyDiscovered', e => {
    // code: group!
  })
  // code: run!
})

(Along the lines of Node EventEmitters)

H3rby7 commented 7 years ago

I was also thinking about this issue. My Idea would be to have the robot/unit "know" its current subroutine. When a new event occurs the programmer has access to that information and can decide himself in the event handling how he wants to continue. In your example @timgrossmann

Unit State

Inside Event: event.ENEMY_DETECTED

if (unit.getCurrentOrder() === action.GATHER_RESSOURCES) {
  unit.issueOrder(action.FLEE)
}

This way we pass the problem and soultion and power to the programmer. He could also not check for the event and always take the newest event, or check if an order is present and just continue. As he pleases.

H3rby7 commented 7 years ago

Addressing the multiple Actions event I would suggest to have a list of events that happened in the entity as suggested here in the Object>Unit section. There is an example there.
Again this empowers the coder to chose which event to handle.