RanXerox 
Master
 
Posts: 550
Likes Given: 1
Likes Received: 12 in 9 posts
Joined: Dec 2010
Reputation: 19
![]()
|
I need a more efficient function
Hey people, I am working on a Hold'em poker script for the community... but I am in need of some help in optimizing some functions that are frequently called. The first one I'd like you to look at for me is an easy one ;-)
This function compares two poker cards to each other... In Poker the highest card is an Ace, next highest is King, then Queen, Jack, Ten, then 9 down to 2. Take a look at the function below and see if you can optimize it further for me:
Note: In this system, poker cards are represented by two letter combinations, and the ranking order needs to be: "As", "Ah", "Ad", "Ac", "Ks", "Kh", "Kd", "Kc", "Qs", "Qh", "Qd", "Qc", "Js", "Jh", "Jd", "Jc", "Ts", "Th", "Td", "Tc", "9s", "9h", "9d", "9c", "8s", "8h", "8d", "8c", "7s", "7h", "7d", "7c", "6s", "6h", "6d", "6c", "5s", "5h", "5d", "5c", "4s", "4h", "4d", "4c", "3s", "3h", "3d", "3c", "2s", "2h", "2d", "2c"
Code:
[FUNCTION f_Poker_RankCards]
//"
// Usage: f_Poker_SortCard CardA,CardB
//
// Compares CardA to CardB
//
// Returns: -1 if A is less than B
// Returns: 0 if A is equal to B
// Returns: 1 if A is greater than B
//"
IF (<ARGV>!=2)
f_pokerlog 1,"Poker_RankCards: needs two cards as arguments"
RETURN 1
ENDIF
LOCAL.CardA=<STRSUB 0 1 <ARGV[0]>>
LOCAL.CardB=<STRSUB 0 1 <ARGV[1]>>
f_pokerlog 1,"Poker_RankCards: CardA=<LOCAL.CardA> CardB=<LOCAL.CardB>"
IF (<ISNUM <LOCAL.CardB>>) && (<ISNUM <LOCAL.CardA>>)
IF (<LOCAL.CardA> > <LOCAL.CardB>)
f_pokerlog 1,"A is ranked Greater than B"
RETURN 1
ELSEIF (<LOCAL.CardA> < <LOCAL.CardB>)
f_pokerlog 1,"A is ranked Less than B"
RETURN -1
ELSE
f_pokerlog 1,"A is equal to B"
RETURN 0
ENDIF
ENDIF
IF !(<ISNUM <LOCAL.CardA>>) && (<ISNUM <LOCAL.CardB>>)
f_pokerlog 1,"A is ranked Greater than B"
RETURN 1
ENDIF
IF (<ISNUM <LOCAL.CardA>>) && !(<ISNUM <LOCAL.CardB>>)
f_pokerlog 1,"A is ranked Less than B"
RETURN -1
ENDIF
IF !(STRCMPI("<LOCAL.CardA>","A")) && (STRCMPI("<LOCAL.CardB>","A"))
f_pokerlog 1,"A is ranked Greater than B"
RETURN 1
ELSEIF (STRCMPI("<LOCAL.CardA>","A")) && !(STRCMPI("<LOCAL.CardB>","A"))
f_pokerlog 1,"A is ranked Less than B"
RETURN -1
ELSEIF !(STRCMPI("<LOCAL.CardA>","K")) && (STRCMPI("<LOCAL.CardB>","K"))
f_pokerlog 1,"A is ranked Greater than B"
RETURN 1
ELSEIF (STRCMPI("<LOCAL.CardA>","K")) && !(STRCMPI("<LOCAL.CardB>","K"))
f_pokerlog 1,"A is ranked Less than B"
RETURN -1
ELSEIF !(STRCMPI("<LOCAL.CardA>","Q")) && (STRCMPI("<LOCAL.CardB>","Q"))
f_pokerlog 1,"A is ranked Greater than B"
RETURN 1
ELSEIF (STRCMPI("<LOCAL.CardA>","Q")) && !(STRCMPI("<LOCAL.CardB>","Q"))
f_pokerlog 1,"A is ranked Less than B"
RETURN -1
ELSEIF !(STRCMPI("<LOCAL.CardA>","J")) && (STRCMPI("<LOCAL.CardB>","J"))
f_pokerlog 1,"A is ranked Greater than B"
RETURN 1
ELSEIF (STRCMPI("<LOCAL.CardA>","J")) && !(STRCMPI("<LOCAL.CardB>","J"))
f_pokerlog 1,"A is ranked Less than B"
RETURN -1
ELSE
f_pokerlog 1,"A is equal to B"
RETURN 0
ENDIF
[FUNCTION f_pokerlog]
IF (<EVAL <DEF.PokerLogging>> >= <ARGV[0]>)
SERV.LOG Poker: <ARGV[1]>
UID.044947.SYSMESSAGE @021 <ARGV[1]>
ENDIF
[DEFNAME poker_system]
PokerLogging=3
(This post was last modified: 05-15-2012 03:08 PM by RanXerox.)
|
|