eishub / eis

The Environment Interface Standard (EIS) is a Java-based interface standard for connecting agents to controllable entities in an environment such as a game. The interface provides support for managing the connection (e.g., for pausing and terminating an environment) and for interaction between agents and entities that are available in an environment (e.g., bots in a game). An agent that is connected to a controllable entity receives percepts from and can send actions to that entity. Percepts inform the agent about the state of the entity and its environment. Actions tell the entity which actions to perform in its environment. Several example implementations of environments are available @github.com/eishub. A default implementation of the EIS interface is also provided.
GNU General Public License v3.0
9 stars 4 forks source link

eis2java supporting percepts with multiple arguments #17

Closed Wouter1 closed 10 years ago

Wouter1 commented 10 years ago

EIS2java does not support returning percepts like on(a,b) - 2 arguments of the 'on'. You need to make a custom translator for it.

It would be nice if such multiple arguments were supported out of the box since it is commonly needed, probably more often than the built-in supported list.

Wouter1 commented 10 years ago

Rien replied

Mocht het nog nuttig zijn. De relevante code:

https://mmi.tudelft.nl/svn/goal/UnrealEnvironment/v3/UT2004Environment/src/main/java/nl/tudelft/goal/ut2004/messages/Percept.java https://mmi.tudelft.nl/svn/goal/UnrealEnvironment/v3/UT2004Environment/src/main/java/nl/tudelft/goal/ut2004/translators/PerceptTranslator.java https://mmi.tudelft.nl/svn/goal/UnrealEnvironment/v3/UT2004Environment/src/main/java/nl/tudelft/goal/ut2004/messages/None.java https://mmi.tudelft.nl/svn/goal/UnrealEnvironment/v3/UT2004Environment/src/main/java/nl/tudelft/goal/ut2004/translators/NoneTranslator.java

Deze code kan nog wel wat verbeterd worden.


Rede om te gebruiken:

Er zijn heel veel percepten die het formaat hebben:

perceptNaam(Object1, Object2, Object3)

Dus een percept dat bestaat uit drie java objecten die vertaald moeten worden naar Prolog. De simpele oplossing hier voor is om een nieuw PerceptNaamObject maken met variabelen voor deze drie Objecten. Dus in de code schrijf je dan:

class Orientation {

public final Location location; public final Rotation rotation; public final Velocity velocity;

public Orientation (Location location, Rotation rotation, Velocity velocity){

this.location = location; this.rotation= rotation; this.rotation= rotation; }

@AsPercept(name = "orientation", filter = Type.ON_CHANGE) public Orientation orientation() { return new Orientation (info.getLocation(), info.getRotation(), info.getVelocity()); }

Vervolgens maak je een PerceptNaamObjectTranslator die alle objecten vertaald door alle argumenten te vertalen.

class OrientationTranslator { //Translate code here. }

In het UT Environment is dit bij elk percept (21 in totaal) het geval. Dit betekend dus 21x een classe maken die alle variabelen vast houd en 21x een Translator schrijven die alle velden vertaald. Dit is 21x het zelfde trucje en kan ook generiek opgelost worden door een object te hebben waar van alle argumenten in de constructor worden vertaald. Dit reduceert het schrijven tot:

@AsPercept(name = "orientation", filter = Type.ON_CHANGE) public Percept orientation() { return new Percept(info.getLocation(), info.getRotation(), info.getVelocity()); }

Bij komend voordeel, het leest ook nog eens lekker weg.

Wouter1 commented 10 years ago

Discussed with Koen.

We introduce a new "multipleArguments" parameter for the @AsPercept tag.

If set, a list at 'top level' is not translated to a ParameterList but the elements are all put as parameters of the Function.

If both multiplePercepts and multipleArguments is turned on, the multiplePercepts has priority: the elements of the top level list that you return from EIS2Java is then split first into an argument for each percept. Then each of this arguments is handled according to the multipleArguments setting.

Wouter1 commented 10 years ago

Added test functions for the proposed new multipleArguments parameter.

I have some problems with the error report. All I see in the maven output is

{{{ Running eis.eis2java.handlers.AllPerceptPerceptHandlerTest Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.08 sec <<< FAILURE! Running eis.eis2java.handlers.DefaultActionHandlerTest Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.005 sec Running eis.eis2java.handlers.DefaultPerceptHandlerTest Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.009 sec <<< FAILURE! }}}

and {{{ [ERROR] Please refer to /Volumes/documents/EclipseWorkspaces/apleis0.3/target/surefire-reports for the individual test results. }}}

Now if I look in that I see {{{ Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.08 sec <<< FAILURE! testGetAllPercepts(eis.eis2java.handlers.AllPerceptPerceptHandlerTest) Time elapsed: 0.03 sec <<< FAILURE! java.lang.AssertionError: at org.junit.Assert.fail(Assert.java:91) at org.junit.Assert.assertTrue(Assert.java:43) at org.junit.Assert.assertTrue(Assert.java:54) at eis.eis2java.handlers.PerceptHandlerTest.testGetAllPercepts(PerceptHandlerTest.java:57) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ..... }}} Which is not informative.

I guess it's because assertTrue is being used.

Wouter1 commented 10 years ago

Feature has been added. use multipleArguments=true in the annotation and pass a list of arguments from @AsPercept.