News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

sorts and statistics ?

Started by daydreamer, July 09, 2024, 03:22:40 PM

Previous topic - Next topic

daydreamer

Working on card game I sort card hand data to another arrays that show statistics of cards in two categories
Colors and value
That way I can check if all five cards have same color and if it has 2,3,4 or even five aces (with joker)
Also  Checking value array for five 1's in a row
Is there a name for this kind of algo?
JJ also likes statistics

my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding


stoo23

You cannot view this attachment.

daydreamer

#3
Thanks JJ
Lol stoo :D
Funny with both English "mean" statistics function and windows cpp header has #define lean and mean ,that mean also = naughty :)
I am concentrating my effort get logic right with console exe first

updated code in zip
yet new updated version 18 july

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    include \masm32\include\masm32rt.inc
   ;daydreamer (c) 2024
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
.686
.XMM
comment * -----------------------------------------------------
                     Build this console app with
                  "MAKEIT.BAT" on the PROJECT menu.
        ----------------------------------------------------- *

    .data?
      value dd ?

    .data
      item dd 0
      v db "123456789",0
      db "10",0
      db "knave","queen","king","ace",0
      db "joker",0
      color db "hearts","diamond","spades","clubs",0
      deck db 2,1
      db 256 dup(0)
      ;flush threes aces and two kings 
      deckp dd 10
      hand1 db 14,0,14,0,14,0,13,0,13,0                    ;db 10,0,11,1,12,2,13,3,14,0
            ;test different hands if evaluate works
            db 10,0,11,0,12,0,13,0,14,0 ;straight flush
            db 14,1,14,1,14,1,14,1,13,1 ;fours aces
            db 14,2,14,2,13,2,13,2,12,2 ;two pair aces and kings 
            db 14,0,13,1,12,2,11,3,10,0 ;straight 
            db 14,0,2,1,10,0,12,0,7,0 ;nothing
            db 256 dup(14)
      hand2 db 0,0, 0,0, 0,0 ,0,0 ,0,0
        ;deck dw 0201h     ; high byte value,low byte color
        ;dw 64 dup (0) ; card deck space 52 cards+ extra space for jokers
        ;hand1 db 0,0,0,0,0 ,0,0,0,0,0 ; five card hand
        ;hand2 db 0,0,0,0,0 ,0,0,0,0,0 ; space for several players hands

        flush db 0
        pair db 0
        threes db 0
        fours db 0
        fives db 0
        straight db 0
        ;none db 0
        heart db 0
        diamond db 0
        spades db 0
        clubs db 0
        ace2 db 0 ;ace value 1
               ;2,3,4,5,6,7,8,9,10,knave,queen,king
        twos db 0,0,0,0,0,0,0,0,0,0,0,0
        ace db 0,0,0,0,0,0,0,0,0,0,0,0,0 ;ace value 14
            db 64 dup(0)
           
     

    .code
vcards proto
start:
  
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    call main
    inkey
    exit
;__________________________________________________________________________
evaluate proc
LOCAL none:DWORD

mov ecx,74 ;clear previous statistics data
lea ebx,flush
@@Le1:mov al,0
      mov [ebx],al
      inc ebx
      dec ecx
      jne @@Le1
      mov none,1 ;default set none 1 hand1 until finding a legal hand1

; evaluate hand if 2,3,4 of same value,if all same color
;for ebx=0 to 5
mov ebx,0
@@L1:
movzx eax,[ebx*2+hand1+1]
movzx edx,[ebx*2+hand1]
inc byte ptr [eax+heart]
inc byte ptr [edx+twos]
inc ebx
cmp ebx,5
jne @@L1
; sort hand and check if values difference is 0,1,2,3,4
;for ebx =2 to 14
mov ebx,2
@@L2:
push ebx

movzx eax,[ebx+twos]
switch eax
case 2
push ebx
print "pair of "
mov none,0
inc pair
;print ustr$(ebx)
pop ebx
invoke vcards

;if two of same+ two same of two others print "pair of "
case 3
push ebx
print "threes of "
mov none,0
inc threes

;print ustr$(ebx)
pop ebx
invoke vcards
case 4
push ebx
print "four of "
mov none,0
inc fours
;print ustr$(ebx)
pop ebx
invoke vcards
case 5
push ebx
print "five of "
mov none,0
inc fives
;print ustr$(ebx)
pop ebx
invoke vcards
endsw
pop ebx
inc ebx
cmp ebx,15
jne @@L2

;if 0,1,2,3,4 difference print "straight"
;for ebx=1 to 14
mov ebx,1
mov al,ace
mov ace2,al
@@L3:
lea esi,[ace2+ebx-1] ;workaround below error
;mov eax,[hand1+ebx*2];error A2070
mov eax,[esi]
mov dl,[esi+4]

.if eax==01010101h
.if dl==1           ;1-2-3-4-5 in a row in hand1 ?
print " straight "
mov none,0
inc straight
.endif
.endif


inc ebx
cmp ebx,15
jne @@L3

;if all same color print "flush"
mov al,heart
.if al==5
print "flush"
mov none,0
inc flush
.endif
mov al,diamond
.if al==5
print "flush"
mov none,0
inc flush
.endif
mov al,spades
.if al==5
print "flush"
mov none,0
inc flush
.endif
mov al,clubs
.if al==5
print "flush"
mov none,0
inc flush
.endif

.if none==1
print "nothing "
.endif

mov ecx,10  ;fetch next hand from card deck
lea ebx,hand1
lea esi,hand1
add esi,deckp

@@L4:mov al,[esi]
    mov [ebx],al
    inc esi
    inc ebx
    dec ecx
    jne @@L4
mov eax,deckp ;increment deckp pointer to next 5 cards in card deck
add eax,10
mov deckp,eax
ret
evaluate endp
;**************************************************************************
vcards proc
push ebx
switch ebx
case 11
print "knaves "
case 12
print "queens "
case 13
print "kings "
case 14
print "aces "

endsw
pop ebx
.if ebx <11
print ustr$(ebx)
print " "
.endif

ret
vcards endp
;**************************************************************************
pcards proc
LOCAL cnt:DWORD
;loc 0,0
mov cnt,5
mov ebx,0
@@L1:
movzx eax,[ebx*2+hand1] ;value of hand card
;inc ebx
movzx edx,[ebx*2+hand1+1] ;color of hand card
push ebx
;push edx
push eax
switch eax
case 11
print "knave of "
case 12
print "queen of "
case 13
print "king of "
case 14
print "ace of "

endsw
pop eax
.if eax <11
print ustr$(eax)
print " "
.endif





pop ebx
push ebx
;pop edx
movzx edx,[ebx*2+hand1+1] ;color of hand card

switch edx
case 0
print "hearts "
case 1
print "diamonds "
case 2
print "spades "
case 3
print "clubs "
endsw
pop ebx
inc ebx
dec cnt
jne @@L1
print " ",13,10
invoke evaluate
print " in your hand",13,10




ret
pcards endp
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

main proc
LOCAL cnt2,tmp,deckcnt:DWORD
mov deckcnt,10
mov cnt2,256
mov ecx,51
mov al,2
mov ah,0
@@Li1:      ;loop to initialize card deck
    mov [ecx*2+deck],al
    mov [ecx*2+deck+1],ah
    add ah,1
    and ah,03h
    add al,1
    .IF al>14
        mov al,2
    .ENDIF
    dec ecx
    cmp ecx,0ffffffffh
    jne @@Li1

rdtsc
    invoke nseed, eax
    invoke nrandom,256
    add eax,cnt2
    mov cnt2,eax         
    mov ebx,0
    mov edx,0        
@@L2:
    push ebx
   
    invoke nrandom,52
    ;add eax,2 ;value of card
    mov tmp,eax
    mov dl,[eax*2+deck];mov random card in deck
    mov dh,[eax*2+deck+1]
    push edx
   
    invoke nrandom,52
    pop edx
    xchg [eax*2+deck],dl ;exchange with different random card in deck
    xchg [eax*2+deck+1],dh
    mov eax,tmp
    xchg [eax*2+deck],dl ;exchange with previous random card in deck
    xchg [eax*2+deck+1],dh
   
   
    inc ebx
    dec cnt2
    jne @@L2

    cls
    print "card game",13,10

@@L3card:
    call pcards
    dec deckcnt
    jne @@L3card

    ret

main endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

end start



my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

stoo23

QuoteLol stoo :D
Glad you enjoyed the humour  :smiley:
I had only found that 'presented' to me on Facebook, about an hour before noticing jj's post referring to;
QuoteCount(pHaystack, pNeedle) :biggrin:
and (with tongue similarly and firmly in one's cheek), figured it to be eminently appropriate  :wink2:  :thumbsup:

daydreamer

Anyone tested it ?
Anyone know a different way ?
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

zedd151

Quote from: daydreamer on July 14, 2024, 01:07:42 AMAnyone tested it ?
Anyone know a different way ?

Out of curiosity...
card game
ace of hearts ace of ace of hearts king of king of hearts
pair of 13threes of 14flush in your hand
Press any key to continue ...
The result does not make any sense at all... :sad:
:azn:

daydreamer

Out of curiosity...
card game
ace of hearts ace of ace of hearts king of king of hearts
pair of 13threes of 14flush in your hand
Press any key to continue ...
The result does not make any sense at all... :sad:
[/quote]
Need some debugging
on first line print 5 card hand
Next line print after evaluate hand according to poker rules: pair of kings and 3 aces simultanously testing if flush detection works
But so far only using ustr$(value of card) it prints 13 and 14 instead
Thats why .data section has several poker hands for testing purpose to see if proc evaluate works for all different hands
Before i start to use random card deck

my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

daydreamer

#8
Fixed bug printing color of cards
Instead of mov edx, [ebx+hand1+1] it should be [ebx*2+hand1+1]
Each card has 1 byte value of card followed by 1 byte color
Replaced ustr$( card value) for pair of,four of,three of,five of with instead switch/ case "knaves","queens","kings","aces"
got evaluation of 5 cards on hand working,added clear statistics data so I can loop thru test data now,after finishing testing will change to random card deck instead

my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding