Esempio n. 1
0
    def insure(self):
        if self.phase is not "begin_game":
            raise InvalidMove("Not in proper phase. You cannot insure!")

        if self.croupier.hand.can_insure:
            self.player._balance -= 0.5 * self.bid
            self.is_insure = True
        else:
            raise InvalidMove("You cannot insure!")
Esempio n. 2
0
    def split(self):
        first_hand, second_hand = self.player.hands
        if not (first_hand.is_empty or second_hand.is_empty):
            raise InvalidMove("Already did split")

        if first_hand.cards[0].rank != first_hand.cards[1].rank:
            raise InvalidMove("Cannot split cards")

        self.player.account_balance -= self.state.bid
        second_hand.add(first_hand.cards.pop())
        first_hand.add(self.decks.get(), face_up=True)
        second_hand.add(self.decks.get(), face_up=True)
Esempio n. 3
0
    def begin_game(self):
        if self.phase not in ["awaiting", "end_game"]:
            raise InvalidMove("Not in proper phase. You cannot begin game!")
        self.croupier.clear()
        self.player.clear()
        self.phase = "begin_game"

        self.is_insure = False
        self.player.account_balance -= self.bid
        self.statewin = 0
        self.statebid = self.bid

        if len(self.decks.cards) < 4:
            self.phase = "end_game"
            self.finish_game()

        else:
            self.croupier.hand.add(self.decks.get(), face_up=False)
            self.croupier.hand.add(self.decks.get(), face_up=True)
            self.player.hands1.add(self.decks.get(), face_up=True)
            self.player.hands1.add(self.decks.get(), face_up=True)
            self.decks.up()

            if self.player.hands1.value >= 21:
                self.player.hands1.playing = False
                self.resolve_game()
Esempio n. 4
0
    def stand2(self):
        if self.phase not in ["in_game", "begin_game"]:
            raise InvalidMove("Not in proper phase. You cannot stand!")

        self.player.hands2.playing = False
        if self.player.hands1.playing is False:
            self.resolve_game()
        else:
            self.phase = "in_game"
Esempio n. 5
0
    def hit2(self):
        if self.phase not in ["in_game", "begin_game"]:
            raise InvalidMove("Not in proper phase. You cannot hit!")
        if self.player.hands1.playing is False:
            raise InvalidMove("Hand is empty")

        if len(self.decks.cards) < 1:
            self.phase = "end_game"
            self.finish_game()

        else:
            self.player.hands2.add(self.decks.get(), face_up=True)
            self.decks.up()
            if self.player.hands2.value >= 21:
                self.player.hands2.playing = False
                if self.player.hands1.playing is False:
                    self.resolve_game()
                else:
                    self.phase = "in_game"
            else:
                self.phase = "in_game"
Esempio n. 6
0
    def split(self):
        if self.phase is not "begin_game":
            raise InvalidMove("Not in proper phase. You cannot split!")

        first_hand, second_hand = self.player.hands
        if not (first_hand.is_empty or second_hand.is_empty):
            raise InvalidMove("Already did split")

        if first_hand.cards[0].rank != first_hand.cards[1].rank:
            raise InvalidMove("Cannot split cards")

        if len(self.decks.cards) < 3:
            self.phase = "end_game"
            self.finish_game()

        else:
            self.player.account_balance -= self.bid
            second_hand.add(first_hand.cards.pop())
            first_hand.add(self.decks.get(), face_up=True)
            second_hand.add(self.decks.get(), face_up=True)
            self.decks.up()

            self.phase = "in_game"
Esempio n. 7
0
    def double_down(self):
        if self.phase is not "begin_game":
            raise InvalidMove("Not in proper phase. You cannot double down!")
        if len(self.decks.cards) < 1:
            self.phase = "end_game"
            self.finish_game()

        else:
            self.player.account_balance -= self.bid
            self.statebid *= 2
            self.player.hands1.add(self.decks.get(), face_up=True)
            self.decks.up()
            self.player.hands1.playing = False
            self.resolve_game()
Esempio n. 8
0
        def wrapper(self, *args, **kw):
            # Do not allow execution of command if not in proper phase
            if self.state.phase not in from_phases:
                raise InvalidMove("Not in proper phase")

            # Execute action and switch to target phase
            foo(self, *args, **kw)
            self.state.phase = to_phase

            # Switch if other hand is still playing, resolve if none is
            if not self.player.hand.playing:
                if self.player.other_hand.playing:
                    self.player.switch_hand()
                else:
                    self.resolve_game()
Esempio n. 9
0
 def surrender(self):
     # TODO abandon bid and start new game (open croupier's card ?)
     raise InvalidMove("Not yet implemented")
Esempio n. 10
0
 def insure(self):
     # TODO put additional 0.5 bid if croupier has ace (blackjack possibility)
     raise InvalidMove("Not yet implemented")
Esempio n. 11
0
 def account_balance(self, value: int):
     if value < 0:
         raise InvalidMove("Negative account balance is not allowed")
     self._balance = value
Esempio n. 12
0
    def finish_game(self):
        self.is_finished = True
        self.player.account_balance += self.bid

        raise InvalidMove("You finish")