Pokerfrage, Straße erkennen! Bitte helfen...^^

Übersicht BlitzBasic Allgemein

Neue Antwort erstellen

 

tmode00

Betreff: Pokerfrage, Straße erkennen! Bitte helfen...^^

BeitragMo, März 12, 2007 10:28
Antworten mit Zitat
Benutzer-Profile anzeigen
Hi,

Ich bin gerade dabei eine Art Videopoker (Wikipedialink) zu programmieren.
Es funktioniert schon ganz gut, nur bei der Straße stehe ich vor einem Rätsel.
Wie kann ich eine Routine skripten, die erkennt ob es sich um eine Straße handelt, oder eben nicht!

Bsp.:
user posted image

Für uns Menschen ist es leicht zu erkennen, 5 Karten in reinfolge, beginnend mit der höchsten!
Die Routine dafür würde ca. so aussehen:

Code: [AUSKLAPPEN]
Function check_straight(a,b,c,d)
   If a - 1 = b Then
      If b - 1 = c Then
         If c - 1 = d Then
            Print "DINGDINGDING, STRAßE!!!
         EndIf
      EndIf
   EndIf
End Function


Wenn nun aber der König an 2. Position ist, dann funktioniert es schon nicht mehr.
Man müsste potenziell gesehen sehr viele berechungenn machen, da ja jede der 5 Karten an jeder der 5 Positionen sein kann:

9 10 Q J K
10 J 9 K Q
Q J K 10 9
.........

etc....

Kurz: Ich brauche eine Funktion, die in der lage ist ne Straße zu erkennen, wie Sie in jeder Online-Poker Software verwendet wird.

Anhang: Wen mein vorhaben interessiert, der kann es HIER DOWNLOADEN!
Und zum schluss noch der Quellcode:
Code: [AUSKLAPPEN]
;Init--->
Graphics 640,480,32,2
Cls
SetBuffer BackBuffer()
standart = LoadFont(Arial,30)
SetFont standart
SeedRnd MilliSecs()

;Globale Variablen
Global karte,farbe,karte_back,sound,sound_s,count_highcard,count_1pair,count_2pair,count_3kind
Global count_straight,count_flush,count_fullhouse,count_fourofakind,count_strflush,count_royalflush

;Sounds--->
Global high_snd = LoadSound("sfx\highcard.mp3")
Global onepair_snd = LoadSound("sfx\onepair.mp3")
Global twopair_snd = LoadSound("sfx\twopair.mp3")
Global threeofakind_snd = LoadSound("sfx\3ofakind.mp3")
Global straight_snd = LoadSound("sfx\straight.mp3")
Global flush_snd = LoadSound("sfx\flush.mp3")
Global fullhouse_snd = LoadSound("sfx\fullhouse.mp3")
Global fourofakind_snd = LoadSound("sfx\4ofakind.mp3")
Global straightflush_snd = LoadSound("sfx\straightflush.mp3")
Global royalflush_snd = LoadSound("sfx\royalflush.mp3")
Dim sounds(16)
For is = 2 To 14
   sounds(is) = LoadSound("sfx\" + Str$(is) + ".mp3")
Next
Dim sounds_s(16)
For is_s = 2 To 14
   sounds_s(is_s) = LoadSound("sfx\" + Str$(is_s) + "s.mp3")
Next

;Images--->
karte = LoadImage("gfx\karte.png")
karte_back = LoadImage("gfx\karte_back.png")
farbe = LoadAnimImage("gfx\farbe.png",40,50,0,4)
MaskImage farbe ,0,0,255
;--------------------------------------------------------------Dekleration ENDE--

Function card_stack(farbee,pos_x,pos_y,kartenr)
   If farbee = 0 Or farbee = 1  Then   Color 189,27,27
   If farbee = 2 Or farbee = 3 Then   Color 0,0,0
   
   If kartenr = 10 Then
       plus = 40
       zahl$ = "10"
   Else
      plus = 50
   EndIf
   
   If kartenr  = 11 Then zahl$ = "J"
   If kartenr  = 12 Then zahl$ = "Q"
   If kartenr  = 13 Then zahl$ = "K"
   If kartenr  = 14 Then zahl$ = "A"
   
   If kartenr > 1 And kartenr < 10 Then zahl$ = kartenr

   DrawImage karte,pos_x,pos_y
   DrawImage farbe,pos_x+13,pos_y+30,farbee;klein links
   Text pos_x+2,pos_y+1, zahl$
   Text pos_x+plus,pos_y+81,zahl$   
      
   If kartenr = 15 Then DrawImage karte_back,pos_x,pos_y   
End Function

Function check_hand(k1,k2,k3,k4,k5,f1,f2,f3,f4,f5)
   ;flush
   If f1 = f2 And f2 = f3 And f3 = f4 And f4 = f5 Then
      
      ;straightflush
      If k1 + 1 = k2 And k2 + 1 = k3 And k3 + 1 = k4 And k4 + 1 = k5 Then
         
         ;royalflush
         If k1 = 14 Or k2 = 14 Or k3 = 14 Or k4 = 14 Or k5 = 14 Then
            royalflush = 4 
            
         Else
            straightflush = 4
         EndIf
         
      EndIf
   
      flush = 4      
   EndIf   

   ;4ofakind
   If threeofakind <> 0 Then
      If k1 = k2 And k2 = k3 And k3 = k4 Then fourofakind = k1
      If k2 = k3 And k3 = k4 And k4 = k5 Then fourofakind = k2
      If k1 = k2 And k2 = k3 And k3 = k5 Then fourofakind = k5
      If k1 = k2 And k2 = k4 And k4 = k5 Then fourofakind = k4
      If k1 = k3 And k3 = k4 And k4 = k5 Then fourofakind = k4
   EndIf

   ;fullhouse
   If k1 = k2 And k3 = k2 Then 
      threeofakind = k1;4 u 5 (bleiben übrig)
      If k4 = k5 Then fullhouse = k1
   EndIf
   
   If k1 = k2 And k4 = k2 Then 
      threeofakind = k1;3 u 5
      If k3 = k5 Then fullhouse = k1   
   EndIf
   
   If k1 = k2 And k5 = k2 Then 
      threeofakind = k1;3 u 4
      If k3 = k4 Then fullhouse = k1      
   EndIf   
   
   If k1 = k3 And k4 = k3 Then
       threeofakind  = k1;2 u 5
      If k2 = k5 Then fullhouse = k3      
   EndIf
   
   If k1 = k3 And k5 = k3 Then 
      threeofakind  = k1;2 u 4
      If k2 = k4 Then fullhouse = k3      
   EndIf
      
   If k1 = k4 And k5 = k4 Then
      threeofakind  = k1;2 u 3
      If k2 = k3 Then fullhouse = k4      
   EndIf
      
   If k2 = k3 And k4 = k3 Then
       threeofakind  = k2;1 u 5
      If k1 = k5 Then fullhouse = k3      
   EndIf   
      
   If k2 = k4 And k5 = k4 Then
      threeofakind  = k2;1 u 3
      If k1 = k3 Then fullhouse = k4         
   EndIf
   
   If k2 = k3 And k5 = k3 Then
       threeofakind  = k2;1 u 4
      If k1 = k4 Then fullhouse = k3      
   EndIf
   
   If k3 = k4 And k5 = k4 Then
      threeofakind  = k3;1 u 2
      If k1 = k2 Then fullhouse = k4      
   EndIf      

   ;straight--->

      
   
   ;3 of a kind
   If k1 = k2 And k3 = k2 Then  threeofakind = k1
   If k1 = k2 And k4 = k2 Then  threeofakind = k1
   If k1 = k2 And k5 = k2 Then  threeofakind = k1
   If k1 = k3 And k4 = k3 Then  threeofakind  = k1
   If k1 = k3 And k5 = k3 Then  threeofakind  = k1
   If k1 = k4 And k5 = k4 Then threeofakind  = k1
   If k2 = k3 And k4 = k3 Then  threeofakind  = k2
   If k2 = k4 And k5 = k4 Then threeofakind  = k2
   If k2 = k3 And k5 = k3 Then  threeofakind  = k2
   If k3 = k4 And k5 = k4 Then threeofakind  = k3

   ;one pair/two pair
   If k1 = k2 Or k1 = k3 Or k1 = k4 Or k1 = k5 Then
      onepair = k1
      countpairs = countpairs + 1
   EndIf
   If k2 = k1 Or k2 = k3 Or k2 = k4 Or k2 = k5 Then
      onepair = k2
      countpairs = countpairs + 1
   EndIf
   If k3 = k1 Or k3 = k2 Or k3 = k4 Or k3 = k5 Then
      onepair = k3
      countpairs = countpairs + 1
   EndIf
   If k4 = k1 Or k4 = k2 Or k4 = k3 Or k4 = k2 Then
      onepair = k4
      countpairs = countpairs + 1
   EndIf
   If k5 = k1 Or k5 = k2 Or k5 = k3 Or k5 = k4 Then
      onepair = k5
      countpairs = countpairs + 1
   EndIf

   ;high card:
   If  k1 >= k2 And k1 >= k3 And k1 >= k4 And k1 >= k5 Then highcard = k1
   If  k2 >= k1 And k2 >= k3 And k2 >= k4 And k2 >= k5 Then highcard = k2
   If  k3 >= k1 And k3 >= k2 And k3 >= k4 And k3 >= k5 Then highcard = k3
   If  k4 >= k1 And k4 >= k2 And k4 >= k3 And k4 >= k2 Then highcard = k4
   If  k5 >= k1 And k5 >= k2 And k5 >= k3 And k5 >= k4 Then highcard = k5      

;----------------------Play Sounds and Count Hands-->
   
   ;fourofakind sound
   If  fourofakind <> 0 Then
      fourofakind_chn = PlaySound(fourofakind_snd)
      While ChannelPlaying (fourofakind_chn)
      Wend
      PlaySound(sounds_s(fourofakind))
       count_fourofakind= count_fourofakind + 1
      Return fourofakind
   EndIf   

   ;fullhouse sound
   If  fullhouse <> 0 Then
      
      fullhouse_chn = PlaySound(fullhouse_snd)
      While ChannelPlaying (fullhouse_chn)
      Wend
      PlaySound(sounds_s(fullhouse))
       count_fullhouse= count_fullhouse + 1
      Return fullhouse
   EndIf   

   ;royalflush sound
   If  royalflush <> 0 Then
      royalflush_chn = PlaySound(royalflush_snd)
      While ChannelPlaying (royalflush_chn)
      Wend
       count_royalflush = count_royalflush + 1
      Return
   EndIf   
   
   ;straightflush sound
   If  straightflush <> 0 Then
      straightflush_chn = PlaySound(straightflush_snd)
      While ChannelPlaying (straightflush_chn)
      Wend
      PlaySound(sounds_s(highcard))
       count_strflush = count_strflush + 1
      Return
   EndIf   

   ;flush sound
   If  flush <> 0 Then
      flush_chn = PlaySound(flush_snd)
      While ChannelPlaying (flush_chn)
      Wend
      PlaySound(sounds_s(highcard))
       count_flush = count_flush + 1
      Return
   EndIf      

   ;straight sound
   If  straight <> 0 Then
      straight_chn = PlaySound(straight_snd)
      While ChannelPlaying (straight_chn)
      Wend
      PlaySound(sounds_s(highcard))
      count_straight = count_straight + 1
      Return
   EndIf   

   ;3ofakind sound
   If  threeofakind <> 0 Then
      threeofakind_chn = PlaySound(threeofakind_snd)
      While ChannelPlaying (threeofakind_chn)
      Wend
      PlaySound(sounds_s(threeofakind))
      count_3kind = count_3kind + 1
      Return
   EndIf
   
   ;twopair sound
   If  countpairs > 2 Then
      twopair_chn = PlaySound(twopair_snd)
      While ChannelPlaying (twopair_chn)
      Wend
      count_2pair = count_2pair + 1      
      Return
   EndIf
   
   ;onepair sound
   If  onepair <> 0 And threeofakind = 0 Then
      onepair_chn = PlaySound(onepair_snd)
      While ChannelPlaying (onepair_chn)
      Wend
      PlaySound(sounds_s(onepair))
      count_1pair = count_1pair + 1
      Return
   EndIf
      
   ;highcard sound
   If onepair = 0 Then
      high_chn = PlaySound(high_snd)
      While ChannelPlaying (high_chn)
      Wend
      PlaySound(sounds(highcard))
      count_highcard = count_highcard + 1
      Return
   EndIf
         
countpairs = 0
End Function

;----------------------------FUNCTIONS END-------------------------------
pos_x = 145;kartenposition
pos_y = 150

;Dynamisches Hauptprogramm---->
While Not KeyHit(1)
   If count_start = 0 Then Text 10,10, "Leertaste drücken um zu beginnen!"

   If KeyHit(57) Then count_start = 1

   If count_start = 1 Then
      delaystart = 1
      counter = counter + 1
      If counter = 7 Then
         count_start = 0
         counter = 0
         delaystart = 0
          waitt = 1
         slot1= 0
         slot2= 0
         slot3= 0
         slot4= 0
         slot5= 0
      Else
          If counter = 1 Then slot1 = 1
         If counter = 2 Then slot2 = 1
         If counter = 3 Then slot3 = 1
         If counter = 4 Then slot4 = 1
         If counter = 5 Then slot5 = 1
      EndIf
   EndIf

   If slot1 = 1 Then ;slot1
      If slot1 = 1 Then
         SeedRnd MilliSecs()
         farbe_rnd_s1 = Rnd(0,3)
         karte_rnd_s1 = Rnd(2,14)
         slot1 = 2
      EndIf
   ElseIf slot1 = 2 Then
      card_stack(farbe_rnd_s1,pos_x,pos_y,karte_rnd_s1)   
   Else
         card_stack(0,pos_x,pos_y,15)
   EndIf

   If slot2 = 1 Then ;slot2
      If slot2 = 1 Then
         SeedRnd MilliSecs()
         farbe_rnd_s2 = Rnd(0,3)
         karte_rnd_s2 = Rnd(2,14)
         slot2 = 2
      EndIf
   ElseIf    slot2 = 2 Then
         card_stack(farbe_rnd_s2,pos_x+71,pos_y,karte_rnd_s2)   
   Else
            card_stack(0,pos_x+71,pos_y,15)
   EndIf

   If slot3 = 1 Then ;slot3
      If slot3 = 1 Then
         SeedRnd MilliSecs()
         farbe_rnd_s3 = Rnd(0,3)
         karte_rnd_s3 = Rnd(2,14)
         slot3 = 2
      EndIf
   ElseIf    slot3 = 2 Then
         card_stack(farbe_rnd_s3,pos_x+142,pos_y,karte_rnd_s3)   
   Else
            card_stack(0,pos_x+142,pos_y,15)
   EndIf

   If slot4 = 1 Then ;slot4
      If slot4 = 1 Then
         SeedRnd MilliSecs()
         farbe_rnd_s4 = Rnd(0,3)
         karte_rnd_s4 = Rnd(2,14)
         slot4 = 2
      EndIf
   ElseIf   slot4 = 2 Then
         card_stack(farbe_rnd_s4,pos_x+213,pos_y,karte_rnd_s4)   
   Else
            card_stack(0,pos_x+213,pos_y,15)
   EndIf

   If slot5 = 1 Then ;slot5
      If slot5 = 1 Then
         SeedRnd MilliSecs()
         farbe_rnd_s5 = Rnd(0,3)
         karte_rnd_s5 = Rnd(2,14)
         slot5 = 2
      EndIf
   ElseIf  slot5 = 2 Then
         card_stack(farbe_rnd_s5,pos_x+284,pos_y,karte_rnd_s5)   
   Else
          card_stack(0,pos_x+284,pos_y,15)
   EndIf

;karte_rnd_s1 = 13
;karte_rnd_s2 = 12
;karte_rnd_s3 = 11
;karte_rnd_s4 = 10
;karte_rnd_s5 = 9




   If waitt = 1 Then
      ergebnis$ = Str$(check_hand(karte_rnd_s1,karte_rnd_s2,karte_rnd_s3,karte_rnd_s4,karte_rnd_s5,farbe_rnd_s1,farbe_rnd_s2,farbe_rnd_s3,farbe_rnd_s4,farbe_rnd_s5))
      
      If ergebnis$ = "11" Then ergebnis$ = "Jacks"
      If ergebnis$ = "12" Then ergebnis$ = "Queen"   
      If ergebnis$ = "13" Then ergebnis$ = "King"
      If ergebnis$ = "14" Then ergebnis$ = "Ace"
      
      FlushKeys
      WaitKey
      waitt = 0
   EndIf
   Flip
   
   If delaystart = 1 Then Delay 140
Wend


Cls
SetBuffer FrontBuffer()
Cls
Color 200,200,0
Print "Highcards--------> " + count_highcard
Print "One Pairs--------> " + count_1pair
Print "Two Pairs--------> " + count_2pair
Print "3 of a Kind's-----> " + count_3kind
Print "Straight's--------->" + count_straight
Print "Flush's------------>" + count_flush
Print "Fullhouses------->" + count_fullhouse
Print "4 of a Kind's----->" + count_fourofakind
Print "Str. Flushs-------->" + count_strflush
Print "Royal-TS Maxi--->" + count_royalflush
Color 255,0,0
Print ""
Print "Enter drücken um Programm zu beenden!"

While Not KeyHit(28)
   Delay 1
Wend


[/url]
While (1) : Wend

SpionAtom

BeitragMo, März 12, 2007 11:12
Antworten mit Zitat
Benutzer-Profile anzeigen
Du könntest die Anordnung der Karten sortieren, sodass die "größte" Karte stets links ist.

Oder du machst die eine Hilfsfunktion namens EnthaeltKarte(groesse), die schaut, ob eine Karte mit entsprechender Größe in deiner Hand vorkommt.
Code-fragment:
Code: [AUSKLAPPEN]

zusammenhaengend = 0
street = 0
For i = 1 to 13
  If EnthaeltKarte(i) And EnthaeltKarte(i - 1) Then
        zusammenhaengend = zusammenhaengend + 1
        If zusammenhaengend = 4 Then street = i: Exit
  Else
        zusammenhaengend = 0
  End if
Next

If street > 0 Then STRASSE!!
os: Windows 10 Home cpu: Intel Core i7 6700K 4.00Ghz gpu: NVIDIA GeForce GTX 1080
 

tmode00

Betreff: Gute Idee, danke!

BeitragMo, März 12, 2007 12:04
Antworten mit Zitat
Benutzer-Profile anzeigen
Das mit der hilfsfunktion hab ich nicht ganz kapiert, aber auf die Idee mit dem Sortieren hätte ich eigendlich auch selbst kommen können. Das ist des Rätsels lösung. Ich besitze die Sonderbare Eigenschaft manschmal zu kompliziert zu denken und das offensichtliche dann zu übersehen.
While (1) : Wend

SpionAtom

BeitragMo, März 12, 2007 14:40
Antworten mit Zitat
Benutzer-Profile anzeigen
Das mit der Hilfsfunktion war eigentlich so gedacht:

Code: [AUSKLAPPEN]
Dim Card(5)
   
   Card(1) = 4: Card(2) = 7: Card(3) = 6:   Card(4) = 5: Card(5) = 3   
   For i = 1 To 5:Print Card(i):Next
   If hasStreet() > 0 Then
      Print "Sie haben eine Straße mit Wert " + hasStreet()
   Else
      Print "Sie haben keine Straße"
   End If
   Print
   Print


   Card(1) = 4: Card(2) = 7: Card(3) = 9: Card(4) = 5: Card(5) = 3
   For i = 1 To 5:Print Card(i):Next
   If hasStreet() > 0 Then
      Print "Sie haben eine Straße mit Wert " + hasStreet()
   Else
      Print "Sie haben keine Straße"
   End If
   
   WaitKey()
   End   
   
Function hasStreet()

   zusammenhaengend = 0
   street = 0
   For i = 1 To 13
     If EnthaeltKarte(i) And EnthaeltKarte(i - 1) Then
       zusammenhaengend = zusammenhaengend + 1
          If zusammenhaengend = 4 Then street = i: Exit
     Else
        zusammenhaengend = 0
       End If
   Next
   
   Return street

End Function

Function EnthaeltKarte(x)
   For i = 1 To 5
      If Card(i) = x Then Return True
   Next
   Return False
End Function
os: Windows 10 Home cpu: Intel Core i7 6700K 4.00Ghz gpu: NVIDIA GeForce GTX 1080

StepTiger

BeitragMo, März 12, 2007 16:59
Antworten mit Zitat
Benutzer-Profile anzeigen
Wäre es nicht viel sinnvoller, einen lokalen array in der Funktion zu deklarieren und dann alle karten abzufragen?

so in der art:

Code: [AUSKLAPPEN]
local karte[12]

for x=0 to allekarten
   karte[kartennummer(x)]=karte[kartennummer(x)]+1
next


dann alle durchprüfen, ob mindestens eine vorhanden ist und fertig! wenn du nicht weißt, wo die straße anfängt, dann einfach mit einer while schleife, einen counter machen, sollte eine karte aus der reihe tanzen, dann counter auf 0 setzen und weiter.
Noch gestern standen wir am Abgrund, doch heute sind wir schon einen Schritt weiter.
Computer:
AMD Sempron 3000+; ATI Radeon 9800 Pro; 512 MB DDR RAM 400Mhz; Asus E7N8X-E Deluxe; Samsung 200GB HD 5.4ns acces t
Gewinner: BP Code Compo #2
Π=3.141592653589793238...<--- und das aus dem kopf Laughing
Seit der Earthlings-Diskussion überzeugter Fleisch(fr)esser.
 

tmode00

Betreff: OKay

BeitragMi, März 14, 2007 12:43
Antworten mit Zitat
Benutzer-Profile anzeigen
Ich habs hinbekommen indem ich die Karten vorsortieren lasse:
Code: [AUSKLAPPEN]

;sortieren slot 1
   If  k1 >= k2 And k1 >= k3 And k1 >= k4 And k1 >= k5 Then
      k1 = k1
      k1 = k1
   ElseIf k2 >= k1 And k2 >= k3 And k2 >= k4 And k2 >= k5 Then
      temp = k1
      k1 = k2
      k2 = temp
   ElseIf k3 >= k1 And k3 >= k2 And k3 >= k4 And k3 >= k5 Then
      temp = k1
      k1 = k3
      k3 = temp
   ElseIf k4 >= k1 And k4 >= k2 And k4 >= k3 And k4 >= k5 Then
      temp = k1
      k1 = k4
      k4 = temp
   ElseIf k5 >= k1 And k5 >= k2 And k5 >= k3 And k5 >= k4 Then
      temp = k1
      k1 = k5
      k5 = temp
   EndIf
   ;sortieren slot 2
   If  k2 >= k3 And k2 >= k4 And k2 >= k5 Then
      k2 = k2
      k2 = k2
   ElseIf k3 >= k2 And k3 >= k4 And k3 >= k5 Then
      temp = k2
      k2 = k3
      k3 = temp
   ElseIf k4 >= k3 And k4 >= k2 And k4 >= k5 Then
      temp = k2
      k2 = k4
      k4 = temp   
   ElseIf k5 >= k4 And k5 >= k3 And k5 >= k2 Then
      temp = k2
      k2 = k5
      k5 = temp   
   EndIf
   ;sortieren slot 3
   If  k3 >= k4 And k3 >= k5 Then
      k3 = k3
      k3 = k3
   ElseIf k4 >= k3 And k4 >= k5 Then
      temp = k3
      k3 = k4
      k4 = temp   
   ElseIf k5 >= k4 And k5 >= k3 Then
      temp = k3
      k3 = k5
      k5 = temp      
   EndIf
   ;sortieren slot 4/5
   If  k4 >= k5 Then
      k4 = k4
      k4 = k4
   ElseIf k5 >= k4 Then
      temp = k4
      k4 = k5
      k5 = temp   
   EndIf
   karte_rnd_s(1) = k1
   karte_rnd_s(2) = k2
   karte_rnd_s(3) = k3
   karte_rnd_s(4) = k4
   karte_rnd_s(5) = k5


Ist zwar etwas Spaghetticode-Artig (Qbasic like...), funktioniert aber einwandfrei! Das Rar-Archiv (5cards.rar) ist auch aktualisiert!
While (1) : Wend

Neue Antwort erstellen


Übersicht BlitzBasic Allgemein

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group