updated roles, init tests, added states

This commit is contained in:
2021-03-12 00:59:38 +01:00
parent 8654e795fe
commit c6e8cc7d29
6 changed files with 193 additions and 39 deletions

View File

@@ -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)