Commit d51425b5 authored by Joseph Walton-Rivers's avatar Joseph Walton-Rivers 🍪

keep track of the current game type

parent 090ef746
Pipeline #2225 passed with stages
in 4 minutes and 39 seconds
......@@ -5,7 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## v1.2.4
## v0.2.5
### Changed
* The type of game (zero life varient or classic) is passed to the agent
## v0.2.4
### Added
- New unit tests to check basic state properties
......@@ -14,7 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixes
- Fix regression in end of game detection ( issue #23 )
## v1.2.3
## v0.2.3
### Added
- New history features allow for easier processing of game events ( issue #6 )
......
......@@ -51,6 +51,14 @@
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
......@@ -133,5 +141,6 @@
<artifactId>reflections</artifactId>
<version>0.9.11</version>
</dependency>
</dependencies>
</project>
......@@ -3,6 +3,7 @@ package com.fossgalaxy.games.fireworks;
import com.fossgalaxy.games.fireworks.ai.Agent;
import com.fossgalaxy.games.fireworks.ai.AgentPlayer;
import com.fossgalaxy.games.fireworks.players.Player;
import com.fossgalaxy.games.fireworks.state.GameType;
import com.fossgalaxy.games.fireworks.utils.AgentUtils;
import java.io.FileOutputStream;
......@@ -79,7 +80,7 @@ public class App2Csv {
for (int i = -0; i < players.length; i++) {
runner.addPlayer(players[i]);
players[i].setID(i, players.length);
players[i].setID(i, players.length, new String[5], GameType.NO_LIVES_CURRENT);
}
GameStats stats = runner.playGame(seed);
......@@ -181,7 +182,7 @@ public class App2Csv {
try {
for (int i = -0; i < players.length; i++) {
runner.addPlayer(players[i]);
players[i].setID(i, players.length);
players[i].setID(i, players.length, new String[5], GameType.NO_LIVES_CURRENT);
}
GameStats stats = runner.playGame(seed);
......
......@@ -24,6 +24,7 @@ public class GameRunner {
private static final int[] HAND_SIZE = {-1, -1, 5, 5, 4, 4};
private final Logger logger = LoggerFactory.getLogger(GameRunner.class);
private final String gameID;
private final GameType type;
protected final Player[] players;
protected final String[] playerNames;
......@@ -74,6 +75,7 @@ public class GameRunner {
this.players = new Player[state.getPlayerCount()];
this.playerNames = new String[state.getPlayerCount()];
this.state = Objects.requireNonNull(state);
this.type = state instanceof NoLifeState ? GameType.NO_LIVES_ZERO : GameType.NO_LIVES_CURRENT;
this.nPlayers = 0;
this.nextPlayer = 0;
this.moves = 0;
......@@ -127,7 +129,7 @@ public class GameRunner {
//step 1: tell all players their IDs
for (int i = 0; i < players.length; i++) {
logger.info("player {} is {}", i, players[i]);
players[i].setID(i, players.length, playerNames);
players[i].setID(i, players.length, playerNames, type);
}
state.init(seed);
......
......@@ -3,6 +3,8 @@ package com.fossgalaxy.games.fireworks.ai;
import com.fossgalaxy.games.fireworks.players.Player;
import com.fossgalaxy.games.fireworks.state.BasicState;
import com.fossgalaxy.games.fireworks.state.GameState;
import com.fossgalaxy.games.fireworks.state.GameType;
import com.fossgalaxy.games.fireworks.state.NoLifeState;
import com.fossgalaxy.games.fireworks.state.actions.Action;
import com.fossgalaxy.games.fireworks.state.events.GameEvent;
......@@ -71,21 +73,21 @@ public class AgentPlayer implements Player {
}
@Override
public void setID(int id, int nPlayers, String[] names) {
public void setID(int id, int nPlayers, String[] names, GameType type) {
assert state == null;
assert playerID == -1;
this.playerID = id;
this.state = new BasicState(nPlayers);
if (type.equals(GameType.NO_LIVES_CURRENT)) {
this.state = new BasicState(nPlayers);
} else if (type.equals(GameType.NO_LIVES_ZERO)) {
this.state = new NoLifeState(nPlayers);
} else {
throw new IllegalArgumentException("Unsupported game type");
}
policy.receiveID(id, names);
}
@Override
public void setID(int id, int nPlayers) {
String[] names = new String[nPlayers];
setID(id, nPlayers, names);
}
@Override
public String getName() {
return name;
......
......@@ -4,6 +4,7 @@ import com.fossgalaxy.games.fireworks.ai.Agent;
import com.fossgalaxy.games.fireworks.ai.AgentPlayer;
import com.fossgalaxy.games.fireworks.human.ui.pretty.HeuristicGameView;
import com.fossgalaxy.games.fireworks.human.ui.pretty.HumanUIAgent;
import com.fossgalaxy.games.fireworks.state.GameType;
import com.fossgalaxy.games.fireworks.state.actions.Action;
import com.fossgalaxy.games.fireworks.state.events.CardInfoColour;
import com.fossgalaxy.games.fireworks.state.events.CardInfoValue;
......@@ -48,8 +49,8 @@ public class UIPlayer extends AgentPlayer {
}
@Override
public void setID(int id, int nPlayers) {
super.setID(id, nPlayers);
public void setID(int id, int nPlayers, String[] player, GameType type) {
super.setID(id, nPlayers, player, type);
if (interactive) {
this.view = new HeuristicGameView(state, id, (HumanUIAgent)policy);
......
package com.fossgalaxy.games.fireworks.players;
import com.fossgalaxy.games.fireworks.state.GameType;
import com.fossgalaxy.games.fireworks.state.actions.Action;
import com.fossgalaxy.games.fireworks.state.events.GameEvent;
......@@ -46,12 +47,10 @@ public interface Player {
*
* @param id the ID of this player
* @param nPlayers the number of players in the game
* @param playerNames the players you are playing with (Array of nulls if unknown)
* @param type the type of game being played
*/
void setID(int id, int nPlayers);
default void setID(int id, int nPlayers, String[] playerNames){
setID(id, nPlayers);
}
void setID(int id, int nPlayers, String[] playerNames, GameType type);
String getName();
......
package com.fossgalaxy.games.fireworks.state;
public enum GameType {
/**
* The histroic mode used for the games
*
* When the team runs out of lives, the agents get the score achieved at the end of the game
*/
NO_LIVES_CURRENT,
/**
* The re-interpreted version of the game
*
* When the team runs out of lives, the agents get a score of zero
*/
NO_LIVES_ZERO
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment