Remote agent

From Rosetta Code
Revision as of 07:44, 14 February 2010 by MikeMol (talk | contribs) (Something I'm working on.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

I'm working on a set of three tasks revolving around the concept of a 'remote agent.' The overarching theme of the task set is to have a simple, stateful world with an agent that operates on the world's state until the end conditions are met. The world is a grid of colored squares, and is populated to some percentage by colored balls. The ending condition is when all balls are in a square of the correct color. The perspective of the agent is limited; it is not given an overview of the world. It only knows its surroundings by responses to its actions. --Michael Mol 07:44, 14 February 2010 (UTC)

Each of the three tasks satisfies a different goal:

  1. Implement the world simulation, accept and respond to agent commands via a stream interface.
  2. Implement the agent side of the stream interface in a manner idiomatic to the language.
  3. Use the agent stream interface to satisfy the end conditions.

Here is a description of the world and commands. I haven't defined the stream protocol yet, but it should be common among all implementations; any agent interface implementation should work equally well with any of the world simulation implementations.

A description of the world

Physics

  • time is quantized. There is only a turn count. No time elapses if no commands are received.
  • distance is quantized on a grid of squares. No coordinate data is provided. Any adjustment in location takes one unit time per unit distance.
  • Orientation is quantized, with four units making a complete rotation. (i.e. each unit is 90 degrees.) adjustments occur at one-unit intervals; two turns in the same direction result in a reversal of bearing with two turns spent, four turns in the same direction result in no ultimate change in bearing, though with four turns spent.
  • A sector may posess no more than one ball at a time. (A ball posessed by an agent in the sector does not count.)
  • An agent may posess no more than one ball at a time.

Grid sectors

Each grid sector has one of the following type properties:

  • Space - an agent may exist here, and may move in and out without impedance.
  • Wall - an agent will not exist here. Any attempt to move into this sector will fail, and a "bump" event will be triggered.

Sector color

Each 'space' grid sector has one of the following color properties (no 'wall' sector may have these properties):

  • Red
  • Green
  • Yellow
  • Blue

Ball color

Each 'space' grid sector may have one and only one of the following properties (no 'wall' sector may have these properties):

  • Red ball
  • Green ball
  • Yellow ball
  • Blue ball

Map generation

  • The grid is always bounded. The outermost rim of sectors must have the 'wall' property.
  • While the distribution and location of the color properties is undefined, there must not be more balls of a color than there are sectors with that color property.
  • There must be at least one 'space' sector without a ball in it. (The agent does not initialize while holding a ball.)

Goal

  • The game ends when the agent holds no ball, and there are no balls in a sector whose color property does not match that of the ball.

Agent activity rules

Movement

  • With the exception of attempting to move from a 'space' sector to a 'wall' sector, which is denied, nothing impedes movement.
  • Movement always occurs at one unit distance per unit time.

Ball manipulation

  • An agent may hold one and only one ball at a time.
  • An agent may only drop a ball if it has one.
  • An agent may only drop a ball while in a sector that does not have a ball in it. The ball the agent held is transferred to that sector.
  • An agent may only pick up a ball while in a sector that has a ball in it. The ball that was in that sector is transferred to being held by the agent.

Agent interface

Commands

ahead

  • Moves ahead one space. Costs one turn if successful.
  • Will respond with a 'color' event indicating the color property of the now-current sector.
  • Will respond with a 'ball' event if there is a ball in the now-current sector.
  • Will be responded to with 'bump' event if unsuccessful, with no turn spent, meaning there is a 'wall' sector "ahead".
  • Will respond with a 'stop' event, once all other events have been sent.

clockwise

  • Orients the agent one unit clockwise, costing one turn. (Recall that four units make a full rotation.)
  • Will respond with a 'stop' event, once all other events have been sent.

counterclockwise

  • Orients the agent one unit counterclockwise, costing one turn. (Recall that four units make a full rotation.)
  • Will respond with a 'stop' event, once all other events have been sent.

get

  • Transfers the ball in the current sector to the agent, if successful. Costs one turn, regardless of success.
  • Will respond with a 'no ball in sector' event, if there is no ball in the sector.
  • Will respond with a 'agent full' event, if the agent already has a ball.
  • Will respond with a 'stop' event, once all other events have been met.

drop

  • Transfers the ball in the agent to the current sector, if successful. Cost one turn, regardless of success.
  • Will respond with a 'no ball in agent' event, if the agent has no ball.
  • Will respond with a 'sector full' event, if the sector already has a ball.
  • Will respond with a 'stop' event, once all other events have been met.

Events

game over

  • Sent when the winning condition has been reached.

stop

  • Sent when all other events for the current command have been sent.

color

  • When sent, indicates the color of the current sector.

ball

  • When sent, indicates the color of the ball in the current sector.

bump

  • When sent, indicates the ahead command failed due to obstruction, no turn spent.

'no ball in sector'

  • When sent, indicates that there is no ball in the current sector, and that a 'get' command failed.

'no ball in agent'

  • When sent, indicates that there is no ball in the agent, and that a 'drop' command failed.

'sector full'

  • When sent, indicates that the sector already has a ball, and that a 'drop' command failed.

'agent full'

  • When sent, indicates that the agent already has a ball, and that a 'get' command failed.