Bug Running run_match.py in Powershell

Hello all,

I’ve been having an issue when trying to run run_match.py in powershell. I found a similar issue held by a different user, but there was no real solution to the problem. I have downloaded the most up-to-date version of the C1GamesStarterKit-master. With a completely fresh install of of the starter kit I get hit with this error

0 P1 {“p2Units”:[[],[],[],[],[],[],[]],“turnInfo”:[0,0,-1],“p1Stats”:[30.0,25.0,5.0,0],“p1Units”:[[],[],[],[],[],[],[]],“p2Stats”:[30.0,25.0,5.0,0],“events”:{“selfDestruct”:[],“breach”:[],“damage”:[],“shield”:[],“move”:[],“spawn”:[],“death”:[],“attack”:[],“melee”:[]}} Invalid command, couldn’t json for player 0 : {“p2Units”:[[],[],[],[],[],[],[]],“turnInfo”:[0,0,-1],“p1Stats”:[30.0,25.0,5.0,0],“p1Units”:[[],[],[],[],[],[],[]],“p2Stats”:[30.0,25.0,5.0,0],“events”:{“selfDestruct”:[],“breach”:[],“damage”:[],“shield”:[],“move”:[],“spawn”:[],“death”:[],“attack”:[],“melee”:[]}} com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path at com.google.gson.Gson.fromJson(Gson.java:899) at com.google.gson.Gson.fromJson(Gson.java:852) at com.google.gson.Gson.fromJson(Gson.java:801) at com.c1games.terminal.game.Parser.processInputForPlayer(Parser.java:178) at com.c1games.terminal.game.Parser.processInputDeploy(Parser.java:354) at com.c1games.terminal.game.GameMain.runLoop(GameMain.java:341) at com.c1games.terminal.game.GameMain.startGame(GameMain.java:197) at com.c1games.terminal.game.GameMain.main(GameMain.java:169) at com.c1games.terminal.Terminal.main(Terminal.java:104) Caused by: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path
at com.google.gson.stream.JsonReader.beginArray(JsonReader.java:350)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:80)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:61)
at com.google.gson.Gson.fromJson(Gson.java:887)
… 8 more

I apologize in advance for the garbled chunk of error. I am running Windows 64-bit, i have java 11.0.1 installed, I changed my powershell script resriction to unrestricted. I am not sure what there is left to try.

I upgraded to Java 11.0.1 recently which gave me similar error, try rolling back to 10.0.2, that worked for me.

I rolled back, and I am still getting the error.

In cmd run “java -version”, what does it say?

java -version:
java version “10.0.2” 2018-07-17
Java™ SE Runtime Environment 18.3 (build 10.0.2+13)
Java HotSpot™ 64-Bit Server VM 18.3 (build 10.0.2+13, mixed mode)

javac -version:
javac 10.0.2

Ok, looks good, hmmm

Prior to upgrading to 11.0.1, I had SE 8u191 which gave me a compatibility error because the engine was compiled in 10.0.2 I believe. So I updated, and no longer had the compatibility error, but now have this.

I remember that I had the same error. What I do not remember clearly is what exactly helped me. Two things I do remember were:

  1. Fresh download of master
  2. Following guidelines and doing exactly as they are written
    Let me try to find that old post from forum.

I had missing replay files at the time and never bothered to create a post about issue with “BEGIN_ARRAY but was BEGIN_OBJECT”.

For me it was not reading the guidelines carefully enough.
Not sure in your exact case though.

I believe that I followed the instructions exactly as written and I am still getting the error. I tried running run_match.py and run_match.ps1 (from the parent folder), but it is the same error every time.

I experienced problems running the game in powershell as well when I upgraded to java 11. Rather than actually solve the problem, I found a workaround that worked for me.

I installed launch4j, which is a program that wraps .jar files into .exe files (or whatever for your os version).

After downloading the program, launch the application which will open a small window. Set the Output file: to be the exact same as the Jar path but make the ending .exe. Then under the Header tab change the Header type to be Console instead of GUI.

Under the JRE tab you will need to set the Min JRE version. This is what will give the error above if you don’t have the most up to date version. I set mine to just be 1.1.0 even though it obviously requires version 10 as C1 specifies, as long as you have v10 or v11 installed it will work. Then also set Max heap size to be whatever you want. This is the maximum amount of memory the .exe will be allowed to use. You can set it to be whatever you want, but the default for java is 64mb. Don’t set it too small or else the program won’t be able to run.

Here is a list of all parameters you’d need to change:
Basic tab:

  • Output file: path to output - set this to the same location as the engine.jar file
  • Jar file: path to engine.jar

Header tab:

  • Header type: must be changed to Console or else won’t work

JRE tab:

  • Min JRE version - must be set to something to work, I did 1.1.0
  • Max Heap size - an amount of max memory to be used

Once these settings have been set you can just click the little gear at the top of the window, save the config file as a .xml file and it will automatically create the .exe file.

The last step you will need to do is tell the C1StarterKit to use the .exe instead of the .jar.
Inside the …\C1GamesStarterKit\scripts\run_match.py change the following:

run_single_game("cd {} && java -jar engine.jar work {} {}".format(parent_dir, algo1, algo2))

to be

run_single_game("cd {} && engine.exe work {} {}".format(parent_dir, algo1, algo2))

This worked for me, let me know if you have any questions.

2 Likes

Nice, maybe solves the issue. BTW looks like in the link you provided, there is also a mac version: https://sourceforge.net/projects/launch4j/files/launch4j-3/3.12/launch4j-3.12-macosx-x86.tgz/download

Thanks! I edited my reply accordingly.

A workaround I found was to just use an Ubuntu WSL, path to the starter kit location, and pretend I’m on Linux. For some reason Powershell wasn’t working for me either, although when I tried it again later it worked just fine.

I appreciate the help, but that didn’t work either. Getting the same error as before.

Hey, did you manage to get to the bottom of this?

No I didn’t. I haven’t had time to try things or even mess around in terminal because of exams.