Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,114 @@ https://www.codingame.com/contests/fall-challenge-2022/
Community starter AIs are located here:

https://github.com/CodinGame/FallChallenge2022-KeepOffTheGrass/tree/main/starterAIs

## Build and run locally

How to build and run the referee locally.

### Prerequites

#### Java 8

Java 8 or higher: The pom.xml file specifies that the maven-compiler-plugin should use a source and target compatibility of 1.8, which means that the code will be compiled to be compatible with Java 8 or higher. You will need to have a Java 8 or higher runtime installed to run the code. See https://openjdk.java.net/ to install.

```console
java -version
```

##### Install OpenJDK:

Download the OpenJDK 8 or higher for the user's platform from the OpenJDK website: https://openjdk.java.net/

Follow the installation instructions provided by OpenJDK to install the JDK on the user's system. This will typically involve extracting the downloaded archive and setting the JAVA_HOME environment variable to point to the installation directory.

After the installation is complete, the user should verify that the OpenJDK is correctly installed by running the java -version command and checking the output. The output should indicate that the OpenJDK is being used (e.g. "OpenJDK 11.0.9").

#### Apache Maven

Apache Maven 3.5.3 or higher: The pom.xml file is a Maven project file, and you will need Maven 3.5.3 or higher installed to build and run the project. Maven is a build automation tool that is used to manage the dependencies, build process, and testing of a Java project.

```console
mvn -version
```
##### Maven install instructions

Download Apache Maven 3.5.3 or higher from the Apache Maven website: https://maven.apache.org/download.cgi

Extract the downloaded archive to a directory on the user's system. This will create a directory with the name "apache-maven-3.5.3" (or similar, depending on the version you downloaded).

Set the MAVEN_HOME environment variable to point to the directory where Maven was installed. This will allow Maven and other tools to find Maven when they need to use it. The user can set the MAVEN_HOME variable by following these steps:

On Windows:
Right-click on the "Computer" icon and select "Properties"
Click on the "Advanced system settings" link
Click on the "Environment Variables" button
Under "System Variables", scroll down and click on the "New" button
In the "Variable name" field, enter "MAVEN_HOME"
In the "Variable value" field, enter the path to the Maven installation directory (e.g. "C:\Program Files\Apache Maven 3.5.3")
Click the "OK" button to close the "New System Variable" dialog
Click the "OK" button to close the "Environment Variables" dialog
Click the "OK" button to close the "System Properties"
On macOS or Linux:
Open a terminal window and enter the following command:
export MAVEN_HOME=path/to/maven/installation/directory
Replace "path/to/maven/installation/directory" with the actual path to the Maven installation directory (e.g. "/usr/local/maven")
Add the Maven bin directory to the user's PATH environment variable. This will allow the user to run Maven from any directory by simply typing "mvn" on the command line. The user can add the bin directory to the PATH variable by following these steps:

On Windows:
Follow the steps 1-3 above to open the "Environment Variables" dialog
Under "System Variables", scroll down and find the "Path" variable
Click on the "Edit"

#### Node and npm

Node.js is a runtime environment for running JavaScript applications, and npm is the package manager for Node.js. If you do not have these tools installed, you can install them from the Node.js website: https://nodejs.org/

### Build Javascript

```console
cd .\src\main\resources\view\
npm install
npm run start
```

To build the Javascript part of the project, you can instruct the user to follow these steps:

Open a terminal window and navigate to the src/main/resource/view directory. This is the directory where the Javascript source code is located.

Run the npm install command to install the required dependencies for the project. This will install the packages listed in the package.json file, which includes any libraries or tools that the project needs to build and run.

Run the npm run start command to build and start the project. This will use the scripts defined in the package.json file to build the project and start a development server. The development server will automatically reload the project when changes are made to the source code, which can be useful for testing and debugging.

### CLI

#### Build and run

To build the project and create an executable jar file, run the following command in the root directory of the project:

```console
mvn clean package
```

#### Execute the jar

To build your bot and run the game with two bots and a specified seed, use a similar Powershell script:

```Powershell
$RefereeWorkingDir = "C:\git\github\TheFreezeTeam\FallChallenge2022-KeepOffTheGrass\"
$RefereeJar = "C:\git\github\TheFreezeTeam\FallChallenge2022-KeepOffTheGrass\target\fall-challenge-2022-keep-off-the-grass-1.0-SNAPSHOT.jar"
$Bot1 = "C:\git\github\StevenTCramer\Training\CodingGame\KeepOffTheGrass\Source\bin\Release\net6.0\KeepOffTheGrass.exe"
$Bot1Nickname = "StevenTCramer"
$Bot2 = "C:\git\github\StevenTCramer\Training\CodingGame\KeepOffTheGrass\bots\SnowFrogDev.exe"
$Bot2Nickname = "SnowFrogDev"
$Seed = "-1338641737090246700"

Stop-Process $CodingameProcess -ErrorAction SilentlyContinue

dotnet build Source\KeepOffTheGrass.csproj -c release;

Push-Location $RefereeWorkingDir
$global:CodingameProcess = Start-Process -FilePath 'C:\Program Files\Amazon Corretto\jdk1.8.0_352\bin\java.exe' -ArgumentList '-jar', $RefereeJar, $Bot1, $Bot1Nickname, $Bot2, $Bot2Nickname, $Seed -PassThru

Pop-Location
```
24 changes: 24 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,28 @@
<version>${gamengine.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>KeepOffTheGrassMain</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
100 changes: 100 additions & 0 deletions src/main/java/KeepOffTheGrassMain.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import java.io.File;
import java.io.IOException;

import com.codingame.gameengine.runner.MultiplayerGameRunner;
import com.google.common.io.Files;

public class KeepOffTheGrassMain {

public static void main(String[] args) throws IOException, InterruptedException {

Options opts = new Options().read(args);

System.out.format("bot1Command %s%n", opts.getBot1Command());
System.out.format("bot1Nickname %s%n", opts.getBot1Nickname());
System.out.format("bot2Command %s%n", opts.getBot2Command());
System.out.format("bot2Nickname %s%n", opts.getBot2Nickname());
System.out.format("seed %d%n", opts.getSeed());

MultiplayerGameRunner gameRunner = new MultiplayerGameRunner();

gameRunner.setSeed(opts.getSeed());
gameRunner.addAgent(opts.getBot1Command(), opts.getBot1Nickname());
gameRunner.addAgent(opts.getBot2Command(), opts.getBot2Nickname());

gameRunner.start();
}

private static String compile(String botFile) throws IOException, InterruptedException {

File outFolder = Files.createTempDir();

System.out.println("Compiling Boss.java... " + botFile);
Process compileProcess = Runtime.getRuntime()
.exec(new String[] { "bash", "-c", "javac " + botFile + " -d " + outFolder.getAbsolutePath() });
compileProcess.waitFor();
return "java -cp " + outFolder + " Player";
}

private static String[] compileTS(String botFile) throws IOException, InterruptedException {

System.out.println("Compiling ... " + botFile);

Process compileProcess = Runtime.getRuntime().exec(
new String[] { "bash", "-c", "tsc --target ES2018 --inlineSourceMap --types ./typescript/readline/ "
+ botFile + " --outFile /tmp/Boss.js" }
);
compileProcess.waitFor();

return new String[] { "bash", "-c", "node -r ./typescript/polyfill.js /tmp/Boss.js" };
}
}

class Options {
private String bot1Command = null;
private String bot1Nickname = null;
private String bot2Command = null;
private String bot2Nickname = null;
private String seed = null;

public Options read(String[] args) {
if (args == null || args.length == 0) {
return this;
}

this.bot1Command = args[0];
this.bot1Nickname = args.length > 1 ? args[1] : null;
this.bot2Command = args.length > 2 ? args[2] : null;
this.bot2Nickname = args.length > 3 ? args[3] : null;
this.seed = args.length > 4 ? args[4] : null;

return this;
}

public String getBot1Nickname(){
return bot1Nickname == null ? "Player1" : bot1Nickname;
}

public String getBot2Nickname(){
return bot1Nickname == null ? "Player1" : bot2Nickname;
}

public String getBot1Command() {
return
bot1Command == null ?
"C:/git/github/StevenTCramer/Training/CodingGame/KeepOffTheGrass/Source/bin/Release/net6.0/KeepOffTheGrass.exe" :
bot1Command;
}

public String getBot2Command() {
return
bot2Command == null ?
"C:/git/github/StevenTCramer/Training/CodingGame/KeepOffTheGrass/bots/SnowFrogDev.exe" :
bot2Command;
}

public Long getSeed() {
if(this.seed == null) return null;
return Long.parseLong(this.seed);
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/view/assets/assets/Case.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading