The following warnings occurred:
Warning [2] Use of undefined constant SAPI_NAME - assumed 'SAPI_NAME' (this will throw an Error in a future version of PHP) - Line: 3388 - File: inc/functions.php PHP 7.4.33-nmm7 (Linux)
File Line Function
/inc/functions.php 3388 errorHandler->error
/showthread.php 116 build_archive_link
Warning [2] Use of undefined constant IN_ARCHIVE - assumed 'IN_ARCHIVE' (this will throw an Error in a future version of PHP) - Line: 3331 - File: inc/functions.php PHP 7.4.33-nmm7 (Linux)
File Line Function
/inc/functions.php 3331 errorHandler->error
/inc/functions.php 3324 build_forum_breadcrumb
/showthread.php 195 build_forum_breadcrumb
Warning [2] Use of undefined constant IN_ARCHIVE - assumed 'IN_ARCHIVE' (this will throw an Error in a future version of PHP) - Line: 3331 - File: inc/functions.php PHP 7.4.33-nmm7 (Linux)
File Line Function
/inc/functions.php 3331 errorHandler->error
/showthread.php 195 build_forum_breadcrumb
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 786 - File: showthread.php PHP 7.4.33-nmm7 (Linux)
File Line Function
/showthread.php 786 errorHandler->error






Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I need a more efficient function
Author Message
RanXerox
Master
**

Posts: 550
Likes Given: 1
Likes Received: 12 in 9 posts
Joined: Dec 2010
Reputation: 19



Post: #1
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.)
05-15-2012 02:46 PM
Find all posts by this user Like Post Quote this message in a reply
Post Reply 


Messages In This Thread
I need a more efficient function - RanXerox - 05-15-2012 02:46 PM

Forum Jump:


User(s) browsing this thread: 1 Guest(s)