updated roles, init tests, added states
This commit is contained in:
@@ -1,3 +1,60 @@
|
||||
import models
|
||||
from pywerwolf import models
|
||||
import typing as t
|
||||
import uuid
|
||||
|
||||
|
||||
class Game(object):
|
||||
state: models.GameState
|
||||
|
||||
def __init__(self, game_id: t.Union[str, uuid.UUID] = None):
|
||||
if game_id is None:
|
||||
self.create_new_game_state()
|
||||
else:
|
||||
self.load_game_state(game_id)
|
||||
|
||||
def create_new_game_state(self):
|
||||
pass
|
||||
|
||||
def load_game_state(self, game_id: t.Union[str, uuid.UUID]):
|
||||
pass
|
||||
|
||||
def valid_game(self):
|
||||
# check if game has been created or loaded
|
||||
return True
|
||||
|
||||
def check_victory(self):
|
||||
"""check for a winner of the current game"""
|
||||
if not self.valid_game():
|
||||
return None
|
||||
|
||||
if self.state.currentPhase == models.GamePhase.Award:
|
||||
return True
|
||||
|
||||
if sum(1 for _ in self.werewolfes) > 0:
|
||||
if sum(1 for _ in self.villagers) <= 0:
|
||||
return models.RoleGroup.Werewolfs
|
||||
pass
|
||||
else:
|
||||
return models.RoleGroup.Villagers
|
||||
|
||||
if sum(1 for _ in self.player_alive) == 2:
|
||||
living = list(self.player_alive)
|
||||
if living[0].lovedOne == living[1]:
|
||||
return models.RoleGroup.LovedOnes
|
||||
|
||||
return None
|
||||
|
||||
@property
|
||||
def player_alive(self):
|
||||
"""Generator for players still alive"""
|
||||
return filter(lambda x: x.alive, self.state.players)
|
||||
|
||||
@property
|
||||
def werewolfes(self):
|
||||
"""Generator for players that are werewolfes"""
|
||||
return filter(models.Player.isWerwolf, self.player_alive)
|
||||
|
||||
@property
|
||||
def villagers(self):
|
||||
"""Generator for players that are villagers"""
|
||||
return filter(not (models.Player.isWerwolf), self.player_alive)
|
||||
|
||||
Reference in New Issue
Block a user