Skip to content

How to test

Raluca D. Gaina edited this page Feb 12, 2018 · 2 revisions

This page explains

  • Quick set up with/without an IDE.
  • How to run a sample Python or Java client with / without an IDE.
  • How to run your Python or Java client with / without an IDE.
  • Legal arguments / Advanced setting.
  • Special guidelines for some Windows users.

More Q&A can be found here.

Important!!! Before starting

  • Please read carefully the following guidelines, otherwise it may not work.
  • Please do NOT move the client folder out of the gvgai, otherwise you will need to edit the sh/bat files which will make the work more complicate. Moving the client source code to another directory is possible but not recommended, as the path to the server source code, to the games, to the sprites will need to be changed.
  • NO additional work will be required if you follow the guidelines.
  • NO need to run the server manually. If you launch the Java or Python client following the guidelines, the server will be compiled and run automatically.
  • Windows, osx and unix are supported. The corresponding sh/bat will be run automatically. But if you are really using Windows, wish you good luck...we've observed some isolated problems for some Windows users (some Windows users have not met any problem at all). All observed cases have been presented at the bottom of this page.

Main steps for testing a controller

Step-by-step without IDE (recommended)

Run a Python agent

If you want to run the given sample random Python agent, all you need to do is to

  1. Go to the folder where the oneclickRunFromPythonClient.sh and oneclickRunFromPythonClient.bat locate (should be gvgai/blob/master/clients/GVGAI-PythonClient/src).
  2. Run oneclickRunFromPythonClient.sh or oneclickRunFromPythonClient.bat.

If you want to run your own Python agent:

  1. Make sure that your agent is named as Agent.py and located in a package with same name as your account on GVGAI and located in the source folder. For instance, the sample agent is defined in GVGAI-PythonClient/src/sampleRandom/Agent.py.
  2. Go to the folder where the oneclickRunFromPythonClient.sh and oneclickRunFromPythonClient.bat locate (should be gvgai/clients/GVGAI-PythonClient/src).
  3. In oneclickRunFromPythonClient.sh or oneclickRunFromPythonClient.bat, in the Python run command line, add the option -agentName ${yourAgentPackage}. E.g., python TestLearningClient.py -agentName sampleRandom.Agent.
  4. Run oneclickRunFromPythonClient.sh or oneclickRunFromPythonClient.bat.

Run a Java agent

If you want to run the given sample random Java agent, all you need to do is to

  1. Go to the folder where the oneclickRunFromJavaClient.sh and oneclickRunFromJavaClient.bat locate (should be gvgai/clients/GVGAI-JavaClient/src).
  2. Run oneclickRunFromJavaClient.sh or oneclickRunFromJavaClient.bat.

If you want to run your own Java agent:

  1. Make sure that your agent is named as Agent.java and located in a package with same name as your account on GVGAI and located in the source folder.
  2. Go to the folder where the oneclickRunFromJavaClient.sh and oneclickRunFromJavaClient.bat locate (should be gvgai/blob/master/clients/GVGAI-JavaClient/src).
  3. In oneclickRunFromJavaClient.sh or oneclickRunFromJavaClient.bat, in the Java run command line, add the option -agentName ${yourAgentPackage}. E.g., java -classpath ${build_folder} TestLearningClient -agentName sampleRandom.Agent.
  4. Run oneclickRunFromJavaClient.sh or oneclickRunFromJavaClient.bat.

Step-by-step using IntelliJ

Run a Java agent

  1. Import the project: Launch the IDE, import the project GVGAI-JavaClient. Attention: Please import the client not the gvgai.

  2. Set your own Java agent If you want to use your own agent, you can change the name of agent in TestLearningClient.java. Otherwise, the sample random agent sampleRandom/Agent.java will be used.

  3. Run TestLearningClient.java in gvgai/GVGAI-JavaClient/src/. It will compile the server, build the communication and launch the program. The output of the client will be shown on the console, while the output of the server will be logged in the logs/ folder: output_server_redirect.txt for stdout, output_server_redirect_err.txt for stderr.

Run a Python agent

  1. Import the project: Launch the IDE, import the project GVGAI-PythonClient. Attention: Please import the client not the gvgai.

  2. Set your own Python agent If you want to use your own agent, you can pass the name of agent as a parameter to TestLearningClient.py in gvgai/clients/GVGAI-PythonClient/src. Otherwise, the sample random agent sampleRandom/Agent.py will be used.

  3. Run TestLearningClient.py in gvgai/clients/GVGAI-PythonClient/src. It will compile the client, build the communication and launch the program.


For Eclipse users

If you are using Eclipse, the build folder is not out but bin, you need to edit the runServer_nocompile.sh at gvgai/clients/GVGAI-JavaClient/src/utils or runServer_nocompile_python.sh at gvgai/clients/GVGAI-PythonClient/src/utils.


Advanced settings

Legal arguments

You can pass arguments to your client. The legal ones are listed below:

  • -serverDir [PathToServerCode]: Where the source folder of the server code locates. Default: ..\\..\\.. for Windows system or ../../.. for osx and unix.
  • -shDir [PathToTheScriptToBuildServer]: Where the script to build and run the server locates. Default: utils.
  • -gameId [IdOfGameToPlay]: The id of the game to play. Default: 0.
  • -agentName [NameOfAgentToRun]: The name of your agent, should be the same to the package name and your GVGAI account username. Default: sampleAgents.Agent for Python and agents.random.Agent for Java.
  • [-visuals]: Visualisation of game playing on if this is passed. Otherwise, visualisation off.

If you are running your Java/Python client with an IDE

The above arguments can be passed to the Java or Python main class, otherwise the default values will be used.

If you are running your Java/Python client without an IDE

The -serverDir [PathToServerCode] is NO MORE optional!!! It should always be passed to specify the path to the server code. This is due to the different working paths when running the main class using IDE or running the oneclick*sh/bat files. If you did not move the client code out of the gvgai folder, then the current setting in the scripts should work.

The options can be passed in the sh/bat files as below.

Python client:

In oneclickFromPythonClient.bat or oneclickFromPythonClient.sh

python TestLearningClient.py -serverDir [PathToServerCode] -shDir [PathToTheScriptToBuildServer] -gameId [IdOfGameToPlay] -agentName [NameOfAgentToRun] [-visuals]

Java client:

In oneclickFromJavaClient.sh:

java -classpath ${build_folder} TestLearningClient -serverDir [PathToServerCode] -shDir [PathToTheScriptToBuildServer] -gameId [IdOfGameToPlay] -agentName [NameOfAgentToRun] [-visuals]

In oneclickFromJavaClient.bat:

java -cp %build_folder% TestLearningClient -serverDir [PathToServerCode] -shDir [PathToTheScriptToBuildServer] -gameId [IdOfGameToPlay] -agentName [NameOfAgentToRun] [-visuals]

Choose a game to play

If you have downloaded the framework, then you can specify the game for testing. Note that in the competition, your agent will play on a set of unknown games and you won't be able to choose the game to play. All games for testing can be found in TestSingleLearning.java. You can passing the game to oneclickRunFromJavaClient.sh or oneclickRunFromPythonClient.sh using -gameId 0 for the game with index 0. Same for bat files.

If you want to test with a different learning duration

Please edit the value of CompetitionParameters.TOTAL_LEARNING_TIME.


Possible issues and actions

Got a java.net.BindException: Address already in use (Bind failed)?

Maybe another process is already running at that port. In Unix, check: lsof -i tcp:<port>

If the connection hangs

Please check if the default port 8080 is already being used. If yes, please try another one by editing both SOCKET_PORT in CompetitionParameters.java and SOCKET_PORT in CompetitionParameters.java or in CompetitionParameters.py.

Path to client code

If you move the GVGAI-JavaClient project to another folder, please change the path to the build and source folders in runClient_nocompile.bat or runClient_nocompile.sh. Attention: this will affect the location of the output file ClientLog.txt (see GVGAI-JavaClient/src/utils/IO.java).


Special notes for Windows users

If you failed in the first run, please don't lose your confidence.

FileNotFound exception for logs/ClientLog.txt

Please create manually a folder namely logs. Normally, the logs folder has been created and added to Git.

Path to SDK

You may need to edit gvgai/src/tracks/SingleLearning/runClient_nocompile.bat to specify the path to the sdk.

If you run a Java client and it hangs

  • If you fail with this, please check if the path to javac is set, please refer to javac-isnt-working-in-windows-command-prompt.

  • If after checking the above one, it still hangs, please try to run it using oneclickRunFromPythonClient.sh or oneclickRunFromPythonClient.bat. It has been observed that in Windows 7 (64bits), the oneclickRunFromPythonClient.bat works but under Eclipse it does not work properly.


You may also be interested in:

Create an agent

Single Player Learning Track Specifications

Q&A

Table of Contents:

Clone this wiki locally