Skip to content

Commit

Permalink
commit patch for ServerCom:start()
Browse files Browse the repository at this point in the history
  • Loading branch information
ljialin committed May 23, 2017
1 parent ff3d779 commit bf65e65
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 24 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,13 @@ production/
*.class

*.xml

*.html

*.txt

*.png

*.gif

*.xml
46 changes: 26 additions & 20 deletions src/tracks/singleLearning/ServerComm.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import core.game.SerializableStateObservation;
import core.game.StateObservation;
import ontology.Types;
import tools.ElapsedCpuTimer;

import java.io.*;
import java.util.Random;
Expand Down Expand Up @@ -154,40 +153,47 @@ public boolean start() {
try {
int count = 11;
commSend("START");
String response = commRecv();
String response;

while(response != null)
{
if(response.equals("START_FAILED"))
while(count>0) {
response = commRecv();
if (response==null) {
System.out.println("For tests: null response");
count--;
} else if(response.equalsIgnoreCase("START_FAILED"))
{
System.out.println("START_FAILED");
//Disqualification because of timeout.
return false;
}else if(!response.equalsIgnoreCase("START_DONE") && count>0){
response = commRecv();
count--;

if(count <= 0)
{
//Disqualification before too many things received that are not appropriate.
System.out.println("Start failed: too many unexpected messages received");
return false;
}
}else if(response.equalsIgnoreCase("START_DONE"))
{
} else if (response.equalsIgnoreCase("START_DONE")) {
logger.fine("Received: " + response);

System.out.println("\nStart done");
return true;
} else {
System.out.println("For tests: not START_DONE, not START_FAILED: "+response);
// response = commRecv();
count--;
}
// else if(count <= 0) {
// System.out.println("3");
// //Disqualification before too many things received that are not appropriate.
// System.out.println("Start failed: too many unexpected messages received");
// return false;
// } else {
//
// }

}

int a = 0;

if (count<=0) {
System.out.println("Start failed: too many unexpected messages received");
return false;
}
} catch (IOException e) {
throw new RuntimeException(e);
}


//Disqualification because of exception, communication fail.
System.out.println("Communication failed for unknown reason, could not play any games :-( ");
return false;
Expand Down
5 changes: 2 additions & 3 deletions src/tracks/singleLearning/runClient_nocompile.bat
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
@echo off

set path=%PATH%;C:\Program Files\Java\jdk1.8.0_121\bin
set build_folder=..\..\..\clients\out\production\GVGAI-JavaClient
set gson=gson-2.6.2.jar
set build_folder=..\..\..\client\GVGAI-JavaClient\out
set src=..\..\..\clients\GVGAI-JavaClient\src
set root_path=..\..\..\

rem This script presumes that all the client-related Java files have been previously compiled and put in a folder called "build"

rem Run the JavaClient class
java -agentlib:jdwp=transport=dt_socket,server=y,address=8000,suspend=n -cp src\%build_folder%;%gson% JavaClient
java -agentlib:jdwp=transport=dt_socket,server=y,address=8000,suspend=n -cp %build_folder%;%gson% JavaClient
2 changes: 1 addition & 1 deletion src/tracks/singleLearning/runClient_nocompile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if [ ! -d "$DIRECTORY" ]; then
mkdir $DIRECTORY
fi

build_folder='../../clients/GVGAI-JavaClient/out/'
build_folder='../../../clients/GVGAI-JavaClient/out'
gson='gson-2.6.2.jar'

java -agentlib:jdwp=transport=dt_socket,server=y,address=8000,suspend=n -classpath ${build_folder}:${gson} JavaClient
Expand Down
27 changes: 27 additions & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Eclipse
.classpath
.project
.settings/

# Intellij
.idea/
.idea
*.iml
*.iws

# Mac
.DS_Store

# Maven
log/
target
out/
/bin
/build/classes/
/build/dist/
production/

*.ipr
*.class

*.xml
63 changes: 63 additions & 0 deletions test/doc/SingleLearningTrackInstruction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#Instruction for GVGAI Single-Player Learning track

## Useful links
[GVGAI competition](http://www.gvgai.net/)

[GVGAI framework](https://github.com/EssexUniversityMCTS/gvgai)

[GVGAI single-learning track framework](https://github.com/EssexUniversityMCTS/gvgai), branch *singleLearning2017*

[GVGAI wiki](https://github.com/EssexUniversityMCTS/gvgai/wiki) (planning tracks and level generation track)

**Contact:** Jialin Liu, University of Essex, UK

Email: *jialin.liu@essex.ac.uk* or *jialin.liu.cn@gmail.com*

## Overview
The Single-Player Learning track is based on the GVGAI framework. Different from the planning tracks, no forward model is given to the agent, thus, no simulation of game is possible. It is notable that the agent still has the access to the current game state (objects in the current game state), as in planning tracks.

## Main procedure
For a given game, each agent will have **10 minutes** for training on levels 0,1,2 of the game, the level 3 and 4 will be used for validation.
### Main steps during training
1. Playing once levels 0, 1 and 2 in a sequence: Firstly, the agent plays once levels 0,1,2 sequentially. At the end of each level, whatever the game has terminated normally or the agent forces to terminate the game, the server will send the results of the (possibly unfinished) game to the agent.
2. (Repeat until time up) Level selection: After having finished step 1, the agent is free to select the next level to play (from levels 0, 1 and 2) by calling the method `int result()` (detailed later). If the selected level id $$$\not\in \\{0,1,2\\}$$$, then a random level id $$$\in \\{0,1,2\\}$$$ will be passed and a new game will start. This step is repeated until **10 minutes** has been used.

In case that 10 minutes has been used up, the results and observation of the game will still be sent to the agent and the agent will have no more than **1 second** before the validation.

### Main steps during validation
During the validation, the agent plays once levels 4 and 5 sequentially.

*Remark: Playing each level once or several times is to be decided.*

## Methods to implement and time control
### Constructor of the agent class
public Agent(SerializableStateObservation sso, ElapsedCpuTimer elapsedTimer){...}
The constructor receives two parameters:

* `SerializableStateObservation sso`: The `StateObservation` is the observation of the current state of the game, which can be used in deciding the next action to take by the agent (see [doc for planning track](https://github.com/EssexUniversityMCTS/gvgai/wiki/Creating-Controllers) for detailed information). The `SerializableStateObservation` is the serialised `StateObservation` **without forward model**, which is a `String`.
* `ElapsedCpuTimer elapsedTimer`: The `ElapsedCpuTimer` is a class that allows querying for the remaining CPU time the agent has to return an action. You can query for the number of milliseconds passed since the method was called (`elapsedMillis()`) or the remaining time until the timer runs out (`remainingTimeMillis()`).
The constructor has **1 second**. If `remainingTimeMillis()` ≤ 0, this agent is **disqualified** in the game being played.

### Initialise the agent
public Types.ACTIONS init(SerializableStateObservation sso, ElapsedCpuTimer elapsedTimer){...}
The `init` method is called once after the constructor, before selecting any action to play. It receives two parameters:

* `SerializableStateObservation sso`.
* `ElapsedCpuTimer elapsedTimer`: (see previous section) The `act` has to finish in **40ms**, otherwise, the `NIL_ACTION` will be played.

### Select an action to play
public Types.ACTIONS act(SerializableStateObservation sso, ElapsedCpuTimer elapsedTimer){...}
The `act` method selects an action to play at every game tick. It receives two parameters:

* `SerializableStateObservation sso`.
* `ElapsedCpuTimer elapsedTimer`: The timer with maximal time **40ms** for the whole training. The `act` has to finish in **40 ms**, otherwise, this agent is **disqualified** in the game being played.

### Abort the current game
The agent can abort the current game by returning the action `ACTION_ESCAPE`. The agent will receive the results and state observation `sso` of the unfinished game and returns the next level to play using the method `int result(sso)`.

### Select the next level to play
public int result(SerializableStateObservation sso, ElapsedCpuTimer elapsedTimer) {...}
During the step 2 of training, after terminating a game and receiving the results and final game state, the agent is supposed to select the next level to play. If the return level id $$$\not\in \\{0,1,2\\}$$$, then a random level id $$$\in \\{0,1,2\\}$$$ will be passed and a new game will start. The `result` method receives two parameters:

* `SerializableStateObservation sso`: the serialised observation of final game stat at termination.
* `ElapsedCpuTimer elapsedTimer`: The global timer with maximal time 10 mins for the whole training. If there is no time left (`remainingTimeMillis()` ≤ 0), an extract timer with maximal time=1 second will be passed.
Binary file added test/doc/singlelearningtrackinstruction.pdf
Binary file not shown.
20 changes: 20 additions & 0 deletions test/src/runClient_compile.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@echo off

set path=%PATH%;C:\Program Files\Java\jdk1.8.0_121\bin
set build_folder=build
set gson=gson-2.6.2.jar
set src=..\clients\GVGAI-JavaClient\src
set root_path=..\

rem Find all the .java files and list their paths in a file called 'source_list.txt'
break>source_list.txt
for /f %%i in ('forfiles /p %src% /s /m *.java /c "cmd /c echo @PATH"') do @echo %%~i >> source_list.txt

rem Make a build folder if none exists
if not exist %build_folder% mkdir %build_folder%

rem Build all java files saved in source_list.txt
for /f "tokens=*" %%A in (source_list.txt) do javac -d %build_folder% -cp %src%;%src%\ontology;%root_path%\gson-2.6.2.jar %%A

rem Run the JavaClient class
java -agentlib:jdwp=transport=dt_socket,server=y,address=8000,suspend=n -cp %build_folder%;..\%gson% JavaClient
11 changes: 11 additions & 0 deletions test/src/tracks/singleLearning/runClient_nocompile.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@echo off

set path=%PATH%;C:\Program Files\Java\jdk1.8.0_121\bin
set build_folder=..\..\..\client\GVGAI-JavaClient\out
set src=..\..\..\clients\GVGAI-JavaClient\src
set root_path=..\..\..\

rem This script presumes that all the client-related Java files have been previously compiled and put in a folder called "build"

rem Run the JavaClient class
java -agentlib:jdwp=transport=dt_socket,server=y,address=8000,suspend=n -cp %build_folder%;%gson% JavaClient
14 changes: 14 additions & 0 deletions test/src/tracks/singleLearning/runClient_nocompile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

DIRECTORY=logs
if [ ! -d "$DIRECTORY" ]; then
mkdir $DIRECTORY
fi

build_folder='/Users/jliu/Essex/Github/gvgai/clients/GVGAI-JavaClient/out'
gson='gson-2.6.2.jar'

java -agentlib:jdwp=transport=dt_socket,server=y,address=8000,suspend=n -classpath ${build_folder}:${gson} JavaClient

#Uncomment this line instead for debug only (all printed out will go to output_redirect.txt. SERVER-CLIENT WON'T WORK
#java -agentlib:jdwp=transport=dt_socket,server=y,address=8000,suspend=n -classpath ${build_folder}:${gson} JavaClient > logs/output_redirect.txt

0 comments on commit bf65e65

Please sign in to comment.