mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Sep 2014
Posts: 259
S
Sakana Offline OP
Fjord artisan
OP Offline
Fjord artisan
S
Joined: Sep 2014
Posts: 259
I'm trying to make a poker probability calculator with the help of http://www.mircscripts.org/showdoc.php?type=code&id=3002 (I've only written the odds alias of the code below). I get an error with line too long referring to
var %a = $1,%b = 1
. There's something wrong with $3 and $4 when I use the odds alias, the calculations are only correct when they are set to 1


alias factorial {
var %a = $1,%b = 1
while (%a) {
var %b = %b * %a
dec %a
}
return %b
}

alias nCr {
return $calc($factorial($1) / ($factorial($$2) * $factorial($calc($1 - $2))))
msg $chan $calc($factorial($1) / ($factorial($$2) * $factorial($calc($1 - $2))))

}

alias odds { msg $chan $calc(($nCr($3,$4) * $nCr($calc($1 - $3),$calc($2 - $4))) / $nCr($1,$2))
}

;; $1 is total cards left in deck
;; $2 is number of cards drawn
;; $3 is number of outs in deck
;; $4 is outs required

Last edited by Sakana; 02/11/14 03:01 PM.
Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
Can you give the value for $1 $2 $3 and $4, passed to the /odds alias?
The only way to get the error you said is when $1 (inside the factorial alias is more than 4141 characters, which I don't think should happen here


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Sep 2014
Posts: 259
S
Sakana Offline OP
Fjord artisan
OP Offline
Fjord artisan
S
Joined: Sep 2014
Posts: 259
Hmm, my bad. I might just have been using invalid numbers or something. I tried again with a real example and it does give a probability now. Sadly, the answer is wrong :p

I used an example with 60 cards left, 7 cards being drawn, 4 outs in deck and 1 out needed:

/odds 60 7 4 1

it comes out as 0.33628 when it should be 0.399499623

The problem seems to be with $3 and $4. If I keep those at 1 then the script works correctly. The equation is based on C(outs,required)*C(total-outs,drawn-required)/C(total,drawn)

Last edited by Sakana; 02/11/14 01:59 PM.
Joined: Sep 2014
Posts: 259
S
Sakana Offline OP
Fjord artisan
OP Offline
Fjord artisan
S
Joined: Sep 2014
Posts: 259
Alright, got it working. It was more of a problem with the math than anything else :p

Code:
alias factorial {
  var %a = $1,%b = 1
  while (%a) {
    var %b = %b * %a
    dec %a
  }
  return %b
}

alias nCr {

  return $calc($factorial($1) / ($factorial($$2) * $factorial($calc($1 - $2))))

}

alias odds {

; This alias calculates the probability of getting the card(s) you need 
;$1 is the number of cards left in the deck
;$2 is the number of cards you are drawing
;$3 is the number of outs left in the deck
;$4 is the number of outs you need to draw

  var %total = $1
  var %drawn = $2
  var %outs = $3
  var %required = $4

  while (%outs >= %required) { 

    var %result = $calc(%result + $calc(($nCr(%outs,%required) * $nCr($calc(%total - %outs),$calc(%drawn - %required))) / $nCr(%total,%drawn)))
    inc %required

  }

  msg $chan The probability is %result 

}

Last edited by Sakana; 03/11/14 12:15 PM.
Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
Yeah, and I couldn't help you with the math, but nice job, I'm sure this can be useful to others


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Sep 2014
Posts: 259
S
Sakana Offline OP
Fjord artisan
OP Offline
Fjord artisan
S
Joined: Sep 2014
Posts: 259
I hope so! It's a good tool for any card game (Hearthstone, Magic, Poker, etc). I added a few comments to make it more clear what's going on smile


Link Copied to Clipboard