Poker checking for pair, straight,flush ect

Hey,
Do anyone of you have any idea how i would check for pairs, straight,flush ect in my poker game?
Im really new to c# and im quite clueless…
thanks!

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DrawCards : MonoBehaviour {

   
    public List<Sprite> cards = new List<Sprite>();
    public SpriteRenderer CardRenderer1;
    public SpriteRenderer CardRenderer2;
    public SpriteRenderer CardRenderer3;
    public SpriteRenderer CardRenderer4;
    public SpriteRenderer CardRenderer5;

    void Start () {
        int hand1 = Random.Range(0, 52);
        int hand2 = Random.Range(0, 52);
        int hand3 = Random.Range(0, 52);
        int hand4 = Random.Range(0, 52);
        int hand5 = Random.Range(0, 52);
        CardRenderer1.sprite = cards[hand1];
        CardRenderer2.sprite = cards[hand2];
        CardRenderer3.sprite = cards[hand3];
        CardRenderer4.sprite = cards[hand4];
        CardRenderer5.sprite = cards[hand5];

        //CHECK FOR DUPLICATE
        if(hand1 == hand2 || hand1 == hand3 || hand1 == hand4 || hand1 == hand5
             || hand2 == hand3 || hand2 == hand4 || hand2 == hand5
             || hand3 == hand4 || hand3 == hand5
             || hand4 == hand5){
            Redraw();
        }
        else{
            Debug.Log("No duplicate");
        }
       

    }

   

    public void Redraw () {
       
        Start();
        //Debug.Log("Duplicate found, re-drawing.");
    }
   

    void OnGUI(){   
    if (GUI.Button(new Rect(10, 70, 50, 30), "Reset"))
    Start();

}
}

There was this thread a little while ago where someone asked the same question. Scan through the answers there and see if it helps any.

Yes i know, that was actually my post haha. Im just really clueless and i need it to be explained really simply…

heh, interesting. I read this thread (then the other post linked), but didn’t notice that was you in there, as well.

If that’s the case, you didn’t follow up with much of the discussed topics in there.
That leads me to wonder if maybe you didn’t understand them … if that’s true, you might want to learn a few more basic ideas before proceeding.
They discussed shuffling with you, gave you some examples for checking, card classes/structs…

but here, your code posted includes very little of that.

Yes trust me i know that i should learn a few basic ideas before proceeding. The thing is i cant really.I got this as a project a few days ago and its due in a week. Im stressing my ass off haha

I find it a little weird… you’re not the first person I’ve seen that’s said they have a project due soon, but they do not know how to program. I do not understand how you can be in a course to do programming (or game design/making), and not learn the basics before being handed an assignment.
If you’re just beginning, it doesn’t hurt to learn… Saying you can’t learn because you have to finish it is quite a weird statement :slight_smile:
Use what you have learned (in class), and what you can piece together online (including the previous forum thread where you were offered help)? :slight_smile:

2 Likes

I don’t see any basic system for suits in your code. You need two variables, suits and number. You can use numbers from 0 to 3 for suits, and 0 to 12 or whatever for number. A card would be a class, or struct, of one suit and one number. Put them all in an array of 52 and shuffle them. Just google c# shuffle program or something, there should be some code around. Then you won’t have to check for duplicates, it will just shuffle all the original cards in random order. Once they are shuffled, deal them out to the players and give them a hand of 5 cards. Check each hand. Pairs are easy to check, just 2 numbers that match, etc. Make individual functions for each test, that way it will be easy to debug. Then compare the results against each other. One way would be to give each test a score and compare scores.

1 Like

I have to agree with @methos5k . You were offered tons of help, which I might add came from knowledgeable sources. Considering this is for a class it appears, I think what was given to you should be more than enough to get you started.

We can’t do the work for you and we can’t teach you if you aren’t willing to learn. If this is an important class/project, it’s going to require a bit of your time.

That was your post? I never noticed.

If you aren’t going to listen to us the first time we give you answers, why should we give you answers this time? Go back and read the other thread. Try the stuff that was suggested there. Its not our job to spoon feed you the answers, we just provide a general guide.

Indeed. Which is why for the most part I still recommend people stay away from game specific schools. As a general rule they seem to suck. I’ve seen graduates that can’t find their way around Unity. And the problem of not being taught enough to solve the assignments is common. A traditional computer science degree would be better. Or teach yourself.

A few points

  • You must learn the basics. As demonstrated by your lack of understanding of the ideas presented in the last thread. Teaching you advanced ideas is a waste of time without the basics.
  • What has your course been teaching you? Poker hands are a non-trivial concept. Which means you have either not being listening in class or you have not been taught enough. If its the first, then you deserve to fail. If its the later, get out of the course now and do another one.
  • Your stress is not my problem.

The trick is that coding is coding, whether you’re using C# in Unity or Pascal in a text-based terminal. Googling “program to check poker hands” should bring up lots of results with completed solutions, easily adapted to work in Unity C#. I’d guess that’s what your classmates are doing.

3 Likes

Check this out: