Allow game speed and map to be dynamically configurable

This commit is contained in:
Andrew Guibert 2018-05-14 14:49:46 -05:00
parent 8f68ddf09e
commit 17cf9906d7
4 changed files with 27 additions and 3 deletions

View File

@ -26,7 +26,7 @@ public abstract class AIPlayer implements AI {
public abstract DIRECTION processGameTick(short[][] board);
public Player asPlayer() {
String name = getClass().getSimpleName() + '-' + takenSpotNumber;
String name = getClass().getSimpleName() + ' ' + (takenSpotNumber + 1);
Player p = new Player(name, name, takenSpotNumber);
p.setAI(this);
return p;

View File

@ -46,8 +46,8 @@ public class GameRound implements Runnable {
FINISHED // game has ended and a winner has been declared
}
public static final Jsonb jsonb = JsonbBuilder.create();
public static final int GAME_TICK_SPEED = 50; // ms
private static final Jsonb jsonb = JsonbBuilder.create();
private static final int GAME_TICK_SPEED_DEFAULT = 50; // ms
private static final int DELAY_BETWEEN_ROUNDS = 5; //ticks
private static final int STARTING_COUNTDOWN = 3; // seconds
private static final int MAX_TIME_BETWEEN_ROUNDS = Integer.getInteger("game-service.time.between.rounds", 20); // 20 seconds default
@ -67,6 +67,7 @@ public class GameRound implements Runnable {
private final Map<Session, Client> clients = new HashMap<>();
private final Deque<Player> playerRanks = new ArrayDeque<>();
private final Set<LifecycleCallback> lifecycleCallbacks = new HashSet<>();
private final int GAME_TICK_SPEED;
private LobbyCountdown lobbyCountdown;
private AtomicBoolean lobbyCountdownStarted = new AtomicBoolean();
@ -87,6 +88,14 @@ public class GameRound implements Runnable {
public GameRound(String id) {
this.id = id;
nextRoundId = getRandomId();
Integer tickSpeed = GAME_TICK_SPEED_DEFAULT;
try {
tickSpeed = InitialContext.doLookup("round/gameSpeed");
} catch (Exception e) {
log("Unable to perform JNDI lookup to determine game tick speed, using default value");
}
GAME_TICK_SPEED = (tickSpeed < 20 || tickSpeed > 100) ? GAME_TICK_SPEED_DEFAULT : tickSpeed;
}
public GameBoard getBoard() {

View File

@ -4,6 +4,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import javax.naming.InitialContext;
import org.libertybikes.game.core.DIRECTION;
import org.libertybikes.game.core.GameBoard;
import org.libertybikes.game.core.GameBoard.Point;
@ -19,6 +21,15 @@ public class GameMap {
* @param map -1=random, 0=empty, >0=specific map
*/
public static GameMap create(int map) {
try {
int mapOverride = InitialContext.doLookup("round/map");
if (mapOverride >= 0 && mapOverride <= NUM_MAPS) {
map = mapOverride;
System.out.println("Overriding map selection to map #" + map);
}
} catch (Exception ignore) {
}
switch (map) {
case -1:
return create(r.nextInt(NUM_MAPS) + 1);

View File

@ -13,6 +13,10 @@
</featureManager>
<httpEndpoint id="defaultHttpEndpoint" host="*" httpPort="${httpPort}" httpsPort="${httpsPort}" />
<!-- Dynamically configurable settings -->
<jndiEntry jndiName="round/gameSpeed" value="50"/> <!-- Default = 50(ms) -->
<jndiEntry jndiName="round/map" value="-1"/> <!-- Default = -1 (random map) -->
<applicationManager autoExpand="true"/>