Skip to content

Commit

Permalink
still there is some bugs!
Browse files Browse the repository at this point in the history
  • Loading branch information
MEgooneh committed Sep 24, 2023
1 parent 20122cd commit 669bd85
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
27 changes: 18 additions & 9 deletions core/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ def targeting(self, Game, command):
res = send_message(render.game_intro(self), render.game_report(Game, self) , command + "REMINDER: your message must include the number of player that you want to perform action on it.")
nums_in_res = re.findall(r'\d+', res)
if nums_in_res == [] :
Game.logger.warning("No player provided in targetting.")
return (None, res)
return (int(nums_in_res[0]), res)
target = int(nums_in_res[0])
if target not in Game.alive_players :
Game.logger.warning("Targeting a wrong player")
return (None, res)
return (target , res)
def vote(self, Game):
target, reason = self.targeting(
Game,
Expand Down Expand Up @@ -76,6 +81,7 @@ def healing(self, Game):
self.special_actions_log.append(f"You have healed Player number {target}")
Game.log_submit({'event' : 'healed' , 'content': {'player':target , 'reason':reason}})


class Seer(Villager):
def __init__(self, role, **kwargs):
super().__init__(role, **kwargs)
Expand All @@ -92,12 +98,11 @@ def inquiry(self, Game):
tag = "" if is_werewolf else "not"
self.special_actions_log.append(f" Player {target} is {tag} werewolf")
Game.log_submit({'event' : 'inquiried' , 'content': {'player':target , 'context': is_werewolf , 'reason':reason}})



class Game():
def __init__(self, id=1):
self.id = id
self.all_players = []
self.alive_players = []
self.dead_players = []
self.report = []
Expand Down Expand Up @@ -132,8 +137,9 @@ def set_players(self, simple_villagers_roles, werewolves_roles, medics_roles, se
werewolves = self.get_alive_werewolves()
for werewolf in werewolves:
werewolf.special_actions_log.append(f"you are werewolf and this is your team (they are all werewolf) : {werewolves}")
self.all_players = self.alive_players
def get_player(self, id):
return self.alive_players[id]
return self.all_players[id]
def get_alive_werewolves(self):
ls = list(filter(lambda player : player.type == "werewolf", self.alive_players))
# to make sure that last werewolf will make the last decision
Expand All @@ -146,6 +152,9 @@ def get_alive_seers(self):
def get_alive_villagers(self):
return list(filter(lambda player : player.type == "villager", self.alive_players))
def kill(self, Player):
if Player not in self.alive_players:
self.logger.warning("Killing an already dead guy! Skipped!")
return
self.alive_players.remove(Player)
self.dead_players.append(Player)
self.log_submit({'event' : 'killed' , 'content': {'player':Player.id}})
Expand All @@ -170,8 +179,8 @@ def check_votes(self):
# [TODO] : debugging here
votes = self.votes[-1]
if max(votes) > 1 :
votes_sorted = sorted(votes.items(), key=lambda x:x[1])
self.kill(self.alive_players[list(votes_sorted.keys())[-1]])
votes_sorted = dict(sorted(votes.items(), key=lambda x:x[1]))
self.kill(self.get_player(list(votes_sorted.keys())[-1]))
if self.is_game_end(): # to check if game is over by votes
self.save_game()
return
Expand Down Expand Up @@ -210,12 +219,12 @@ def run_night(self) :
for medic in medics:
medic.healing(self)
for seer in seers:
seer.inquiry(Game)
seer.inquiry(self)
for werewolf in werewolves:
if werewolf.rank == "leader":
werewolf.killing(Game)
werewolf.killing(self)
else:
werewolf.advicing(Game)
werewolf.advicing(self)
return


Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
langchain[openai]~=0.0
openai
langchain[openai]~=0.0

0 comments on commit 669bd85

Please sign in to comment.