def test_blackjack_with_one_ace(self): self.player_hand.append(("Spades", "Ace")) self.assertEqual(player_is_bust(self.player_hand), False) self.player_hand.append(("Spades", "Jack")) self.assertEqual(player_is_bust(self.player_hand), False) self.player_hand.append(("Spades", "Queen")) self.assertEqual(player_is_bust(self.player_hand), False) self.assertEqual(blackjack(self.player_hand), True)
def test_blackjack_with_no_aces(self): self.player_hand.append(("Spades", 2)) self.assertEqual(player_is_bust(self.player_hand), False) self.player_hand.append(("Spades", 9)) self.assertEqual(player_is_bust(self.player_hand), False) self.player_hand.append(("Spades", 4)) self.assertEqual(player_is_bust(self.player_hand), False) self.player_hand.append(("Spades", 6)) self.assertEqual(blackjack(self.player_hand), True)
def execute_play(game_id): """This function takes the name of a mini-game and then calls it. The game is then played by the player, if the player loses the mini-game, the player must "have a drink", which is implemented by a counter. If the player wins the mini-game, then the player doesn't incur any "drinking" penalties, i.e. the counter remains the same. """ global alcoholCounter global winCounter if game_id == "rps": # RPS works fine if current_room == rooms["Tiger Tiger"]: alc, win = rps() if alc == True and win == False: alcoholCounter += 1 elif alc == False and win == True: winCounter += 1 else: print("You cannot play that game here.") elif game_id == "hangman": # Problem! Hangman won't seem to reset when you play it again! if current_room == rooms["Students Union"]: alcFromHangman = exec_hangman() if alcFromHangman < 6: winCounter += 1 alcoholCounter += alcFromHangman else: print("You cannot play that game here.") elif game_id == "fetch": # Works fine. if current_room == rooms["Retros"]: fetch() else: print("You cannot play that game here.") elif game_id == "riddle": # Works fine. if current_room == rooms["Pryzm"]: riddleNumber = random.randint(1, 6) if (riddleNumber == 1): alcFromRiddle, winFromRiddle = riddle_one() if (alcFromRiddle == True and winFromRiddle == False): alcoholCounter += 1 else: winCounter += 1 if (riddleNumber == 2): alcFromRiddle, winFromRiddle = riddle_two() if (alcFromRiddle == True and winFromRiddle == False): alcoholCounter += 1 else: winCounter += 1 if (riddleNumber == 3): alcFromRiddle, winFromRiddle = riddle_three() if (alcFromRiddle == True and winFromRiddle == False): alcoholCounter += 1 else: winCounter += 1 if (riddleNumber == 4): alcFromRiddle, winFromRiddle = riddle_four() if (alcFromRiddle == True and winFromRiddle == False): alcoholCounter += 1 else: winCounter += 1 if (riddleNumber == 5): alcFromRiddle, winFromRiddle = riddle_five() if (alcFromRiddle == True and winFromRiddle == False): alcoholCounter += 1 else: winCounter += 1 else: print("You cannot play that game here.") elif game_id == "numberguesser": # Works fine. if current_room == rooms["Glam"]: pass alcoholCounter += number_guesser() winCounter += 1 else: print("You cannot play that game here.") elif game_id == "blackjack": # Untested if current_room == rooms["Live Lounge"]: pass alcoholCounter += blackjack() winCounter += 1 else: print("You cannot play that game here.") elif game_id == "mastermind": # Works fine. if current_room == rooms["Unse Unse Unse"]: alcoholCounter += mastermind() winCounter += 1 else: print("You cannot play that game here.") else: print("This doesn't make sense.") print("Overall, you have consumed " + str(alcoholCounter) + " units of alcohol.") print("Overall, you have won the mini-games " + str(winCounter) + " times.") time.sleep(3)
def test_one_ace_worth_eleven_points_no_blackjack(self): self.player_hand.append(("Spades", "Ace")) self.assertEqual(player_is_bust(self.player_hand), False) self.player_hand.append(("Spades", 9)) self.assertEqual(calc_score(self.player_hand), 20) self.assertEqual(blackjack(self.player_hand), False)
def test_one_ace_worth_eleven_points_blackjack(self): self.player_hand.append(("Spades", "Ace")) self.assertEqual(player_is_bust(self.player_hand), False) self.player_hand.append(("Spades", "Jack")) self.assertEqual(blackjack(self.player_hand), True)
# -*- coding: utf-8 -*- """ Created on Sun Jun 28 12:46:40 2020 @author: hugosousa """ from blackjack import * from agents import Q_Agent import matplotlib.pyplot as plt p1 = Q_Agent() p1.play(["6", "3"], ["2", "3", "2", "2"]) blackjack(p1) num_games = 1000 games = [] for _ in range(num_games): games.append(blackjack(p1)) p1.policy p1.values games = np.array(games) sum(games == 1) sum(games == 0) sum(games == -1) plt.plot(games.cumsum())
def setUp(self): self.tdeck1 = deck() self.tdeck2 = deck() self.tbj = blackjack() self.tplayer = player()