RanXerox
Master
Posts: 550
Likes Given: 1
Likes Received: 12 in 9 posts
Joined: Dec 2010
Reputation: 19
|
RE: I need a more efficient function
This function:
Code:
[FUNCTION f_Poker_SortCards]
//"
// Usage: f_Poker_SortCards CardArray
//
// Sorts an existing LIST object named CardArray, which is assumed to contain
// CardSymbols. The sort order has highest ranked cards (Ace) first (suit is
// ignored.)
//"
IF (<ARGV>==0)
f_pokerlog 1,"Poker_SortCards: needs a CardArray"
RETURN 1
ENDIF
LOCAL.Input=<ARGS>
LOCAL.InputSize=<LIST.<LOCAL.Input>.COUNT>
IF (<LOCAL.InputSize> < 2)
f_pokerlog 1,"Poker_SortCards: CardArray <LOCAL.Input> is too small to sort"
RETURN 1
ENDIF
f_pokerlog 1,"Poker_SortCards: Start sorting <LOCAL.Input> (size=<LOCAL.InputSize>)"
LOCAL.Swapped=1
WHILE (<dLOCAL.Swapped>==1)
LOCAL.Swapped=0
FOR LoopNumber 1 <EVAL <LOCAL.InputSize>-1>
LOCAL.CardA="<STRSUB 1 2 <LIST.<LOCAL.Input>.<EVAL <LOCAL.LoopNumber>-1>>>"
LOCAL.CardB="<STRSUB 1 2 <LIST.<LOCAL.Input>.<dLOCAL.LoopNumber>>>"
f_pokerlog 2,"Poker_SortCards: ..Loop=<dLOCAL.LoopNumber>: Is <LOCAL.CardA> ranked higher than <LOCAL.CardB>?"
IF (<f_Poker_RankCards <LOCAL.CardA>,<LOCAL.CardB>>==-1) //CardA ranks lower than CardB
f_pokerlog 3,"Poker_SortCards: ....swap them"
LIST.<LOCAL.Input>.<EVAL <LOCAL.LoopNumber>-1>=<LOCAL.CardB>
LIST.<LOCAL.Input>.<dLOCAL.LoopNumber>=<LOCAL.CardA>
LOCAL.Swapped=1
ELSE
f_pokerlog 3,"Poker_SortCards: ....skipping"
ENDIF
ENDFOR
LOCAL.InputSize=<EVAL <LOCAL.InputSize>-1>
ENDWHILE
f_pokerlog 1,"Poker_SortCards: Sorting Completed"
Sometimes produces an error:
Code:
15:31:(Poker.scp,642)Poker: Poker_SortCards: Start sorting POKERGame_040036a76_Player7 (size=07)
15:31:(Poker.scp,642)Poker: Poker_SortCards: ..Loop=1: Is 2h ranked higher than Js?
15:31:(Poker.scp,642)Poker: Poker_SortCards: ....swap them
15:31:(Poker.scp,642)Poker: Poker_SortCards: ..Loop=2: Is 2h ranked higher than Qc?
15:31:(Poker.scp,642)Poker: Poker_SortCards: ....swap them
15:31:(Poker.scp,642)Poker: Poker_SortCards: ..Loop=3: Is 2h ranked higher than 9h?
15:31:(Poker.scp,642)Poker: Poker_SortCards: ....swap them
15:31:(Poker.scp,642)Poker: Poker_SortCards: ..Loop=4: Is 2h ranked higher than Tc?
15:31:(Poker.scp,642)Poker: Poker_SortCards: ....swap them
15:31:(Poker.scp,642)Poker: Poker_SortCards: ..Loop=5: Is 2h ranked higher than 9s?
15:31:(Poker.scp,642)Poker: Poker_SortCards: ....swap them
15:31:(Poker.scp,642)Poker: Poker_SortCards: ..Loop=6: Is 2h ranked higher than Ac?
15:31:(Poker.scp,642)Poker: Poker_SortCards: ....swap them
15:31:(Poker.scp,642)Poker: Poker_SortCards: ..Loop=1: Is Js ranked higher than Qc?
15:31:(Poker.scp,642)Poker: Poker_SortCards: ....swap them
15:31:(Poker.scp,642)Poker: Poker_SortCards: ..Loop=2: Is Js ranked higher than 9h?
15:31:(Poker.scp,642)Poker: Poker_SortCards: ....skipping
15:31:(Poker.scp,642)Poker: Poker_SortCards: ..Loop=3: Is 9h ranked higher than Tc?
15:31:(Poker.scp,642)Poker: Poker_SortCards: ....swap them
15:31:(Poker.scp,642)Poker: Poker_SortCards: ..Loop=4: Is 9h ranked higher than 9s?
15:31:(Poker.scp,642)Poker: Poker_SortCards: ....skipping
15:31:(Poker.scp,642)Poker: Poker_SortCards: ..Loop=5: Is 9s ranked higher than Ac?
15:31:(Poker.scp,642)Poker: Poker_SortCards: ....swap them
15:31:(Poker.scp,642)Poker: Poker_SortCards: ..Loop=1: Is Qc ranked higher than Js?
15:31:(Poker.scp,642)Poker: Poker_SortCards: ....skipping
15:31:(Poker.scp,642)Poker: Poker_SortCards: ..Loop=2: Is Js ranked higher than Tc?
15:31:(Poker.scp,642)Poker: Poker_SortCards: ....skipping
15:31:(Poker.scp,642)Poker: Poker_SortCards: ..Loop=3: Is Tc ranked higher than 9h?
15:31:(Poker.scp,642)Poker: Poker_SortCards: ....skipping
15:31:(Poker.scp,642)Poker: Poker_SortCards: ..Loop=4: Is 9h ranked higher than Ac?
15:31:(Poker.scp,642)Poker: Poker_SortCards: ....swap them
15:31:(Poker.scp,642)Poker: Poker_SortCards: ..Loop=1: Is Qc ranked higher than Js?
15:31:(Poker.scp,642)Poker: Poker_SortCards: ....skipping
15:31:(Poker.scp,642)Poker: Poker_SortCards: ..Loop=2: Is Js ranked higher than Tc?
15:31:(Poker.scp,642)Poker: Poker_SortCards: ....skipping
15:31:(Poker.scp,642)Poker: Poker_SortCards: ..Loop=3: Is Tc ranked higher than Ac?
15:31:(Poker.scp,642)Poker: Poker_SortCards: ....swap them
15:31:(Poker.scp,642)Poker: Poker_SortCards: ..Loop=1: Is Qc ranked higher than Js?
15:31:(Poker.scp,642)Poker: Poker_SortCards: ....skipping
15:31:(Poker.scp,642)Poker: Poker_SortCards: ..Loop=2: Is Js ranked higher than Ac?
15:31:(Poker.scp,642)Poker: Poker_SortCards: ....swap them
15:31:(Poker.scp,642)Poker: Poker_SortCards: ..Loop=1: Is Qc ranked higher than Ac?
15:31:(Poker.scp,642)Poker: Poker_SortCards: ....swap them
15:31:(Poker.scp,642)Poker: Poker_SortCards: ..Loop=1: Is Ac ranked higher than Qc?
15:31:(Poker.scp,642)Poker: Poker_SortCards: ....skipping
15:31:ERROR:(Poker_CardFunctions.scp,121)Can't resolve <STRSUB1>
15:31:(Poker.scp,642)Poker: Poker_SortCards: ..Loop=0: Is 0 ranked higher than Ac?
15:31:(Poker.scp,642)Poker: Poker_SortCards: ....skipping
15:31:(Poker.scp,642)Poker: Poker_SortCards: Sorting Completed
Any suggestions for a proper fix?
|
|