Beispiel #1
0
    def launch(self, proc_number):
        """Runs a simulation
        :return: double: the ratio of successful hands over total hands
        """

        logging.info(process.current_process().name + ': Plot data will be collected every {} runs'.
                     format(self.collect_frequency))

        success_count = 0
        deck = Deck()

        for sim_nb in range(self.number_simulations):
            deck.initialise()
            card_rules=CardRules(deck)
            card_rules.set_target(self.target_rank)

            cards_in_hand = self.get_starting_hand(deck, self.starting_cards)

            for v in range(self.number_of_draws):
                retained_cards = card_rules.apply_rules(cards_in_hand)
                #draw additional cards from deck to make a full hand
                dealer_cards = [deck.get_card() for c in
                                range(self.MAX_CARDS_IN_HAND - len(retained_cards))]
                cards_in_hand=retained_cards+dealer_cards

            # at the end of the last draw we check the final hand to see if we hit the target
            is_success=card_rules.check_success(cards_in_hand)
            if is_success:
                success_count += 1
            if self.is_plot and sim_nb % self.collect_frequency == 0 and sim_nb > 0:
                self._intermediate_results.append((success_count) / sim_nb)

        self._simulation_result = (success_count)/self.number_simulations
        return self