# Money bag alghorithm

This topic is 4060 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi all. I have to make one simple algorithm, but I'm still in doubt how to do it. It is about simple game. Say person A have 1.000 gold and he have to guess a number from 1 to 10. He puts 1,2 or 3 gold on table and make a guess. Winning numbers are from 6 to 10, and loosing numbers from 1 to 5. Person B imagine one number, write it down, person A make a guess. If person A wins, he double his bet and put won money in a bag (1 become 2, 2-4 and 3 -6). If he loose he just loose a money. Well the tricky part comes. How can I achieve that person A after spending all his money on gambling have exact sum in his bag (1.000 gold)? thanks in advance

##### Share on other sites
Quote:
 Original post by streamerHow can I achieve that person A after spending all his money on gambling have exact sum in his bag (1.000 gold)?

I'm not sure I understand this. Are you asking how you could ensure that no matter what betting the player does, he/she will always end up with 1,000 gold? Or are you asking how you can check if the player has won exactly 1,000 gold? Please explain the situation again, if you will. Thanks.

##### Share on other sites
Yes I want to ensure that no matter what betting the player does, he/she will always end up with exact sum he/she is started with (in this example 1,000 gold).
Person B will be actually a program that decides player's chances to win/lose.

##### Share on other sites
Your game description is confused. If I understand correctly, the world chooses a number between 1 and 10. The player bids a sum and attempts to guess the number. He gets double his initial bid if he guesses, and loses his bid otherwise.

Assuming an intelligent player, the optimal strategy for the opponent is random choice. When the player bids a sum, he therefore has a probability p(win) = 0.1 and a probability p(lose) = 0.9 of losing. Therefore, no matter what the player bids on, the expected amount of money gained for a bid of x is v(win) p(win) + v(lose) p(lose) = 2*x*0.1 + 0*0.9 = 0.2 x. If you consider enough repetitions to play the initial 1000, then the total expected gain would be 200. The variance decreases when the sums that the player bids are smaller.

In practice you cannot guarantee a gain larger than 0 (what if the player always loses?).

##### Share on other sites
I'll try to wrote it differently.
There is Player and CPU. Player has 1000 gold in pocket.
CPU guess number 1 or 2
Player places the bid 1,2 or 3 gold
Player guess the number
If player guessed the number he gets double of his bid otherwise he lose his money
If player won money he puts won money in the bag
Game ends when player have no money in his pocket.
Won money is in the bag (and he cannot play with that money)

How can I achieve that player on the end of game has 1000 gold in bag?

##### Share on other sites
If you consider the random optimal strategy ToohrVyk explains, the game is equivalent to a simplified version of roulette, and if it's random it's random.
What you ask for is a fixed, completely cheating roulette: you need to make up wins and losses arbitrarily to obtain the desired sum.
Unfortunately you need either prescience or a very constrained system, to know how many times and how much the player will gamble; at each point you need to guarantee that enough gambles, and of the appropriate value, will be made to compensate the apparently random results of previous rounds.
You could settle for more realistic objectives, like letting the player gamble freely and randomly, then forcing him to leave if he wins or loses too much, and subsequently make him get or lose some money with any excuse necessary to compensate wins or losses.
Of course an exact compensation leaving the character as wealthy as he started will be perceived as very artificial, and worse it would make the gambling completely pointless unless it has non-monetary consequences.

##### Share on other sites
The only way you can do this is to constrain the player into playing a fixed number of times. If you know the number of times he will play it's easy to design an algorithm that will always leave him even, but without that constraint there is no way of doing it.

##### Share on other sites
Quote:
 Original post by tok_juniorThe only way you can do this is to constrain the player into playing a fixed number of times. If you know the number of times he will play it's easy to design an algorithm that will always leave him even, but without that constraint there is no way of doing it.

Huh?

If I swear to play this game exactly five times, what's your proposed strategy? And how can you possibly account for the case where I lose each time?

The only way I can see to win such a game is if the player is allowed to go infinitely into debt. That way, putting the same amount of gold down each time will send you on a random walk that is infinitely-likely to get you back to the starting point at some undetermined point in the future (well, an infinity of them).

Of course, the condition that the game ends when the money runs out removes any chance of such a strategy existing. This is why the seemingly attractive 'double-or-quits' roulette martingale doesn't work (and has ruined so many poor suckers [rolleyes]).

In other words, no strategy exists, and the player can do whatever the hell they want, without it making any predictable difference.

##### Share on other sites
I Think what tok_junior is getting at, is that if you know the player will run exactly 10 rounds, than you
can do 5 random runs, then predict based on the first 5 exactly what the next 5 runs have to be to get the desired amount.
But only if you know the bet, meaning it cant be 1,2,3. it'd have to be a single fixed sum.

and by know what they have to be, i mean if you got 2 losses, you need 1 win. so it cheats and gives you the win.

##### Share on other sites
Not sure if this is what you're thinking of, but the Gamblers Problem can be solved using reinforcement learning. Some aspects of that problem look similar to what you are describing

• 33
• 12
• 10
• 9
• 9
• ### Forum Statistics

• Total Topics
631352
• Total Posts
2999486
×