2021-04-29 17:15:29 +00:00
|
|
|
package uulm.teamname.marvelous.gamelibrary.gamelogic;
|
|
|
|
|
|
|
|
import uulm.teamname.marvelous.gamelibrary.IntVector2;
|
|
|
|
import uulm.teamname.marvelous.gamelibrary.entities.Entity;
|
|
|
|
import uulm.teamname.marvelous.gamelibrary.entities.EntityID;
|
2021-04-30 18:54:34 +00:00
|
|
|
import uulm.teamname.marvelous.gamelibrary.entities.EntityList;
|
2021-04-29 17:15:29 +00:00
|
|
|
import uulm.teamname.marvelous.gamelibrary.entities.StoneType;
|
|
|
|
import uulm.teamname.marvelous.gamelibrary.Tuple;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
2021-04-30 19:48:28 +00:00
|
|
|
import java.util.Iterator;
|
2021-04-29 17:15:29 +00:00
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/** Represents the state of a game instance. */
|
2021-04-29 17:15:29 +00:00
|
|
|
class GameState {
|
2021-04-30 18:54:34 +00:00
|
|
|
/** The size of the map */
|
2021-04-29 17:15:29 +00:00
|
|
|
public final IntVector2 mapSize;
|
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/** The list of {@link Entity}s inside the game */
|
|
|
|
public final EntityList entities = new EntityList();
|
2021-04-29 17:15:29 +00:00
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/** The total amount of full turn cycles that occurred */
|
2021-04-29 17:15:29 +00:00
|
|
|
public int roundNumber = 0;
|
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/** The turn order of every character */
|
2021-04-30 19:48:28 +00:00
|
|
|
public ArrayList<EntityID> turnOrder = new ArrayList<>();
|
2021-04-29 17:15:29 +00:00
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/** The total amount of turns that occurred */
|
2021-04-29 17:15:29 +00:00
|
|
|
public int turnNumber = 0;
|
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/** The {@link EntityID} of the active character */
|
2021-04-30 19:48:28 +00:00
|
|
|
public EntityID activeCharacter = null;
|
2021-04-29 17:15:29 +00:00
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/** Whether or not the game was won */
|
2021-04-29 17:15:29 +00:00
|
|
|
public boolean won = false;
|
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/** The global cooldown of every infinity stone */
|
|
|
|
public final HashMap<StoneType, Float> stoneCooldown = new HashMap<>();
|
2021-04-29 17:15:29 +00:00
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/** The store of the {@link WinCondition} data for every win condition for each player */
|
|
|
|
public final HashMap<Tuple<ParticipantType, WinCondition>, Integer> winConditions = new HashMap<>();
|
2021-04-29 17:15:29 +00:00
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/**
|
|
|
|
* Constructs a new {@link GameState}.
|
|
|
|
* @param mapSize The size of the map
|
2021-04-29 17:15:29 +00:00
|
|
|
*/
|
|
|
|
public GameState(IntVector2 mapSize) {
|
|
|
|
this.mapSize = mapSize;
|
|
|
|
}
|
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/**
|
2021-04-30 19:48:28 +00:00
|
|
|
* Clones the state into a new {@link GameState} object. This is slow.
|
2021-04-30 18:54:34 +00:00
|
|
|
* @return The cloned game state
|
2021-04-29 17:15:29 +00:00
|
|
|
*/
|
|
|
|
public GameState snapshot() {
|
2021-04-30 19:48:28 +00:00
|
|
|
GameState clone = new GameState(this.mapSize);
|
|
|
|
|
|
|
|
for(Iterator<Entity> it = this.entities.getEntities(); it.hasNext(); ) {
|
|
|
|
clone.entities.addEntity(it.next().clone());
|
|
|
|
}
|
|
|
|
|
|
|
|
clone.roundNumber = roundNumber;
|
|
|
|
|
|
|
|
clone.turnOrder = new ArrayList<>();
|
|
|
|
for(EntityID id: turnOrder) {
|
|
|
|
clone.turnOrder.add(id.clone());
|
|
|
|
}
|
|
|
|
|
|
|
|
clone.turnNumber = turnNumber;
|
|
|
|
|
|
|
|
clone.activeCharacter = activeCharacter != null ? activeCharacter.clone() : null;
|
|
|
|
|
|
|
|
clone.won = won;
|
|
|
|
|
|
|
|
for(StoneType type: stoneCooldown.keySet()) {
|
|
|
|
clone.stoneCooldown.put(type, stoneCooldown.get(type));
|
|
|
|
}
|
|
|
|
|
|
|
|
for(Tuple<ParticipantType, WinCondition> condition: winConditions.keySet()) {
|
|
|
|
clone.winConditions.put(condition, winConditions.get(condition));
|
|
|
|
}
|
|
|
|
|
|
|
|
return clone;
|
2021-04-29 17:15:29 +00:00
|
|
|
}
|
|
|
|
}
|