Author Topic: From the Trenches :: Issue #1  (Read 3881 times)

Offline codestryke

  • Administrator
  • Level 33
  • *****
  • Posts: 588
  • Reputation: +22/-0
    • View Profile
    • eXtremeCast Games
From the Trenches :: Issue #1
« on: December 13, 2006, 05:12:51 PM »
Ok I'm going to start a series of articles, topics that talk about game design, programming and admin'ing an online game that I've picked up along the way. I'm not sure with what frequency these articles will get published, and with the holidays upon us they will probably dip for a couple weeks ;) However I've run across a LOT of things that I've learned that my be of some use to any budding game programmer / designer...

My apologies Zeg if this was posted in the wrong forum ;)

Durning the time of running BordelloBattles I decided to add a casino option to the game (I think the wife and I just got back from Vegas so I was full of ideas LOL). I hunted around and really couldn't find any Blackjack or Poker programs written in PHP, PERL or ASP that were really of any worth.. Those that I did find wanted me to pay for the scripts, pfft I can code so I'll just write them myself. Writing those two (blackjack and video poker) were great programming exercises.. Lots of conditionals to check for, lot of little things you need to keep track of etc etc... Anyways those two items aren't the focus of the article the real focus is on the slots I also added.

The slots, at the time, were the easiest to code, heck take a bunch of pictures put them in a set of three arrays and randomize one from each array.. If they match a given sequence you win X amount.. Not the most difficult thing to write LOL... So I put the slots up along with the blackjack and video poker and it was a huge success in the game.. Blackjack took a lot of work because I wasn't fully aware of ALL the rules and just coded a quick version of it.. After the players got a hold of it they wanted double downs, splits and every other damn that a blackjack table had...

So the game went 3-4 rounds (months) without any problems with the casino.... Then it happened a bunch of very "creative" players had found out that the slots won more often then they lost..So these "creative" players all downloaded Opera and basically had Opera automatically "click" the bet button every 20 seconds and were basically making HUGE amounts of cash off the slot machines...

Anyone know why?

I'll tell ya, for those that don't know.. It's because rand and mt_rand randomize numbers in an even pattern, or try to at least. Because of this the slots were winning more then they were losing ;) I tried a number of hacks to try and get the slots to return a set, or close to a set of percentages... Scoured the internet trying to find (in detail) how slots work. Found a lot of casino sites with basic rules, some articles with "how they work" but were very very basic. Eventually though I came across this link http://wizardofodds.com/slots/slotapx2.html which finally described, in the detail I needed, how slots really work and the mathematics behind it.

Course I'll skip over all the drama that played out on the actual game between the players since this was "sort of" an exploit that the "creative" players were using, yet not really because it was working the way I coded it. It caused a lot of problems and many users were very angry at myself and the game because of this.

Moral of the story, just because the task looks easy to accomplish doesn't always mean it is easy to, and, if it is to easy, well then maybe it was to easy and something not readily "obvious" is wrong :)

Oh and this article was inspired by a thread here of where to find games and someone offered up links to some slot code. Might want to check how that code is generating a "winning" spin before you put it up on your game :)




Creating online addictions, one game at a time:

Offline Marek

  • Level 17
  • *
  • Posts: 170
  • Reputation: +6/-0
  • XHTML, CSS, JS, PHP and MySQL are my pantheon.
    • View Profile
Re: From the Trenches :: Issue #1
« Reply #1 on: December 14, 2006, 03:42:47 PM »
That's a very informative article, thanks! I think you should continue writing more.

Offline Zeggy

  • Global Moderator
  • Level 35
  • *****
  • Posts: 1,187
  • Reputation: +13/-4
    • View Profile
Re: From the Trenches :: Issue #1
« Reply #2 on: December 18, 2006, 12:08:23 PM »
I agree with nano, that is some great advice! You should write some more  -|-

Offline npshmear

  • Level 6
  • *
  • Posts: 26
  • Reputation: +0/-0
    • View Profile
Re: From the Trenches :: Issue #1
« Reply #3 on: January 11, 2007, 11:42:07 AM »
I think you should write more as well.  I am a new programmer, and this entire forum has really helped me to begin programming games.  I knwo that I need to start somewhere and browser based games are the easiest (other then c++ etc).

But please do keep posting, I like hearing the thoughts of people who know what their talking about so I may learn all that I can!

nps

Offline Broda

  • Level 13
  • *
  • Posts: 97
  • Reputation: +2/-0
    • View Profile
    • Nightfall Games
Re: From the Trenches :: Issue #1
« Reply #4 on: March 23, 2007, 10:40:02 AM »
Informative post and the link is definitely bookmarked :)

Offline sokii

  • Level 14
  • *
  • Posts: 107
  • Reputation: +2/-1
  • Bored? Yea me too... :/
    • View Profile
    • Pyloth
Re: From the Trenches :: Issue #1
« Reply #5 on: November 08, 2007, 06:57:44 PM »
lol nice story :]
Forum Designer Since: March 23, 2006
We are still looking for staff at Pyloth! Send me a PM at my forums located here.

Offline raestlyn

  • Level 29
  • **
  • Posts: 463
  • Reputation: +9/-5
    • View Profile
Re: From the Trenches :: Issue #1
« Reply #6 on: January 24, 2008, 02:48:56 AM »
Nice story and Article :)


I can send you pics of my cocks if you want reference.


Offline vizion

  • Level 7
  • *
  • Posts: 32
  • Reputation: +1/-0
    • View Profile
    • Riddle Contest of Dooooom
Re: From the Trenches :: Issue #1
« Reply #7 on: January 24, 2008, 05:22:44 PM »
Is this a problem for all games of chance that use mt_rand? The reason I ask is that I play a browser-based game that has what's basically a coin-flip game. You place a bet, someone else takes your bet, the code uses mt_rand to determine the winner. It's obviously supposed to be a straight 50/50 shot every time. However, many people on the game claim they can sense patterns after extended play and find the right time to get on winning streaks. As you can imagine, this has caused numerous debates on the forums about how the people who "feel" the patterns are idiots and so on and so on. Could you explain more about how the mt_rand() function might be exploited and the solutions to the problem?

Online Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,134
  • Reputation: +26/-1
    • View Profile
Re: From the Trenches :: Issue #1
« Reply #8 on: April 12, 2008, 06:38:19 AM »
I got similar problem. Strangely it appeared only after 1000 daily players or after switching servers. Or maybe it is not connected and players simply haven't reported it earlier? Change from rand() to mt_rand() improved the situation but did not fix it completely.

Anyone tried if seeding removes the problem? (but they claim that seeding is not required starting at PHP 4.2...)
mt_srand((double)microtime()*1000000 );

Offline Zeggy

  • Global Moderator
  • Level 35
  • *****
  • Posts: 1,187
  • Reputation: +13/-4
    • View Profile
Re: From the Trenches :: Issue #1
« Reply #9 on: April 12, 2008, 12:11:31 PM »
I think mt_rand seeds itself each time it is called, but I'm not sure.
There's probably more information on the PHP website.

Offline JGadrow

  • Level 35
  • **
  • Posts: 1,133
  • Reputation: +23/-2
    • View Profile
Re: From the Trenches :: Issue #1
« Reply #10 on: April 12, 2008, 02:00:54 PM »
Right you are, Zeggy!

Quoted from PHP.net:

Note: As of PHP 4.2.0, there is no need to seed the random number generator with srand() or mt_srand() as this is now done automatically.
Idiocy - Never underestimate the power of stupid people in large groups.


Offline codestryke

  • Administrator
  • Level 33
  • *****
  • Posts: 588
  • Reputation: +22/-0
    • View Profile
    • eXtremeCast Games
Re: From the Trenches :: Issue #1
« Reply #11 on: April 12, 2008, 06:53:49 PM »
Is this a problem for all games of chance that use mt_rand? The reason I ask is that I play a browser-based game that has what's basically a coin-flip game. You place a bet, someone else takes your bet, the code uses mt_rand to determine the winner. It's obviously supposed to be a straight 50/50 shot every time. However, many people on the game claim they can sense patterns after extended play and find the right time to get on winning streaks. As you can imagine, this has caused numerous debates on the forums about how the people who "feel" the patterns are idiots and so on and so on. Could you explain more about how the mt_rand() function might be exploited and the solutions to the problem?

My partner and I talk about this exact subject matter a lot!!! For a very interesting read about random and probability check out the following articles.

http://www.gamasutra.com/features/20061018/sigman_01.shtml

It'll shed a LOT of light on the matter... People tend to find patterns when there is none, in fact, while running a number of games we've found some very interesting superstitions our player's believe. They aren't true of course but it's amazing what patters people will believe they see that simply are not there.

Creating online addictions, one game at a time:

Online Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,134
  • Reputation: +26/-1
    • View Profile
Re: From the Trenches :: Issue #1
« Reply #12 on: April 13, 2008, 04:12:29 PM »
People tend to find patterns when there is none, in fact, while running a number of games we've found some very interesting superstitions our player's believe. They aren't true of course but it's amazing what patters people will believe they see that simply are not there.
Yes, that's probably it. It was after one person started spreading these rumours on my forum that others started to report the problem as well...
Anyway, the mt_rand() seems to be better quality than rand() and that's all we can do under PHP.

Offline codestryke

  • Administrator
  • Level 33
  • *****
  • Posts: 588
  • Reputation: +22/-0
    • View Profile
    • eXtremeCast Games
Re: From the Trenches :: Issue #1
« Reply #13 on: April 13, 2008, 05:16:29 PM »
Anyway, the mt_rand() seems to be better quality than rand() and that's all we can do under PHP.

If you want other ways try the code at.. There are more options :)
http://forums.devshed.com/php-development-5/php-randomization-questions-357534.html
Creating online addictions, one game at a time:

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal