1919import java .util .List ;
2020import java .util .stream .Collectors ;
2121
22- /**
23- * Represents the current state of the Werewolf game.
24- */
22+ /** Represents the current state of the Werewolf game. */
2523public class GameState {
2624 private final List <Player > allPlayers ;
2725 private final List <Player > seers ;
@@ -33,9 +31,17 @@ public class GameState {
3331 private Player lastPoisonedVictim ;
3432 private boolean lastVictimResurrected ;
3533
34+ // First night jump candidate (悍跳候选人)
35+ private Player jumpCandidate ; // 第一夜狼人投票选出的悍跳候选人
36+
37+ // Sheriff election state
38+ private Player sheriff ; // 当前警长
39+ private boolean speakOrderReversed ; // 发言顺序是否逆序(警长决定)
40+ private boolean sheriffKilledInNight ; // 警长是否在夜间被杀(用于天亮后移交警徽)
41+
3642 /**
37- * Constructs a new GameState instance with the provided players.
38- * Special role players (seer, witch, hunter) are detected from the list.
43+ * Constructs a new GameState instance with the provided players. Special role players (seer,
44+ * witch, hunter) are detected from the list.
3945 *
4046 * @param allPlayers the list of all players participating in the game
4147 */
@@ -47,6 +53,11 @@ public GameState(List<Player> allPlayers) {
4753 this .seers = findPlayersByRole (Role .SEER );
4854 this .witches = findPlayersByRole (Role .WITCH );
4955 this .hunters = findPlayersByRole (Role .HUNTER );
56+
57+ // Initialize sheriff state
58+ this .sheriff = null ;
59+ this .speakOrderReversed = false ;
60+ this .sheriffKilledInNight = false ;
5061 }
5162
5263 private List <Player > findPlayersByRole (Role role ) {
@@ -184,10 +195,53 @@ public boolean isLastVictimResurrected() {
184195 return lastVictimResurrected ;
185196 }
186197
198+ /**
199+ * Returns the current sheriff.
200+ *
201+ * @return the sheriff player, or null if none
202+ */
203+ public Player getSheriff () {
204+ return sheriff ;
205+ }
206+
207+ /**
208+ * Indicates whether the speaking order is reversed.
209+ *
210+ * @return true if speaking order is reversed; false otherwise
211+ */
212+ public boolean isSpeakOrderReversed () {
213+ return speakOrderReversed ;
214+ }
215+
216+ /**
217+ * Indicates whether the sheriff was killed during the night.
218+ *
219+ * @return true if sheriff was killed at night; false otherwise
220+ */
221+ public boolean isSheriffKilledInNight () {
222+ return sheriffKilledInNight ;
223+ }
224+
225+ /**
226+ * Returns the jump candidate selected by werewolves on the first night.
227+ *
228+ * @return the jump candidate player, or null if none
229+ */
230+ public Player getJumpCandidate () {
231+ return jumpCandidate ;
232+ }
233+
187234 // State modifiers
188235 /**
189- * Increments the round counter by one to start a new round.
236+ * Sets the jump candidate selected by werewolves on the first night.
237+ *
238+ * @param jumpCandidate the werewolf player selected to jump as seer
190239 */
240+ public void setJumpCandidate (Player jumpCandidate ) {
241+ this .jumpCandidate = jumpCandidate ;
242+ }
243+
244+ /** Increments the round counter by one to start a new round. */
191245 public void nextRound () {
192246 this .currentRound ++;
193247 }
@@ -220,32 +274,83 @@ public void setLastVictimResurrected(boolean resurrected) {
220274 }
221275
222276 /**
223- * Clears last night results, including the werewolf victim, poisoned victim,
224- * and resurrection flag, preparing for the next night.
277+ * Clears last night results, including the werewolf victim, poisoned victim, and resurrection
278+ * flag, preparing for the next night.
225279 */
226280 public void clearNightResults () {
227281 this .lastNightVictim = null ;
228282 this .lastPoisonedVictim = null ;
229283 this .lastVictimResurrected = false ;
230284 }
231285
286+ /**
287+ * Sets the sheriff.
288+ *
289+ * @param sheriff the new sheriff player
290+ */
291+ public void setSheriff (Player sheriff ) {
292+ // Remove sheriff status from previous sheriff
293+ if (this .sheriff != null ) {
294+ this .sheriff .setSheriff (false );
295+ }
296+ this .sheriff = sheriff ;
297+ if (sheriff != null ) {
298+ sheriff .setSheriff (true );
299+ }
300+ }
301+
302+ /**
303+ * Sets whether the speaking order is reversed.
304+ *
305+ * @param reversed true for reversed order; false for normal order
306+ */
307+ public void setSpeakOrderReversed (boolean reversed ) {
308+ this .speakOrderReversed = reversed ;
309+ }
310+
311+ /**
312+ * Sets whether the sheriff was killed during the night.
313+ *
314+ * @param killed true if sheriff was killed at night; false otherwise
315+ */
316+ public void setSheriffKilledInNight (boolean killed ) {
317+ this .sheriffKilledInNight = killed ;
318+ }
319+
232320 // Winning condition checks
233321 /**
234- * Checks if werewolves meet the win condition.
235- * Werewolves win if they are alive and their count is greater than or equal to
236- * the number of alive villager-camp players.
322+ * Checks if werewolves meet the win condition. Werewolves win if: 1. All villagers (ordinary
323+ * villagers) are dead, OR 2. All god roles (seer, witch, hunter) are dead
237324 *
238325 * @return true if werewolves win; false otherwise
239326 */
240327 public boolean checkWerewolvesWin () {
241328 int aliveWerewolves = getAliveWerewolves ().size ();
242- int aliveVillagers = getAliveVillagers ().size ();
243- return aliveWerewolves > 0 && aliveWerewolves >= aliveVillagers ;
329+ if (aliveWerewolves == 0 ) {
330+ return false ;
331+ }
332+
333+ // Check if all ordinary villagers are dead
334+ boolean allVillagersDead =
335+ getAlivePlayers ().stream ().noneMatch (p -> p .getRole () == Role .VILLAGER );
336+
337+ // Check if all god roles are dead
338+ boolean allGodsDead =
339+ getAlivePlayers ().stream ()
340+ .filter (
341+ p ->
342+ p .getRole () == Role .SEER
343+ || p .getRole () == Role .WITCH
344+ || p .getRole () == Role .HUNTER )
345+ .count ()
346+ == 0 ;
347+
348+ return allVillagersDead || allGodsDead ;
244349 }
245350
246351 /**
247- * Checks if villagers meet the win condition.
248- * Villagers win when all werewolves have been eliminated.
352+ * Checks if villagers meet the win condition. Villagers win when all werewolves have been
353+ * eliminated.
249354 *
250355 * @return true if villagers win; false otherwise
251356 */
0 commit comments