Change witch function

This commit is contained in:
yoxu 2025-09-04 23:17:30 +02:00
commit 9e8b7a3e40
Signed by: yoxu
GPG key ID: CC1DC0EBE5E7D4E8

55
main.py
View file

@ -120,6 +120,31 @@ class Game:
log.debug("Fuzz score: %s" % fuzz_score) log.debug("Fuzz score: %s" % fuzz_score)
return fuzz_player return fuzz_player
def choose_between(self, options):
#Prompt the user to choose between options until a valid one is entered
options_available = ', '.join(map(str, options))
#Make a prompt with a list of options, accepting either a list or a tuple.
prompt = f"Choose between {options_available}: "
while True:
selected = input(prompt)
if selected in options:
return selected
# fuzzy matching
match = process.extract(selected, options, limit=1)
log.debug(match)
if match:
fuzz_option, fuzz_score = match[0][0], match[0][1] #options, score
log.debug(fuzz_option)
log.debug(fuzz_score)
if fuzz_score >= 60:
log.info("You meant %s!", fuzz_option)
log.debug("Fuzz score: %s" % fuzz_score)
return fuzz_option
# ------------------------- # -------------------------
# game actions # game actions
# ------------------------- # -------------------------
@ -248,35 +273,37 @@ class Game:
@role @role
def witch(self) -> None: def witch(self) -> None:
"""Interactively choose to kill or revive someone""" """Interactively choose to kill or revive someone"""
log.info("Choose if you want to use your revive potion") log.info("With the Revive Potion, you can revive someone, and with the Death Potion, you can kill someone. You can only use each potion once, and you can also choose to do nothing.")
print(self.players) if len(self.used_potions) == 2:
log.info("You already used all of your potions. ")
else:
while True: while True:
potionchoice = input("What do you want to use Revive or Death potion: ") options = ("Death", "Revive", "Nothing")
potionchoice = self.choose_between(options)
if potionchoice == "Revive" and "Revive" not in self.used_potions: if potionchoice == "Revive" and "Revive" not in self.used_potions:
player = self.select_someone() player = self.select_someone()
if player in self.dead_this_night: if player in self.dead_this_night:
self.used_potions.append("Revive") self.used_potions.append("Revive")
self.revive(player) self.revive(player)
return return
elif player not in self.dead_this_night: elif player not in self.dead_this_night and not self.players[player].alive:
log.info("This player didn't died this night.") log.info("You cannot bring this person back to life because they have been buried.")
elif "Revive" not in self.used_potions: else:
log.info("This potion is already used.") log.info("This player is not dead.")
elif potionchoice == "Death" and "Death" not in self.used_potions: elif potionchoice == "Death" and "Death" not in self.used_potions:
player = self.select_someone() player = self.select_someone()
if self.players[player]: if self.players[player].alive:
self.used_potions.append("Death") self.used_potions.append("Death")
self.kill(player) self.kill(player)
return return
elif not self.players[player]: elif not self.players[player].alive:
self.used_potions.append("Death") self.used_potions.append("Death")
return return
elif potionchoice in self.used_potions: elif potionchoice == "Nothing":
log.info("You already used all of your potions") log.info("You are not doing anything tonight.")
return return
else: elif potionchoice in self.used_potions:
log.info("Please write Revive or Death") log.info("You already used this potion.")
# ------------------------- # -------------------------
# game flow # game flow