From e228e9551aa72c267478f6498b3763ca42b1f38a Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Wed, 26 Apr 2023 11:49:06 +1000 Subject: [PATCH] state: Added simple mode for isPhaseOver() --- src/comp1110/ass2/BlueLagoon.java | 2 +- src/comp1110/ass2/State.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/comp1110/ass2/BlueLagoon.java b/src/comp1110/ass2/BlueLagoon.java index b8245f5..9ef9097 100644 --- a/src/comp1110/ass2/BlueLagoon.java +++ b/src/comp1110/ass2/BlueLagoon.java @@ -538,7 +538,7 @@ public class BlueLagoon { */ public static boolean isPhaseOver(String stateString){ State state = new State(stateString); - return state.isPhaseOver(); + return state.isPhaseOver(true); } /** diff --git a/src/comp1110/ass2/State.java b/src/comp1110/ass2/State.java index 9bf01d7..778d1ff 100644 --- a/src/comp1110/ass2/State.java +++ b/src/comp1110/ass2/State.java @@ -412,6 +412,23 @@ public class State { return !resourcesLeft || !moveLeft; } + /** + * is the phase over? + * @param simple boolean don't check all player moves + */ + public boolean isPhaseOver(boolean simple){ + boolean resourcesLeft = false; + for (Resource r : resources) { + if (!r.isClaimed() && r.getType() != 'S') resourcesLeft = true; + } + + boolean moveLeft = false; + if (getCurrentPlayer().canPlay(this)) moveLeft = true; + + + return !resourcesLeft || !moveLeft; + } + /** * Clean board for next phase */