maletaja81
maletaja81
  • Threads: 6
  • Posts: 12
Joined: Jun 5, 2014
June 9th, 2014 at 6:26:42 AM permalink
I would like to program some scripts where to start?
For example roulette. Program makes million of spins we know payouts. Program shows roulette edge.
Or Blackjack should we hit 15 vs 16 or not
MangoJ
MangoJ
  • Threads: 10
  • Posts: 905
Joined: Mar 12, 2011
June 9th, 2014 at 7:05:16 AM permalink
Start with roulette.
geoff
geoff
  • Threads: 3
  • Posts: 368
Joined: Feb 19, 2014
June 9th, 2014 at 7:31:34 AM permalink
Quote: maletaja81

I would like to program some scripts where to start?
For example roulette. Program makes million of spins we know payouts. Program shows roulette edge.
Or Blackjack should we hit 15 vs 16 or not



Well what do you mean by where to start? Do you already know python and are asking how to design the program or are you asking how to learn the language to do what you want?
ssho88
ssho88
  • Threads: 53
  • Posts: 657
Joined: Oct 16, 2011
February 19th, 2019 at 6:28:31 PM permalink
Quote: geoff

Well what do you mean by where to start? Do you already know python and are asking how to design the program or are you asking how to learn the language to do what you want?



I have just started to learn python, possible for you to write python script to find the house edge of single zero roulette game and post it here ? What good RNG are you using ? Script for RNG( random number generator) ?

With your help I may modify it and use it to simulate other games......
ThatDonGuy
ThatDonGuy
  • Threads: 117
  • Posts: 6219
Joined: Jun 22, 2011
February 19th, 2019 at 6:43:51 PM permalink
Quote: ssho88

I have just started to learn python, possible for you to write python script to find the house edge of single zero roulette game and post it here ? What good RNG are you using ? Script for RNG( random number generator) ?


To find a proper house edge, you don't use an RNG; you use "brute force" to go through every possible result, multiplied by the probability of that result.

Python has an RNG in integers called random.randrange; randrange(100), for example, will return a random integer from 0 to 99 inclusive. You initialize it using random.seed(); this sets the initial parameters based on the current date and time.

Keep in mind that, for complicated games like blackjack, it's not so much being able to write the code, as knowing what code to write.
ssho88
ssho88
  • Threads: 53
  • Posts: 657
Joined: Oct 16, 2011
February 19th, 2019 at 8:19:40 PM permalink
Quote: ThatDonGuy

To find a proper house edge, you don't use an RNG; you use "brute force" to go through every possible result, multiplied by the probability of that result.

Python has an RNG in integers called random.randrange; randrange(100), for example, will return a random integer from 0 to 99 inclusive. You initialize it using random.seed(); this sets the initial parameters based on the current date and time.

Keep in mind that, for complicated games like blackjack, it's not so much being able to write the code, as knowing what code to write.




I know how to calculate the roulette house edge with simple hand calculations and I have learned VBA to write code for Blackjack, Three card poker, poker, 80++baccarat side bets and many other games . . . .

Unfortunately VBA is running quite slow compare to Python( I was told that !), I want something that can do combination analysis FAST(within seconds) based on exact remaining deck composition(especially for baccarat sidebets that involve suits !), my current VBA program take 20 minutes to complete CA for baccarat sidebets that involve suits( which is TOO SLOW !). So I have decided to learn new language python . . . .If you can show me the simple python codes to calculate roulette house edge . . .then from there I may learn fast and from there expand to other games . . . . .I know that RNG is for simulations( to find betting opportunities, ev/shoe . . .) and CA(to find house edge and does not required RNG).

Is python built-in RNG comparable to Mersenne Twister ?


p/s : House edge by billion rounds of simulation should match the house edge by CA, I normally use both method to verify the correct house edge.

Thanks
Last edited by: ssho88 on Feb 19, 2019
Dalex64
Dalex64
  • Threads: 1
  • Posts: 1067
Joined: Feb 10, 2013
February 20th, 2019 at 5:37:24 AM permalink
Python is not known for it's speed, especially when executing FOR loops. It should be faster than VBA, though.

Python is easy to learn and use, and after you get down the basics, you can speed it up with external libraries such as numpy, scipy, and numba.

Python uses the Mersene Twister.
https://docs.python.org/3/library/random.html
ssho88
ssho88
  • Threads: 53
  • Posts: 657
Joined: Oct 16, 2011
February 20th, 2019 at 6:08:30 AM permalink
Quote: Dalex64

Python is not known for it's speed, especially when executing FOR loops. It should be faster than VBA, though.

Python is easy to learn and use, and after you get down the basics, you can speed it up with external libraries such as numpy, scipy, and numba.

Python uses the Mersene Twister.
https://docs.python.org/3/library/random.html




Thanks !
ssho88
ssho88
  • Threads: 53
  • Posts: 657
Joined: Oct 16, 2011
February 25th, 2019 at 4:36:26 PM permalink
Quote: Dalex64

Python is not known for it's speed, especially when executing FOR loops. It should be faster than VBA, though.

Python is easy to learn and use, and after you get down the basics, you can speed it up with external libraries such as numpy, scipy, and numba.

Python uses the Mersene Twister.
https://docs.python.org/3/library/random.html




Hi,

I need your/other comments on this python codes(cards shuffling), is it any way to shorten the code(especially line 7) so that it can run faster ? See link : https://imgur.com/a/0j18RSR

ssho88
Dalex64
Dalex64
  • Threads: 1
  • Posts: 1067
Joined: Feb 10, 2013
February 25th, 2019 at 7:32:55 PM permalink
I am assuming that code came from here: https://www.programiz.com/python-programming/examples/shuffle-card

I would do that quite a bit differently.

First off, though, I know a lot of the people who do this sort of thing for money use C for raw blazing speed, and lots of bitmask and integer operations.

Here is how you can do something similar in python.

First I would represent the deck as an ordered list of integers. 4 bits of the integers would hold the value of the card, 2 bits to hold the suit, then more bits to hold the deck number.
To avoid any lookup tables at all, you can use a bit for each value, a bit for each suit, and a bit for each deck.

That can list of numbers can be generated on the outside, and then created in your program as a literal numpy array. No need to make that up every time you run the program.

Then instead of shuffling the whole list, I would grab the cards I needed from it. This will work if you need enough to simulate a hand at a time out of a fresh deck, for instance

See numpy random choice without replacement.
https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.choice.html

You can also shuffle the whole array:
https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.shuffle.html

HERE IS THE SHORT VERSION:
do the work of generating the deck ahead of time.

If you want to keep using human readable strings, just spell out the whole two dimensional array as a literal array in a separate file and import it.

For example, file 8decks.py would be
deck = [[1,"spades"], [2,"spades],... Etc

Then import it
from 8decks import deck

That should be faster.
Last edited by: Dalex64 on Feb 25, 2019
ssho88
ssho88
  • Threads: 53
  • Posts: 657
Joined: Oct 16, 2011
February 25th, 2019 at 7:49:05 PM permalink
Quote: Dalex64

I am assuming that code came from here: https://www.programiz.com/python-programming/examples/shuffle-card

I would do that quite a bit differently.

First off, though, I know a lot of the people who do this sort of thing for money use C for raw blazing speed, and lots of bitmask and integer operations.

Here is how you can do something similar in python.

First I would represent the deck as an ordered list of integers. 4 bits of the integers would hold the value of the card, 2 bits to hold the suit, then more bits to hold the deck number.

That can list of numbers can be generated on the outside, and then created in your program as a literal numpy array. No need to make that up every time you run the program.

Then instead of shuffling the whole list, I would grab the cards I needed from it. This will work if you need enough to simulate a hand at a time out of a fresh deck, for instance

See numpy random choice without replacement.
https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.choice.html

You can also shuffle the whole array:
(Saving progress, more to come)




Yes, the cards only need to be generated once and can be "re-use" in next shuffling . . . . and normally it is required to shuffle ALL cards as the game will be play until near the bottom of the deck( normally cards will be dealt 7/8 whole shoe)
Dalex64
Dalex64
  • Threads: 1
  • Posts: 1067
Joined: Feb 10, 2013
February 25th, 2019 at 7:54:09 PM permalink
I added some more info to my original reply.
walshmergak
walshmergak
  • Threads: 0
  • Posts: 1
Joined: May 11, 2020
May 11th, 2020 at 12:08:08 AM permalink
check this .... python tutorial

  • Jump to: