codingame 2023春 ローカル環境構築(自分用メモ)

やったこと

ボンドさんの真似

Codingameのローカル対戦環境をdockerでポンする - 接着剤の精進日記

jiro:~/work$ git clone https://github.com/EmulsionBondo/CodingameLocalBattle.git
jiro:~/work$ git clone git@github.com:CodinGame/SpringChallenge2023.git
jiro:~/work$ curl -OL https://github.com/dreignier/cg-brutaltester/releases/download/1.0.0/cg-brutaltester-1.0.0.jar
jiro:~/work$ ls
CodingameLocalBattle  SpringChallenge2023  cg-brutaltester-1.0.0.jar

2023春をcg-brutaltesterに対応

https://github.com/dreignier/cg-brutaltester#all-steps

Modify the pom.xml file.

2022春のpom.xmlを参考にして、SpringChallenge2023/pom.xmlを以下で置き換え

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.codingame.game</groupId>
    <artifactId>spring-2023-ants</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <gamengine.version>4.4.2</gamengine.version>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.codingame.gameengine</groupId>
            <artifactId>core</artifactId>
            <version>${gamengine.version}</version>
        </dependency>

        <dependency>
            <groupId>com.codingame.gameengine</groupId>
            <artifactId>module-endscreen</artifactId>
            <version>${gamengine.version}</version>
        </dependency>

        <dependency>
            <groupId>com.codingame.gameengine</groupId>
            <artifactId>runner</artifactId>
            <version>${gamengine.version}</version>
        </dependency>

        <dependency>
            <groupId>commons-cli</groupId>
            <artifactId>commons-cli</artifactId>
            <version>1.3.1</version>
        </dependency>
    </dependencies>


    <build>
        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>com.codingame.gameengine.runner.CommandLineInterface</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.4.2</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>com.codingame.gameengine.runner.CommandLineInterface</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>
</project>

Add the CommandLineInterface class in the package com.codingame.gameengine.runner

SpringChallenge2023/src/main/java/com/codingame/gameengine/runner/ディレクトリを作成して、その中に

2022春のCommandLineInterface .javaをそのまま突っ込む

追記:2023/06/01

src/main/java/com/codingame/game/Config.javaSCORES_IN_IOfalse になってるので、trueに直す

ボンドさんの続き

jiro:~/work$ docker run -it --rm --name my-maven-project -v $PWD/SpringChallenge2023/:/usr/src/mymaven -w /usr/src/mymaven maven:3.3-jdk-8 mvn clean install package
...
(たくさんのログ)
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 14.670 s
[INFO] Finished at: 2023-05-25T17:21:22+00:00
[INFO] Final Memory: 56M/655M
[INFO] ------------------------------------------------------------------------
jiro:~/work$ cp SpringChallenge2023/target/spring-2023-ants-1.0-SNAPSHOT.jar ./
jiro:~/work$ ls
CodingameLocalBattle
SpringChallenge2023
cg-brutaltester-1.0.0.jar
spring-2023-ants-1.0-SNAPSHOT.jar
jiro:~/work$ docker build -t local_battle ./CodingameLocalBattle/
jiro:~/work$ docker run -it -d --name local_battle -v $PWD:/work local_battle

結果

./mainは適切に自分のプログラムに置き換えてください

jiro:~/work$ docker exec local_battle java -jar cg-brutaltester-1.0.0.jar -r "java -jar spring-2023-ants-1.0-SNAPSHOT.jar" -p1 "./main" -p2 "./main" -n 10
02:31:36,775 INFO  [com.magusgeek.brutaltester.Main] Referee command line: java -jar spring-2023-ants-1.0-SNAPSHOT.jar
02:31:36,775 INFO  [com.magusgeek.brutaltester.Main] Player 1 command line: ./main
02:31:36,775 INFO  [com.magusgeek.brutaltester.Main] Player 2 command line: ./main
02:31:36,775 INFO  [com.magusgeek.brutaltester.Main] Number of games to play: 10
02:31:36,776 INFO  [com.magusgeek.brutaltester.Main] Number of threads to spawn: 1
02:31:37,368 INFO  [com.magusgeek.brutaltester.GameThread] End of game 1      0.00% 0.00%
02:31:38,312 INFO  [com.magusgeek.brutaltester.GameThread] End of game 2      50.00% 0.00%
02:31:39,214 INFO  [com.magusgeek.brutaltester.GameThread] End of game 3      33.33% 33.33%
02:31:39,995 INFO  [com.magusgeek.brutaltester.GameThread] End of game 4      25.00% 50.00%
02:31:40,888 INFO  [com.magusgeek.brutaltester.GameThread] End of game 5      20.00% 60.00%
02:31:41,502 INFO  [com.magusgeek.brutaltester.GameThread] End of game 6      16.67% 66.67%
02:31:42,181 INFO  [com.magusgeek.brutaltester.GameThread] End of game 7      14.29% 71.43%
02:31:42,981 INFO  [com.magusgeek.brutaltester.GameThread] End of game 8      12.50% 75.00%
02:31:43,599 INFO  [com.magusgeek.brutaltester.GameThread] End of game 9      11.11% 77.78%
02:31:44,232 INFO  [com.magusgeek.brutaltester.GameThread] End of game 10     20.00% 70.00%
02:31:44,233 INFO  [com.magusgeek.brutaltester.Main] *** End of games ***
+----------+----------+----------+
| Results  | Player 1 | Player 2 |
+----------+----------+----------+
| Player 1 |          | 20.00%   |
+----------+----------+----------+
| Player 2 | 70.00%   |          |
+----------+----------+----------+

参考

CodinGame でローカル対戦環境を作る - koyumeishiのブログ