From 798b4ce2761f57e93f58b20484d8c278e0826a27 Mon Sep 17 00:00:00 2001 From: yoxu Date: Thu, 4 Sep 2025 21:05:15 +0200 Subject: [PATCH 1/6] Added role witch --- .vscode/settings.json | 5 +++++ main.py | 46 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..0455c60 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "cSpell.words": [ + "potionchoice" + ] +} \ No newline at end of file diff --git a/main.py b/main.py index 9ab617f..b5185b9 100644 --- a/main.py +++ b/main.py @@ -21,6 +21,11 @@ class Game: # lovers self.lovers: Optional[Tuple[str, str]] = None + # Dead this night + self.dead_this_night: [List[str]] = [] + + # Used potions + self.used_potions: [list[str]] = [] # ------------------------- # setup / I/O # ------------------------- @@ -95,7 +100,7 @@ class Game: Prompt the user to enter a player name until a valid one is entered. Returns None on EOF/KeyboardInterrupt. """ - prompt = prompt or "Enter the name of the player: " + prompt = prompt or "Enter the name of the player: " while True: selected = input(prompt).strip() @@ -157,15 +162,18 @@ class Game: for p in self.lovers: # kill them and their lover log.debug("Killed %s", p) + self.dead_this_night.append(p) p.alive = False return # else just kill them - log.debug("Killed %s" % p) + log.info("Killed %s" % player) + self.dead_this_night.append(player) target.alive = False def revive(self, player: str) -> None: """Revive a player.""" + log.info("Players that will die this night are: %s", self.dead_this_night) if player not in self.players: log.error("Tried to revive unknown player: %s", player) return @@ -237,6 +245,38 @@ class Game: self.players[protected].protected = True log.debug("Protected: %s", protected) + @role + def witch(self) -> None: + """Interactively choose to kill or revive someone""" + log.info("Choose if you want to use your revive potion") + print(self.players) + while True: + potionchoice = input("What do you want to use Revive or Death potion: ") + if potionchoice == "Revive" and "Revive" not in self.used_potions: + player = self.select_someone() + if player in self.dead_this_night: + self.used_potions.append("Revive") + self.revive(player) + return + elif player not in self.dead_this_night: + log.info("This player didn't died this night.") + elif "Revive" not in self.used_potions: + log.info("This potion is already used.") + elif potionchoice == "Death" and "Death" not in self.used_potions: + player = self.select_someone() + if self.players[player]: + self.used_potions.append("Death") + self.kill(player) + return + elif not self.players[player]: + self.used_potions.append("Death") + return + elif potionchoice in self.used_potions: + log.info("You already used all of your potions") + return + else: + log.info("Please write Revive or Death") + # ------------------------- # game flow @@ -245,6 +285,8 @@ class Game: log.info("All the villagers fall asleep.") self.cupidon() self.savior() + self.witch() + From c55315fa3eaf0701da01639cd213a3bff9ae0192 Mon Sep 17 00:00:00 2001 From: yoxu Date: Thu, 4 Sep 2025 21:07:34 +0200 Subject: [PATCH 2/6] Edit gitignore + remove .vscode folder --- .gitignore | 2 +- .vscode/settings.json | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.gitignore b/.gitignore index 5290d13..d779048 100644 --- a/.gitignore +++ b/.gitignore @@ -199,7 +199,7 @@ cython_debug/ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore # and can be added to the global gitignore or merged into this file. However, if you prefer, # you could uncomment the following to ignore the entire vscode folder -# .vscode/ + .vscode/ # Ruff stuff: .ruff_cache/ diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 0455c60..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "cSpell.words": [ - "potionchoice" - ] -} \ No newline at end of file From 28aeb84c505e36d96224b2614f711914edc78dc6 Mon Sep 17 00:00:00 2001 From: yoxu Date: Thu, 4 Sep 2025 22:53:58 +0200 Subject: [PATCH 3/6] Change choose system for the witch and revert commit c55315fa3e --- .gitignore | 2 +- .vscode/settings.json | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .vscode/settings.json diff --git a/.gitignore b/.gitignore index d779048..5290d13 100644 --- a/.gitignore +++ b/.gitignore @@ -199,7 +199,7 @@ cython_debug/ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore # and can be added to the global gitignore or merged into this file. However, if you prefer, # you could uncomment the following to ignore the entire vscode folder - .vscode/ +# .vscode/ # Ruff stuff: .ruff_cache/ diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..0455c60 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "cSpell.words": [ + "potionchoice" + ] +} \ No newline at end of file From 9e8b7a3e4018e49ed653c3735a017da08ac2545f Mon Sep 17 00:00:00 2001 From: yoxu Date: Thu, 4 Sep 2025 23:17:30 +0200 Subject: [PATCH 4/6] Change witch function --- main.py | 85 +++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 56 insertions(+), 29 deletions(-) diff --git a/main.py b/main.py index b5185b9..f3d5024 100644 --- a/main.py +++ b/main.py @@ -23,7 +23,7 @@ class Game: # Dead this night self.dead_this_night: [List[str]] = [] - + # Used potions self.used_potions: [list[str]] = [] # ------------------------- @@ -120,6 +120,31 @@ class Game: log.debug("Fuzz score: %s" % fuzz_score) 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 # ------------------------- @@ -248,35 +273,37 @@ class Game: @role def witch(self) -> None: """Interactively choose to kill or revive someone""" - log.info("Choose if you want to use your revive potion") - print(self.players) - while True: - potionchoice = input("What do you want to use Revive or Death potion: ") - if potionchoice == "Revive" and "Revive" not in self.used_potions: - player = self.select_someone() - if player in self.dead_this_night: - self.used_potions.append("Revive") - self.revive(player) + 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.") + if len(self.used_potions) == 2: + log.info("You already used all of your potions. ") + else: + while True: + options = ("Death", "Revive", "Nothing") + potionchoice = self.choose_between(options) + if potionchoice == "Revive" and "Revive" not in self.used_potions: + player = self.select_someone() + if player in self.dead_this_night: + self.used_potions.append("Revive") + self.revive(player) + return + elif player not in self.dead_this_night and not self.players[player].alive: + log.info("You cannot bring this person back to life because they have been buried.") + else: + log.info("This player is not dead.") + elif potionchoice == "Death" and "Death" not in self.used_potions: + player = self.select_someone() + if self.players[player].alive: + self.used_potions.append("Death") + self.kill(player) + return + elif not self.players[player].alive: + self.used_potions.append("Death") + return + elif potionchoice == "Nothing": + log.info("You are not doing anything tonight.") return - elif player not in self.dead_this_night: - log.info("This player didn't died this night.") - elif "Revive" not in self.used_potions: - log.info("This potion is already used.") - elif potionchoice == "Death" and "Death" not in self.used_potions: - player = self.select_someone() - if self.players[player]: - self.used_potions.append("Death") - self.kill(player) - return - elif not self.players[player]: - self.used_potions.append("Death") - return - elif potionchoice in self.used_potions: - log.info("You already used all of your potions") - return - else: - log.info("Please write Revive or Death") - + elif potionchoice in self.used_potions: + log.info("You already used this potion.") # ------------------------- # game flow From ce60013fbd0f562e859729d2bd7c5a783e253abf Mon Sep 17 00:00:00 2001 From: yoxu Date: Sat, 6 Sep 2025 15:40:24 +0200 Subject: [PATCH 5/6] Fix witch function --- main.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index f3d5024..776255c 100644 --- a/main.py +++ b/main.py @@ -274,12 +274,13 @@ class Game: def witch(self) -> None: """Interactively choose to kill or revive someone""" 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.") + log.info("Players who might die are %s", ' '.join(map(str, self.dead_this_night))) if len(self.used_potions) == 2: log.info("You already used all of your potions. ") - else: + elif len(self.used_potions) != 2: while True: options = ("Death", "Revive", "Nothing") - potionchoice = self.choose_between(options) + potionchoice = self.choose_between(options).capitalise() if potionchoice == "Revive" and "Revive" not in self.used_potions: player = self.select_someone() if player in self.dead_this_night: @@ -288,8 +289,11 @@ class Game: return elif player not in self.dead_this_night and not self.players[player].alive: log.info("You cannot bring this person back to life because they have been buried.") - else: + elif log.info("This player is not dead.") + else: + log.info("Unknown error: Invalid player choice") + return elif potionchoice == "Death" and "Death" not in self.used_potions: player = self.select_someone() if self.players[player].alive: @@ -297,13 +301,22 @@ class Game: self.kill(player) return elif not self.players[player].alive: - self.used_potions.append("Death") + log.info("This player is already dead.") + else: + log.info("Unknown error: Invalid player choice") return elif potionchoice == "Nothing": log.info("You are not doing anything tonight.") return elif potionchoice in self.used_potions: log.info("You already used this potion.") + else: + log.critical("Unknown error: Invalid potion choice.") + return + else: + log.critical("Unknown error: Invalid check") + + # ------------------------- # game flow From a857221bed2d800727f8e717681eb52b9effec0e Mon Sep 17 00:00:00 2001 From: yoxu Date: Sat, 6 Sep 2025 20:05:20 +0200 Subject: [PATCH 6/6] Refactor witch function --- main.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index 776255c..967073b 100644 --- a/main.py +++ b/main.py @@ -275,12 +275,12 @@ class Game: """Interactively choose to kill or revive someone""" 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.") log.info("Players who might die are %s", ' '.join(map(str, self.dead_this_night))) - if len(self.used_potions) == 2: + if len(self.used_potions) >= 2: log.info("You already used all of your potions. ") - elif len(self.used_potions) != 2: + else: while True: options = ("Death", "Revive", "Nothing") - potionchoice = self.choose_between(options).capitalise() + potionchoice = self.choose_between(options).capitalize() if potionchoice == "Revive" and "Revive" not in self.used_potions: player = self.select_someone() if player in self.dead_this_night: @@ -289,7 +289,7 @@ class Game: return elif player not in self.dead_this_night and not self.players[player].alive: log.info("You cannot bring this person back to life because they have been buried.") - elif + elif self.players[player].alive: log.info("This player is not dead.") else: log.info("Unknown error: Invalid player choice") @@ -313,10 +313,6 @@ class Game: else: log.critical("Unknown error: Invalid potion choice.") return - else: - log.critical("Unknown error: Invalid check") - - # ------------------------- # game flow