Commit ddb86804 authored by Joseph Walton-Rivers's avatar Joseph Walton-Rivers 🐦

Merge branch 'feature-learntrack' into 'master'

2019 Competition - Learning Track

See merge request !7
parents d60230c5 906cc7d3
Pipeline #2163 passed with stages
in 2 minutes and 45 seconds
......@@ -24,7 +24,10 @@ 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;
protected final Player[] players;
protected final String[] playerNames;
protected final GameState state;
private int nPlayers;
......@@ -69,6 +72,7 @@ public class GameRunner {
public GameRunner(String gameID, GameState state){
this.players = new Player[state.getPlayerCount()];
this.playerNames = new String[state.getPlayerCount()];
this.state = Objects.requireNonNull(state);
this.nPlayers = 0;
this.nextPlayer = 0;
......@@ -88,6 +92,19 @@ public class GameRunner {
players[nPlayers++] = Objects.requireNonNull(player);
}
/**
* Add a named player.
*
* Player names will be revealed to all players at the start of a game.
*
* @param name the name of the player
* @param player the player object
*/
public void addNamedPlayer(String name, Player player) {
addPlayer(player);
playerNames[nPlayers - 1] = name;
}
/**
* Initialise the game for the players.
* <p>
......@@ -110,7 +127,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);
players[i].setID(i, players.length, playerNames);
}
state.init(seed);
......
......@@ -32,6 +32,11 @@ public interface Agent {
*
* @param agentID this agent's ID.
*/
default void receiveID(int agentID, String[] names) {
receiveID(agentID);
}
@Deprecated
default void receiveID(int agentID) {
}
......
......@@ -71,13 +71,19 @@ public class AgentPlayer implements Player {
}
@Override
public void setID(int id, int nPlayers) {
public void setID(int id, int nPlayers, String[] names) {
assert state == null;
assert playerID == -1;
this.playerID = id;
this.state = new BasicState(nPlayers);
policy.receiveID(id);
policy.receiveID(id, names);
}
@Override
public void setID(int id, int nPlayers) {
String[] names = new String[nPlayers];
setID(id, nPlayers, names);
}
@Override
......
......@@ -267,7 +267,7 @@ public class HatGuessing implements Agent {
@Override
public void receiveID(int agentID) {
public void receiveID(int agentID, String[] names) {
playerID = agentID;
}
......
......@@ -41,8 +41,8 @@ public class NoisyPredictor implements Agent {
}
@Override
public void receiveID(int agentID) {
policy.receiveID(agentID);
public void receiveID(int agentID, String[] names) {
policy.receiveID(agentID, names);
}
@Override
......
......@@ -49,6 +49,10 @@ public interface Player {
*/
void setID(int id, int nPlayers);
default void setID(int id, int nPlayers, String[] playerNames){
setID(id, nPlayers);
}
String getName();
......
......@@ -245,4 +245,5 @@ public interface GameState extends Serializable {
* @param eventList the resulting events from out perspective.
*/
void addAction(int playerID, Action action, List<GameEvent> eventList);
}
\ No newline at end of file
List<HistoryEntry> getActionHistory();
}
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