emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master a275e71: Improve poker-hand-value performance by 25%


From: Mario Lang
Subject: [elpa] master a275e71: Improve poker-hand-value performance by 25%
Date: Wed, 3 Aug 2016 23:39:16 +0000 (UTC)

branch: master
commit a275e71c6ef8e3ece445d53582491fc606304d1b
Author: Mario Lang <address@hidden>
Commit: Mario Lang <address@hidden>

    Improve poker-hand-value performance by 25%
    
    Avoid unnecessary calls to poker-card-suit in flush check.
---
 packages/poker/poker.el |   13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/packages/poker/poker.el b/packages/poker/poker.el
index c908bb6..61888ae 100644
--- a/packages/poker/poker.el
+++ b/packages/poker/poker.el
@@ -109,11 +109,16 @@ The highest possible value is therefore #x8CBA98 and the 
lowest is #x053210."
                                             (eq (nth 1 ranks) 3))
                                    (setq ranks '(3 2 1 0 0)))
                                  (eq (- (nth 0 ranks) (nth 4 ranks)) 4)))
-                   (flush (not (cdr (delete-dups (mapcar #'poker-card-suit 
hand))))))
+                   (flush (let ((suit (poker-card-suit (car hand)))
+                                (tail (cdr hand)))
+                            (while (and tail
+                                        (eq suit (poker-card-suit (car tail))))
+                              (setq tail (cdr tail)))
+                            (not tail))))
                (cond ((and straight flush) #x800000)
-                     (straight #x400000)
-                     (flush #x500000)
-                     (t 0))))
+                     (straight             #x400000)
+                     (flush                #x500000)
+                     (t                      0))))
             ((equal rank-counts '(2 2 1)) #x200000)
             ((equal rank-counts '(3 1 1)) #x300000)
             ((equal rank-counts '(3 2)) #x600000)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]