Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 136,080 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,589 people online right now. Registration is fast and FREE... Join Now!




c# arrays for beginners

 
Reply to this topicStart new topic

c# arrays for beginners, counting no of same values in an array

c#newbiefc
11 Apr, 2008 - 08:27 AM
Post #1

New D.I.C Head
*

Joined: 11 Apr, 2008
Posts: 6

hi. im trying to design a poker game as a windows application.i have managed to dealcards and now trying to score each players hand.
i have tried using a string array for the 7 cards(2 player cards,5 community cards) but im getting a little stuck.
ie playerhand[7]={10h,10s,7c,ad,ah,ks,3c},
i am trying to find a way of extracting cards with same value(ie 10h,10s) to
determine whether player has a pair (or 2pair,3 of akind,4 of a kind etc.)

can anybody point me in the right direction here?
User is offlineProfile CardPM
+Quote Post

killnine
RE: C# Arrays For Beginners
11 Apr, 2008 - 09:38 AM
Post #2

D.I.C Head
**

Joined: 12 Feb, 2007
Posts: 107



Thanked: 3 times
My Contributions
QUOTE(c#newbiefc @ 11 Apr, 2008 - 09:27 AM) *

hi. im trying to design a poker game as a windows application.i have managed to dealcards and now trying to score each players hand.
i have tried using a string array for the 7 cards(2 player cards,5 community cards) but im getting a little stuck.
ie playerhand[7]={10h,10s,7c,ad,ah,ks,3c},
i am trying to find a way of extracting cards with same value(ie 10h,10s) to
determine whether player has a pair (or 2pair,3 of akind,4 of a kind etc.)

can anybody point me in the right direction here?



Okay.
I am assuming your array is a bunch of strings. This might make what you are trying to do a little difficult.

I dont know specifically how you are doing this, but I might suggest going back and designing your application a little differently.

I would make a card class, with properties "Value" and "Suit". Then create a global enumerator (http://msdn2.microsoft.com/en-us/library/sbbt4032(VS.80).aspx) for the different values (Ace through King) and a global enumerator of the suit (Clubs, Hearts, Spades, Diamonds). This way it will be easier to compare what your hand is.

If you really want to get fancy, you could create a comparable interface that would allow you to simply input two different "hands" (another class you might consider making) and see which is higher. Here is potentially some demo code.

I wrote this in like....5 minutes. But I hope it gives you an idea of where you may start. I also suggested making a "Hand" class for each player...

CODE

using System;

public enum Value
{
    One,
    Two,
    Three,
    Four,
    Five,
    Six,
    Seven,
    Eight,
    Nine,
    Ten,
    Jack,
    Queen,
    King,
    Ace

}

public enum Suit
{
    Hearts,
    Clubs,
    Diamonds,
    Spades
}

public class Card
{
    Suit type;
    Value cardValue;

    public Card(Value newCardValue, Suit newCardSuit)
    {
        cardValue = newCardValue;
        cardSuit = newCardSuit;
        
    }

    public Suit cardSuit
    {
        get { return type; }
        set { this.type = value; }
    }

    public Value cardValue
    {
        get { return cardValue; }
        set { this.cardValue = value; }
    }
    
}


User is offlineProfile CardPM
+Quote Post

wiko
RE: C# Arrays For Beginners
15 Apr, 2008 - 09:06 AM
Post #3

New D.I.C Head
*

Joined: 15 Apr, 2008
Posts: 21


My Contributions
I absolutely agree with killnine. This is absolutely what I was thinking of!
Welldone smile.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 07:29PM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month