Example #1
0
    def make_bet(self, current_bet):
        print('enemy bet = {0}'.format(current_bet))
        if current_bet is None:
            value = random.choice(self.dice).value
            quantity_limit = (self.total_dice - len(self.dice)) / 6

            if value > 1:
                quantity_limit *= 2

            quantity = self.count_dice(value) + random.randrange(0, ceil(quantity_limit + 1))
            bet = create_bet(quantity, value, current_bet, self, self.game)

        else:
            if self.choose_action(self.table, current_bet) == DUDO:
                return DUDO

            else:
                Action = self.choose_action(self.table, current_bet)
                act_q = current_bet.quantity + Action[0]  # quantity + action = next bet's quantity
                act_v = Action[1]
                bet = create_bet(act_q, act_v, current_bet, self, self.game)

            self.Qtable(current_bet, bet)
            print('AI bet = {0}'.format(bet))
        return bet
Example #2
0
    def make_bet(self, current_bet):
        if current_bet is None:
            value = random.choice(self.dice).value
            quantity_limit = (self.game.total_dice - len(self.dice)) / 6

            if value > 1:
                quantity_limit *= 2

            quantity = self.count_dice(value) + random.randrange(
                0, ceil(quantity_limit + 1))
            bet = create_bet(quantity, value, current_bet, self, self.game)

        else:
            if np.random.uniform() < 0.5:
                return DUDO
            else:
                value = random.choice(self.dice).value
                quantity = current_bet.quantity + 1
                if quantity > self.game.total_dice:
                    return DUDO
                else:
                    try:
                        bet = create_bet(quantity, value, current_bet, self,
                                         self.game)
                    except BetException:
                        bet = None

        return bet
Example #3
0
    def make_bet(self, current_bet):

        if current_bet is None:
            total_dice_estimate = len(self.dice) * len(self.game.players)
            value = random.choice(self.dice).value
            quantity_limit = (total_dice_estimate - len(self.dice)) / 6

            if value > 1:
                quantity_limit *= 2

            quantity = self.count_dice(value) + random.randrange(
                0, ceil(quantity_limit + 1))
            bet = create_bet(quantity, value, current_bet, self, self.game)

        else:
            if self.choose_action(self.table, current_bet) == DUDO:
                return DUDO

            else:
                Action = self.choose_action(self.table, current_bet)
                act_q = current_bet.quantity + Action[
                    0]  # quantity + action = next bet's quantity
                act_v = Action[1]
                bet = create_bet(act_q, act_v, current_bet, self, self.game)

            self.Qtable(current_bet, bet)
        return bet
Example #4
0
    def make_bet(self, current_bet):
        if current_bet is None:
            value = random.choice(self.dice).value
            quantity_limit = (self.total_dice - len(self.dice)) / 6

            if value > 1:
                quantity_limit *= 2

            quantity = self.count_dice(value) + random.randrange(
                0, ceil(quantity_limit + 1))
            bet = create_bet(quantity, value, current_bet, self, self.game)

        else:
            # Estimate the probability of current bet
            P_current = self.prob(
                self.total_dice,
                current_bet.quantity - self.count_dice(current_bet.value),
                current_bet.value)
            # Estimate the number of dice in the game with the bet's value
            if current_bet.value == 1 or self.game.is_palifico_round():
                # There should be twice as many of any value than 1
                limit = ceil(self.total_dice / 6.0) + random.randrange(
                    0, ceil(self.total_dice / 4.0))
            else:
                limit = ceil(self.total_dice / 6.0) * 2 + random.randrange(
                    0, ceil(self.total_dice / 4.0))
            if current_bet.quantity >= limit or P_current < 0.1:
                return DUDO
            else:
                bet = None
                while bet is None:
                    if self.game.is_palifico_round(
                    ) and self.palifico_round == -1:
                        # If it is a Palifico round and the player has not already been palifico,
                        # the value cannot be changed.
                        value = current_bet.value
                        quantity = current_bet.quantity + 1
                    else:
                        value = random.choice(self.dice).value
                        if value == 1:
                            if current_bet.value > 1:
                                quantity = int(ceil(current_bet.quantity /
                                                    2.0))
                            else:
                                quantity = current_bet.quantity + 1
                        else:
                            if current_bet.value == 1:
                                quantity = current_bet.quantity * 2 + 1
                            else:
                                quantity = current_bet.quantity + 1

                    try:
                        bet = create_bet(quantity, value, current_bet, self,
                                         self.game)
                    except BetException:
                        bet = None

        return bet
Example #5
0
	def make_bet(self, current_bet):
		total_dice_estimate = len(self.dice) * len(self.game.players)
		if current_bet is None:
			# CPU is the first player, so make a conservative estimate
			value = random.choice(self.dice).value
			quantity_limit = (total_dice_estimate - len(self.dice))/6
			if value > 1:
				quantity_limit *= 2
			quantity = self.count_dice(value) + random.randrange(0, quantity_limit + 1)
			bet = create_bet(quantity, value, current_bet, self, self.game)
		else:
			# Estimate the number of dice in the game with the bet's value
			if current_bet.value == 1 or self.game.is_palifico_round():
				# There should be twice as many of any value than 1
				limit = ceil(total_dice_estimate/6.0) + random.randrange(0, ceil(total_dice_estimate/4.0))
			else:
				limit = ceil(total_dice_estimate/6.0) * 2 + random.randrange(0, ceil(total_dice_estimate/4.0))
			if current_bet.quantity >= limit:
				return DUDO
			else:
				bet = None
				while bet is None:
					if self.game.is_palifico_round() and self.palifico_round == -1:
						# If it is a Palifico round and the player has not already been palifico,
						# the value cannot be changed.
						value = current_bet.value
						quantity = current_bet.quantity + random.randrange(0, 2)
					else:
						value = random.choice(self.dice).value
						if value == 1:
							if current_bet.value > 1:
								quantity = int(ceil(current_bet.quantity/2.0))
							else:
								quantity = current_bet.quantity + random.randrange(0, 2)
						else:
							if current_bet.value == 1:
								quantity = current_bet.quantity * 2 + 1
							else:
								quantity = current_bet.quantity + random.randrange(0, 2)
					try:
						bet = create_bet(quantity, value, current_bet, self, self.game)
					except BetException:
						bet = None

		return bet
Example #6
0
    def make_bet(self, current_bet):
        total_dice_estimate = len(self.dice) * len(self.game.players)
        if current_bet is None:
            value = random.choice(self.dice).value
            quantity_limit = (total_dice_estimate - len(self.dice)) / 6

            if value > 1:
                quantity_limit *= 2

            quantity = self.count_dice(value) + random.randint(
                0, ceil(quantity_limit + 1))
            bet = create_bet(quantity, value, current_bet, self, self.game)

        else:
            # Estimate the number of dice in the game with the bet's value
            limit = ceil(total_dice_estimate / 6.0) * 2 + random.randrange(
                0, ceil(total_dice_estimate / 4.0))
            if current_bet.quantity >= limit:
                return DUDO
            else:
                bet = None
                while bet is None:
                    if self.game.is_palifico_round(
                    ) and self.palifico_round == -1:
                        # If it is a Palifico round and the player has not already been palifico,
                        # the value cannot be changed.
                        value = current_bet.value
                        quantity = current_bet.quantity + 1
                    else:
                        value = random.choice(self.dice).value
                        quantity = current_bet.quantity + 1

                    try:
                        bet = create_bet(quantity, value, current_bet, self,
                                         self.game)
                    except BetException:
                        bet = None

        return bet
Example #7
0
    def make_bet(self, current_bet):
        if current_bet is None:
            total_dice_estimate = len(self.dice) * len(self.game.players)
            value = random.choice(self.dice).value
            quantity_limit = (total_dice_estimate - len(self.dice)) / 6

            if value > 1:
                quantity_limit *= 2

            quantity = self.count_dice(value) + random.randrange(
                0, ceil(quantity_limit + 1))
            bet = create_bet(quantity, value, current_bet, self, self.game)
        else:
            p = self.prob(
                self.game.total_dice - len(self.dice),
                current_bet.quantity - self.count_dice(current_bet.value),
                current_bet.value)
            abservation = np.array([
                current_bet.value, current_bet.quantity, p,
                self.game.total_dice
            ])
            action = self.method.choose_action(abservation)
            if action == 0:
                bet = DUDO
                reward = self.reward(current_bet) * 10 * (
                    self.game.play_no - len(self.game.players))
            else:
                value = action % 6
                quantity = ceil(action / 6) + current_bet.quantity
                try:
                    bet = create_bet(quantity, value, current_bet, self,
                                     self.game)
                    reward = 1 - self.reward(bet)
                except BetException:
                    bet = None
                    reward = 0
            self.record.append((abservation, action, reward))
        return bet
Example #8
0
    def make_bet(self, current_bet):
        string = 'Your turn. Your dice:'
        for die in self.dice:
            string += ' {0}'.format(die.value)
        print(string)
        bet = None
        while bet is None:
            bet_input = input('> ')
            if bet_input.lower() == 'dudo':
                return DUDO
            if 'x' not in bet_input:
                print(BAD_BET_ERROR)
                continue
            bet_fields = bet_input.split('x')
            if len(bet_fields) < 2:
                print(BAD_BET_ERROR)
                continue

            try:
                quantity = int(bet_fields[0])
                value = int(bet_fields[1])

                try:
                    bet = create_bet(quantity, value, current_bet, self,
                                     self.game)
                except InvalidDieValueException:
                    bet = None
                    print(INVALID_DIE_VALUE_ERROR)
                except NonPalificoChangeException:
                    bet = None
                    print(NON_PALIFICO_CHANGE_ERROR)
                except InvalidNonWildcardQuantityException:
                    bet = None
                    print(INVALID_NON_WILDCARD_QUANTITY)
                except InvalidWildcardQuantityException:
                    bet = None
                    print(INVALID_WILDCARD_QUANTITY)
                except InvalidBetException:
                    bet = None
                    print(INVALID_BET_EXCEPTION)
            except ValueError:
                print(BAD_BET_ERROR)

        return bet
Example #9
0
	def make_bet(self, current_bet):
		string = 'Your turn. Your dice:'
		for die in self.dice:
			string += ' {0}'.format(die.value)
		print string
		bet = None
		while bet is None:
			bet_input = raw_input('> ')
			if bet_input.lower() == 'dudo':
				return DUDO
			if 'x' not in bet_input:
				print BAD_BET_ERROR
				continue
			bet_fields = bet_input.split('x')
			if len(bet_fields) < 2:
				print BAD_BET_ERROR
				continue

			try:
				quantity = int(bet_fields[0])
				value = int(bet_fields[1])

				try:
					bet = create_bet(quantity, value, current_bet, self, self.game)
				except InvalidDieValueException:
					bet = None
					print INVALID_DIE_VALUE_ERROR
				except NonPalificoChangeException:
					bet = None
					print NON_PALIFICO_CHANGE_ERROR
				except InvalidNonWildcardQuantityException:
					bet = None
					print INVALID_NON_WILDCARD_QUANTITY
				except InvalidWildcardQuantityException:
					bet = None
					print INVALID_WILDCARD_QUANTITY
				except InvalidBetException:
					bet = None
					print INVALID_BET_EXCEPTION
			except ValueError:
				print BAD_BET_ERROR

		return bet