Würfelpoker programmieren?
Hallo liebe Community,
ich muss ein Würfelspiel, also in dem Falle Würfelpoker programmieren. Dort gibt es dann verschiedene Enden. Grand Poker Full House oder nichts. Grand erreicht man zum Beispiel wenn die Augenzahl bei allen 5 Würfeln gleich ist. Wie kann man das in C schreiben
2 Antworten
Genau so ein Spiel habe ich programmiert aber es ist in Visual Basic. Den Teil mit den Würfen erkennen kann ich dir liefern:
a() stellt ein Array der 5 gewürfelten Zahlen dar.
Private Function is3Pasch(ByVal a() As Integer) As Boolean
Array.Sort(a)
is3Pasch = False
If a(1) = a(2) And a(1) = a(3) Then
is3Pasch = True
End If
If a(2) = a(3) And a(2) = a(4) Then
is3Pasch = True
End If
If a(3) = a(4) And a(3) = a(5) Then
is3Pasch = True
End If
End Function
Private Function isFool(ByVal a() As Integer) As Boolean
Array.Sort(a)
If a(1) = a(2) And a(1) = a(3) And a(4) = a(5) Then
isFool = True
Exit Function
End If
If a(1) = a(2) And a(3) = a(4) And a(3) = a(5) Then
isFool = True
Exit Function
End If
isFool = False
End Function
Private Function isPoker(ByVal a() As Integer) As Boolean
Array.Sort(a)
If a(1) = a(2) And a(1) = a(3) And a(1) = a(4) Then
isPoker = True
Exit Function
End If
If a(2) = a(3) And a(2) = a(4) And a(2) = a(5) Then
isPoker = True
Exit Function
End If
isPoker = False
End Function
Private Function isKlStr(ByVal a() As Integer) As Boolean
Array.Sort(a)
isKlStr = False
If a(1) = 1 And a(2) = 2 And a(3) = 3 And a(4) = 4 Then
isKlStr = True
End If
If a(1) = 1 And a(2) = 1 And a(3) = 2 And a(4) = 3 And a(5) = 4 Then
isKlStr = True
End If
If a(1) = 1 And a(2) = 2 And a(3) = 2 And a(4) = 3 And a(5) = 4 Then
isKlStr = True
End If
If a(1) = 1 And a(2) = 2 And a(3) = 3 And a(4) = 3 And a(5) = 4 Then
isKlStr = True
End If
If a(1) = 2 And a(2) = 2 And a(3) = 3 And a(4) = 4 And a(5) = 5 Then
isKlStr = True
End If
If a(1) = 2 And a(2) = 3 And a(3) = 4 And a(4) = 5 Then
isKlStr = True
End If
If a(1) = 3 And a(2) = 4 And a(3) = 5 And a(4) = 6 Then
isKlStr = True
End If
If a(1) = 2 And a(2) = 3 And a(3) = 4 And a(4) = 4 And a(5) = 5 Then
isKlStr = True
End If
If a(1) = 3 And a(2) = 3 And a(3) = 4 And a(4) = 5 And a(5) = 6 Then
isKlStr = True
End If
If a(1) = 1 And a(2) = 3 And a(3) = 4 And a(4) = 5 And a(5) = 5 Then
isKlStr = True
End If
If a(1) = 1 And a(2) = 3 And a(3) = 4 And a(4) = 5 And a(5) = 6 Then
isKlStr = True
End If
End Function
Private Function isStrasse(ByVal a() As Integer) As Boolean
Array.Sort(a)
If a(1) = a(2) Then
isStrasse = False
Exit Function
End If
If a(2) = a(3) Then
isStrasse = False
Exit Function
End If
If a(3) = a(4) Then
isStrasse = False
Exit Function
End If
If a(4) = a(5) Then
isStrasse = False
Exit Function
End If
If a(1) = 1 And a(5) = 6 Then
isStrasse = False
Exit Function
End If
isStrasse = True
End Function
Private Function is50(ByVal a() As Integer) As Boolean
If a(1) = a(2) And a(1) = a(3) And a(1) = a(4) And a(1) = a(5) Then
is50 = True
Else
is50 = False
End If
End Function
Private Function isOnePair(ByVal a() As Integer) As Boolean
Array.Sort(a)
isOnePair = False
If a(1) = a(2) Then isOnePair = True
If a(2) = a(3) Then isOnePair = True
If a(3) = a(4) Then isOnePair = True
If a(4) = a(5) Then isOnePair = True
End Function
Private Function isTwoPair(ByVal a() As Integer) As Boolean
Array.Sort(a)
isTwoPair = False
If a(1) = a(2) And a(3) = a(4) Then isTwoPair = True
If a(1) = a(2) And a(4) = a(5) Then isTwoPair = True
If a(2) = a(3) And a(4) = a(5) Then isTwoPair = True
End Function
Private Function isTreeOfKind(ByVal a() As Integer) As Boolean
Array.Sort(a)
isTreeOfKind = False
If a(1) = a(2) And a(1) = a(3) Then isTreeOfKind = True
If a(2) = a(3) And a(2) = a(4) Then isTreeOfKind = True
If a(3) = a(4) And a(3) = a(5) Then isTreeOfKind = True
End Function
du kannst mit der rand() funktion und modulo rechnung würfeln simulieren
ok, zahlen kannst du mit scanf() in z.b. ein array einlesen und dann gehst du mit ner for oder while schleife drüber und prüfst ob alle aufeinanderfolgenden (nachbarn) gleich sind, wenn ja dann sind alle zahlen gleich
Wie genau kann ich das dann schreiben ? Ich hatte angefangen mit for(i=0;i < 6;i++) und dann ein if Befehl. Was kann ich da dann jetzt eingeben damit ich Grand erhalte ?
Oder wie würdest deinen Vorschlag in ein programm eintippen?
int arr[6];
for(int i=0; i<6; ++i) scanf("%d",&arr[i]);
// Überprüfen kannst Du auch mit ner for oder while Schleife, aber das packst Du schon.
#include <stdio.h>
int main(){
const int Wuerfel = 5;
int a[Wuerfel];
int i
//Eingabe der Augenzahl
printf("Programm Wuerfelspiel\n");
for(i=0;i < Wuerfel;i++){
printf("Wuerfel %i: \n",i+1);
scanf("%i",&a[i]);
}
//Ausgabe
printf("Die Ausgabe sieht dann so aus:\n");
printf("Es wurde gewuerfelt:\n");
printf("Wuerfel \t1\t2\t3\t4\t5\n");
printf("Augenzahl\t%i\t%i\t%i\t%i\t%i\n",a[0],a[1],a[2],a[3],a[4]);
//Auswertung des Ereignisses
int j = a[0];
for(j = 0; j < Wuerfel;j++){
if(j == a[i]){
i++;
}
}
return 0;
}
Das ist mein aktueller code
das überprüfen kannst du mit einer laufvariable mach die von 0 bis einschließlich Wuerfel-2 geht, den Rest findest du schon selber raus
ok. Aber der würde dann ja random zahlen rausspucken. Bei mir ist der Fall, dass ich die Augenzahlen per Hand eingebe
Und wenn ich dann zum Beispiel 4 4 4 4 4 eingebe soll dann Grand erscheinen