@@ -129,25 +129,20 @@ impl Game {
129
129
( guilty, innocent)
130
130
}
131
131
132
- pub fn winner ( & self ) -> Option < EndGameCondition > {
133
- let mut winning_team = None ;
132
+ pub fn game_is_over ( & self ) -> bool {
133
+ //find list of all remaining teams
134
+ let remaining_teams: Vec < EndGameCondition > =
135
+ PlayerReference :: all_players ( self ) . into_iter ( )
136
+ . filter ( |p|p. alive ( self ) ) . map ( |p|p. end_game_condition ( self ) ) . collect ( ) ;
134
137
135
- for player_ref in PlayerReference :: all_players ( self ) {
136
- if !player_ref. alive ( self ) { continue ; }
137
- let egc = player_ref. end_game_condition ( self ) ;
138
- if egc == EndGameCondition :: None { continue ; }
139
-
140
- if let Some ( ref winning_team) = winning_team{
141
- //if there are two different teams alive then nobody won
142
- if * winning_team != egc{
143
- return None ;
144
- }
145
- } else {
146
- winning_team = Some ( egc. clone ( ) ) ;
147
- }
148
- }
149
-
150
- winning_team
138
+ //remove all duplicates from remaining_teams
139
+ let remaining_teams = remaining_teams. into_iter ( )
140
+ . collect :: < std:: collections:: HashSet < EndGameCondition > > ( ) . into_iter ( ) . collect :: < Vec < EndGameCondition > > ( ) ;
141
+
142
+ //if there is only one team left, then the game is over
143
+ remaining_teams. len ( ) <= 1
144
+
145
+ //it doesnt matter if the final team is none, because this doesnt care who won, just that game is over
151
146
}
152
147
153
148
pub fn current_phase ( & self ) -> & PhaseState {
@@ -165,7 +160,7 @@ impl Game {
165
160
166
161
if !self . ongoing { return }
167
162
168
- if let Some ( _winner ) = self . winner ( ) {
163
+ if self . game_is_over ( ) {
169
164
self . add_message_to_chat_group ( ChatGroup :: All , ChatMessage :: GameOver ) ;
170
165
self . send_packet_to_all ( ToClientPacket :: GameOver { reason : GameOverReason :: Draw } ) ;
171
166
self . ongoing = false ;
0 commit comments