refactor: improve stone cooldown storing and implement better cloning

This commit is contained in:
2021-05-01 19:47:19 +02:00
parent 01ee534a56
commit fe249f39ea
6 changed files with 74 additions and 19 deletions

View File

@ -1,15 +1,11 @@
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;
import uulm.teamname.marvelous.gamelibrary.entities.EntityList;
import uulm.teamname.marvelous.gamelibrary.entities.StoneType;
import uulm.teamname.marvelous.gamelibrary.entities.*;
import uulm.teamname.marvelous.gamelibrary.Tuple;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
/** Represents the state of a game instance. */
class GameState {
@ -17,7 +13,7 @@ class GameState {
public final IntVector2 mapSize;
/** The list of {@link Entity}s inside the game */
public final EntityList entities = new EntityList();
public final EntityManager entities = new EntityManager();
/** The total amount of full turn cycles that occurred */
public int roundNumber = 0;
@ -35,7 +31,7 @@ class GameState {
public boolean won = false;
/** The global cooldown of every infinity stone */
public final HashMap<StoneType, Float> stoneCooldown = new HashMap<>();
public final StoneCooldownManager stoneCooldown = new StoneCooldownManager();
/** The store of the {@link WinCondition} data for every win condition for each player */
public final HashMap<Tuple<ParticipantType, WinCondition>, Integer> winConditions = new HashMap<>();
@ -55,9 +51,7 @@ class GameState {
public GameState snapshot() {
GameState clone = new GameState(this.mapSize);
for(Iterator<Entity> it = this.entities.getEntities(); it.hasNext(); ) {
clone.entities.addEntity(it.next().clone());
}
clone.entities.cloneFrom(entities);
clone.roundNumber = roundNumber;
@ -72,9 +66,7 @@ class GameState {
clone.won = won;
for(StoneType type: stoneCooldown.keySet()) {
clone.stoneCooldown.put(type, stoneCooldown.get(type));
}
clone.stoneCooldown.cloneFrom(stoneCooldown);
for(Tuple<ParticipantType, WinCondition> condition: winConditions.keySet()) {
clone.winConditions.put(condition, winConditions.get(condition));

View File

@ -45,7 +45,7 @@ public class GameStateView {
return state.won;
}
public float getStoneCooldown(StoneType stone) {
return state.stoneCooldown.get(stone);
public int getStoneCooldown(StoneType stone) {
return state.stoneCooldown.getCooldown(stone);
}
}