Skul 
Master
 
Posts: 413
Likes Given: 0
Likes Received: 19 in 15 posts
Joined: Jun 2012
Reputation: 9
![]()
|
RE: I need a more efficient function
Right, I know what you mean now (considering how your script originally was). But after reading Shir's suggestion, sorting your cart types using numbers 1 - 52 that 'mess' of an array will be gone if you were to use TAGs, guaranteed. You can use a function to read your hand, shuffle the cards, let me think up a simple script quick:
Code:
[function f_poker_shuffle]
while !(<dlocal.y>==52)
local.x=<eval {1 52}>
if !(<local.x.<dlocal.x>>)
if (<isempty <tag.poker.hand.shuffled>>)
tag.poker.hand.shuffled=<local.x>
else
tag.poker.hand.shuffled=<tag.poker.hand.shuffled>,<local.x>
endif
local.y += 1
endif
endwhile
[function f_poker_pass_card]
//argn1 = cards
//argn2 = uid of game host
if (<argn1>)
for x 1 <argn1>
if (<isempty <tag.poker.hand>>)
tag.poker.hand=<uid.<argn2>.f_poker_retrieve_card <uid.<argn2>.tag0.poker.hand.shuffled>>
else
tag.poker.hand=<tag.poker.hand>,<uid.<argn2>.f_poker_retrieve_card <uid.<argn2>.tag0.poker.hand.shuffled>>
endif
endfor
endif
[function f_poker_retrieve_card]
if (<tag0.poker.hand.shufffled>)
tag.poker.hand.shuffled=
for x 1 <eval <args> +-1> //eliminate the first card from the array, restore the tag.
if(<isempty <tag.poker.hand.shuffled>>)
tag.poker.hand.shuffled=<argv[<local.x>]>
else
tag.poker.hand.shuffled=<tag.poker.hand.shuffled>,<argv[<local.x>]>
endif
endfor
return <argv[0]> //the first card in the array (after shuffling)
else
return '' //no tag, no return
endif
So if you were to sort your card names by 1 - 52 in a defname, as an example you can retrieve the card name by number like
Code:
<serv.def.Poker_Card<card #1-52>_Name
<serv.def.Poker_Card<card #1-52>_Name_Short
Cards are also sorted by suite, example Spades are more than Hearts are more than Clubs are more than Diamonds. So sorting it out in number you can simplify this by dividing your deck by 4 suites.
Code:
if (<card #> <= 52) && (<card #> >= <eval 52 - <eval 52 /4>>)
//spades
elseif (<card #> < <eval 52 - <eval 52 /4>>) && (<card #> >= <eval 52 - <eval <eval 52 /4> *2>>)
//hearts
elseif (<card #> < <eval 52 - <eval <eval 52 /4> *2>) && (<card #> >= <eval 52 - <eval <eval 52 /4> *3>>)
//clubs
else
//diamonds
endif
"I ask a question to the answer I already know."
Marchadium :: http://www.marchadium.ca/ :: Join us!
(This post was last modified: 07-11-2012 09:32 AM by Skul.)
|
|
07-11-2012 09:26 AM |
|
|