Skip to content

Commit

Permalink
Update seekers grpc version
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiyotoko committed Apr 25, 2024
1 parent 8f53cc3 commit 8d33f43
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 103 deletions.
42 changes: 41 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ If you start the server for the first time, the following file and folders will
| `results` | Save tournament results |

Before the server starts, the app checks first if all listed paths exist. If a path does not exist, it will be created.
Then it will launch all plugins.
Then it will launch all plugins. It will create a tournament with a list of matches. In the tournament will every player
play a match against every other opponent. If the

## Config

Expand All @@ -71,12 +72,51 @@ For example, the section of the python plugin is `[python-plugin]`. The name of
the plugin. Please note that the config file of the seekers-py repo and this config file are interchangeable. If you
have already altered your config file for python, you can simply reuse it for the server.

Please note that the playtime is measured in game ticks. For a conversion between ticks and time, you can look at the
table below:

| Ticks | Time |
|:----------:|:-----:|
| 1 | 10ms |
| 100 | 1s |
| 6000 | 1min |
| 30000 | 5min |
| 90000 | 15min |
| 360000 | 1h |
| 8640000 | 1d |
| 3155760000 | 1a |

## Players

The server will create a tournament with all AIs that are in the `players` folder. A file is marked as a valid player
if it starts with `ai`. Drop all files you want to run into this folder and start the server. Please note that an empty
folder will result into an empty tournament. If the tournament is empty, the server will be closed automatically.

## Plugins

The server will not host any clients on its own. If you want to do it automatically instead manually, you can add
plugins. Simply download the plugin jar from the release page of the publisher, move it to the plugins folder and add
the settings if required to the config.

## Results

All results will be saved in the ``results`` folder. This file contains a list of all matches that are still running and
a map of all results for the players. Every player has a list of all the points that it received in the respective
match.

```json
{
"matches": [
["players/ai-x\u003dx+1.py", "players/ai-triumvirat.py"],
["players/ai-undefined.py", "players/ai-triumvirat.py"]
],
"results": {
"players/ai-x\u003dx+1": [0],
"players/ai-undefined":[0]
}
}
```

## Structure

This is the class diagram of important types in this program:
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<dependency>
<groupId>com.github.seekers-dev</groupId>
<artifactId>seekers-grpc</artifactId>
<version>69bbfb4</version>
<version>555ce6bc3c</version>
</dependency>
<dependency>
<groupId>org.pf4j</groupId>
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/seekers/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public class App extends Application {
/**
* Before the server or stage is started, three things must be checked:
* <ol>
* <li>Loads the config.ini file</li>
* <li>Checks for all content folders. If a folder does not exist, it will be created.</li>
* <li>Loads the config.ini file</li>
* <li>Loads all plugins.</li>
* </ol>
*
Expand Down Expand Up @@ -89,15 +89,14 @@ public void init() throws IOException {
extension.setup(config.get(manager.whichPlugin(extension.getClass()).getPluginId()));
extension.addLanguageLoaders(loaders);
}

manager.stopPlugins();
}

@Override
public void start(Stage stage) throws Exception {
final SeekersServer server = new SeekersServer(stage, config, loaders);
stage.setOnCloseRequest(c -> {
logger.info("Try unloading plugins and stopping server on stage close request");
manager.stopPlugins();
manager.unloadPlugins();
try {
server.stop();
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/org/seekers/game/Camp.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import javafx.scene.shape.Rectangle;
import org.ini4j.Ini;
import org.seekers.grpc.Corresponding;
import org.seekers.grpc.game.CampOuterClass;

import javax.annotation.Nonnull;

Expand All @@ -31,7 +32,7 @@
*
* @author karlz
*/
public class Camp extends Rectangle implements Corresponding<org.seekers.grpc.game.Camp> {
public class Camp extends Rectangle implements Corresponding<CampOuterClass.Camp> {

private final @Nonnull Player player;
private final @Nonnull Properties properties;
Expand Down Expand Up @@ -112,8 +113,8 @@ public void setPosition(@Nonnull Point2D position) {
}

@Override
public org.seekers.grpc.game.Camp associated() {
return org.seekers.grpc.game.Camp.newBuilder().setId(getIdentifier()).setPlayerId(player.getIdentifier())
public CampOuterClass.Camp associated() {
return CampOuterClass.Camp.newBuilder().setId(getIdentifier()).setPlayerId(player.getIdentifier())
.setPosition(TorusMap.toMessage(position)).setWidth(properties.width).setHeight(properties.height).build();
}

Expand Down
18 changes: 9 additions & 9 deletions src/main/java/org/seekers/game/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
import javafx.util.Duration;
import org.ini4j.Ini;
import org.seekers.grpc.Corresponding;
import org.seekers.grpc.service.CommandResponse;
import org.seekers.plugin.GameMap;
import org.seekers.plugin.Tournament;
import org.seekers.grpc.net.StatusResponse;

import javax.annotation.Nonnull;
import java.util.*;
Expand All @@ -55,7 +55,7 @@ public class Game extends Scene {
// Game objects
private final @Nonnull List<Entity> entities = new ArrayList<>();
private final GameMap gameMap;
private int tick = 0;
private long tick = 0;

// Cached types for gRPC fast access
private final @Nonnull List<Player> players = new ArrayList<>();
Expand Down Expand Up @@ -237,12 +237,12 @@ public void addGoals() {
/**
* @return the current status of the game
*/
public synchronized StatusResponse getStatusResponse() {
return StatusResponse.newBuilder().addAllPlayers(Corresponding.transform(getPlayers()))
.addAllCamps(Corresponding.transform(getCamps()))
.addAllSeekers(Seeker.transform(getSeekers()))
.addAllGoals(Goal.transform(getGoals()))
.setPassedPlaytime(getPassedPlaytime()).build();
public synchronized CommandResponse.Builder getCommandResponse() {
return CommandResponse.newBuilder().addAllPlayers(Corresponding.transform(getPlayers()))
.addAllCamps(Corresponding.transform(getCamps()))
.addAllSeekers(Seeker.transform(getSeekers()))
.addAllGoals(Goal.transform(getGoals()))
.setPassedPlaytime(getPassedPlaytime());
}

/**
Expand Down Expand Up @@ -312,7 +312,7 @@ public Group getFront() {
/**
* @return the passed playtime
*/
public double getPassedPlaytime() {
public long getPassedPlaytime() {
return tick;
}
}
8 changes: 5 additions & 3 deletions src/main/java/org/seekers/game/Goal.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import org.ini4j.Ini;
import org.seekers.grpc.game.GoalOuterClass;
import org.seekers.grpc.game.PhysicalOuterClass;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand All @@ -37,7 +39,7 @@
*/
public class Goal extends Physical<Goal.Properties> {

public static Iterable<org.seekers.grpc.game.Goal> transform(Collection<? extends Goal> goals) {
public static Iterable<GoalOuterClass.Goal> transform(Collection<? extends Goal> goals) {
return goals.stream().map(Goal::associated).collect(Collectors.toList());
}

Expand Down Expand Up @@ -150,8 +152,8 @@ public void setTimeOwned(double timeOwned) {
}

@Override
public org.seekers.grpc.game.Goal associated() {
return org.seekers.grpc.game.Goal.newBuilder().setSuper((org.seekers.grpc.game.Physical) super.associated())
public GoalOuterClass.Goal associated() {
return GoalOuterClass.Goal.newBuilder().setSuper((PhysicalOuterClass.Physical) super.associated())
.setCampId((capture != null) ? capture.getIdentifier() : "").setTimeOwned(timeOwned).build();
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/seekers/game/Physical.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import javafx.scene.shape.Circle;
import org.ini4j.Ini;
import org.seekers.grpc.Corresponding;
import org.seekers.grpc.game.PhysicalOuterClass;

import javax.annotation.Nonnull;
import javax.annotation.OverridingMethodsMustInvokeSuper;
Expand Down Expand Up @@ -204,7 +205,7 @@ public double getThrust() {

@Override
public Message associated() {
return org.seekers.grpc.game.Physical.newBuilder().setId(getIdentifier())
return PhysicalOuterClass.Physical.newBuilder().setId(getIdentifier())
.setAcceleration(TorusMap.toMessage(acceleration)).setPosition(TorusMap.toMessage(position))
.setVelocity(TorusMap.toMessage(velocity)).build();
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/seekers/game/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import org.seekers.grpc.Corresponding;
import org.seekers.grpc.game.PlayerOuterClass;

/**
* The Player class represents a player in the game.
*
* @author karlz
game.getFront().getChildren().add(this);
*/
public class Player extends Label implements Corresponding<org.seekers.grpc.game.Player> {
public class Player extends Label implements Corresponding<PlayerOuterClass.Player> {

private static final @Nonnull Random rand = new Random();

Expand Down Expand Up @@ -181,10 +182,9 @@ public void putUp() {
}

@Override
public org.seekers.grpc.game.Player associated() {
return org.seekers.grpc.game.Player.newBuilder().setId(getIdentifier()).addAllSeekerIds(seekers.keySet())
.setCampId(camp != null ? camp.getIdentifier() : "").setName(name).setColor(color.toString())
.setScore(score).build();
public PlayerOuterClass.Player associated() {
return PlayerOuterClass.Player.newBuilder().setId(getIdentifier()).addAllSeekerIds(seekers.keySet())
.setCampId(camp != null ? camp.getIdentifier() : "").setScore(score).build();
}

}
8 changes: 5 additions & 3 deletions src/main/java/org/seekers/game/Seeker.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import org.ini4j.Ini;
import org.seekers.grpc.game.PhysicalOuterClass;
import org.seekers.grpc.game.SeekerOuterClass;
import org.seekers.plugin.GameMap;

import javax.annotation.Nonnull;
Expand All @@ -35,7 +37,7 @@
*/
public class Seeker extends Physical<Seeker.Properties> {

public static Iterable<org.seekers.grpc.game.Seeker> transform(Collection<? extends Seeker> seekers) {
public static Iterable<? extends SeekerOuterClass.Seeker> transform(Collection<? extends Seeker> seekers) {
return seekers.stream().map(Seeker::associated).collect(Collectors.toList());
}

Expand Down Expand Up @@ -271,8 +273,8 @@ public void setPosition(@Nonnull Point2D position) {
}

@Override
public org.seekers.grpc.game.Seeker associated() {
return org.seekers.grpc.game.Seeker.newBuilder().setSuper((org.seekers.grpc.game.Physical) super.associated())
public SeekerOuterClass.Seeker associated() {
return SeekerOuterClass.Seeker.newBuilder().setSuper((PhysicalOuterClass.Physical) super.associated())
.setPlayerId(player.getIdentifier()).setMagnet(magnet).setTarget(TorusMap.toMessage(target))
.setDisableCounter(disabledCounter).build();
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/seekers/game/TorusMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.seekers.game;

import javafx.geometry.Point2D;
import org.seekers.grpc.game.Vector2DOuterClass;
import org.seekers.plugin.GameMap;

import javax.annotation.Nonnull;
Expand All @@ -38,8 +39,8 @@ public TorusMap(double width, double height) {
this.height = height;
}

static org.seekers.grpc.game.Vector2D toMessage(Point2D vec) {
return org.seekers.grpc.game.Vector2D.newBuilder().setX(vec.getX()).setY(vec.getY()).build();
static Vector2DOuterClass.Vector2D toMessage(Point2D vec) {
return Vector2DOuterClass.Vector2D.newBuilder().setX(vec.getX()).setY(vec.getY()).build();
}

/**
Expand Down
Loading

0 comments on commit 8d33f43

Please sign in to comment.