Remote agent/Agent interface: Difference between revisions
m
→{{header|Wren}}: Changed to Wren S/H
(Added Wren) |
m (→{{header|Wren}}: Changed to Wren S/H) |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 12:
=={{header|Go}}==
<
// Streamer interface type defines how agent and world talk to each other.
Line 49:
EvNoBallInSector = 's'
EvNoBallInAgent = 'a'
)</
Above is the interface package defining the abstract interface. Below is an example of a driver program that supplies a concrete implementation of the interface. This implementation uses Go channels to run a simulation in a single process. A different implementation might produce two executables that would run on different processes or different machines. It would use the same interface however.
<
import (
Line 99:
// point. The program terminates immediately when World returns.
world.World(chanStreamer{"world", cmd, ev})
}</
A separate file, but still part of the driver, contains human readable text for commands and events. Alternatively, this file could be included with the interface package for maintainability, but technically it is not a required part of the abstract interface used by the agent and world simulator.
<
import "ra/ifc"
Line 127:
ifc.EvNoBallInSector: "event no ball in sector",
ifc.EvNoBallInAgent: "event no ball in agent",
}</
Line 136:
=== abstract interface ===
Modify this to include one of the two concrete implementations below (but not both!)
<!--<
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\Remote_Agent_Interface.exw
Line 227:
-- in a suitable format for use as per fn() in show() above.
--</span>
<!--</
=== Interface_Direct ===
This implementation of the above interface is a single standalone program
<!--<
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\Remote_Agent_Interface_Direct.e
Line 281:
<span style="color: #008080;">if</span> <span style="color: #000000;">accept_command</span><span style="color: #0000FF;">!=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span> <span style="color: #000000;">main_event_loop</span><span style="color: #0000FF;">()</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<!--</
=== Interface_IPC ===
This implementation of the above interface lets two separate programs communicate using ipc
<!--<
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\Remote_Agent_Interface_IPC.e
Line 396:
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<!--</
=={{header|PicoLisp}}==
Line 403:
=={{header|Tcl}}==
{{works with|Tcl|8.6}}
<
oo::class create AgentAPI {
Line 526:
# Export as package
package provide RC::RemoteAgent 1</
=={{header|Wren}}==
{{trans|Go}}
{{libheader|Wren-
Unlike the Go entry, I've placed the 'human readable text' code inside the 'ifc' module and have also placed a basic logging facility in there too as its called by both the 'world' and 'agent' modules. It always prints to stdout.
I've changed the 'handshake' symbol from "A" to "H" to distinguish it from 'evAgentFull'.
The 'driver code' has been moved to the [[Remote_agent/Simulation]] task.
<syntaxhighlight lang="wren">/* ifc.wren */
import "./fmt" for Fmt
// The Streamer abstract class defines how agent and world talk to each other.
// If implemented in Wren, send and rec will be synchronous blocking operations.
class Streamer {
send(ch) {}
}
// The agent and world send and receive single characters, out of the set of
// constants defined here.
class Ifc {
static handshake { "H" }
static cmdForward
static cmdRight
static cmdLeft
static cmdGet
static cmdDrop
static evGameOver
static evStop
static evColorRed { "R" }
static evColorGreen { "G" }
static evColorYellow { "Y" }
static evColorBlue { "B" }
static evBallRed { "r" }
static evBallGreen { "g" }
static evBallYellow { "y" }
static evBallBlue { "b" }
static evBump { "|" }
static evSectorFull { "S" }
static evAgentFull { "A" }
static evNoBallInSector { "s" }
static evNoBallInAgent { "a" }
// Human readable text for the above commands and events.
static init_() {
__hrText = {
handshake : "handshake",
cmdForward : "command forward",
cmdRight : "command turn right",
cmdLeft : "command turn left",
cmdGet : "command get",
cmdDrop : "command drop",
evGameOver : "event game over",
evStop : "event stop",
evColorRed : "event color red",
evColorGreen : "event color green",
evColorYellow : "event color yellow",
evColorBlue : "event color blue",
evBallRed : "event ball red",
evBallGreen : "event ball green",
evBallYellow : "event ball yellow",
evBallBlue : "event ball blue",
evBump : "event bump",
evSectorFull : "event sector full",
evAgentFull : "event agent full",
evNoBallInSector : "event no ball in sector",
evNoBallInAgent : "event no ball in agent"
}
}
static text { __hrText }
}
class Log {
static prefix=(p) { __prefix = Fmt.swrite("$06d: ", p) }
static print(s) { System.print(__prefix + s) }
static fatal(s) { Fiber.abort(s) }
}
Ifc.init_()</syntaxhighlight>
|