last day (20 days later) » 

7:56 PM
Hi!
 
howdy, how are you?
 
Good, yourself?
For reference here is the code we were discussing:
public Rank GetRankForCard(int card)
{
     return (Rank)(card % 13);
}

public Suit GetSuitForCard(int card)
{
    return (Suit)(card / 13);
}
 
I'm very good.
yes
 
Could you expand on which part of that was confusing?
 
My question to you is:
why are you taking the card variable and dividing or using the modulo operator on it?
And I looked up enums and its a pretty basic concept, but I dont quite understand how you getting the cards out of the deck
Im sorry if my questions arent making a bunch of sense, you are talking to a brand new c# student
 
8:06 PM
no problem
give me a sec, and I'll answer those :)
Okay, for the first one.
I'm using both division and modulo to get my number in the range I want
With the desirable side effect that it causes repeating patterns.
So for modulo, the pattern of i % 13 as i increases will be 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 0, 1, 2 and so on
Which happens to map perfectly to the Rank enum I set up
In the division case, by dividing by 13, 0-12 will return 0, 13-25 1, and so on
obviously a value outside the range (52 for instance) will not work
but thats outside my expected input range, so thats ok
The function could easily throw if the input was outside the range, but you don't really need that at this point
And those ranges correspond to the correct members of the Suit enum
 
ok i follow
 
Now obviously, thats not just coincidence, I designed both functions and the enums to match the algorithm patterns (as well as the card->number map)
It just so happens that the card division/modulo algorithms are pretty well known
 
its very well done and simple, it taught me the concepts much better than the msdn lol
oh, well i didnt know so thank you for the education
now as for the deck organization
 
No problem, wouldn't expect you to know :)
Right
 
I understand the queue mechanic pretty well I feel
but Im not understanding what one's deck would look like if it were feeding into this enum
Or i guess into the Suit and Rank methods
functions*
 
8:20 PM
Your deck would be a Queue<int>
 
which then call the enum functions
 
And methods is actually more correct than functions
When I did Cribbage, I actually made a Card class
That just held the number, but also had all the associated Suit/Rank methods.
But you could totally just do a Queue<int>
Then to get the top card of the deck, you just call deck.Dequeue()
and feed that number into the aforementioned methods
Does that make sense?
 
I think...
So while i am storing each card as a two number address in my array
 
You shouldn't need to do that
 
you would have each card individually in a queue
 
8:24 PM
Right
I've found that programming as if they were real objects makes for the best code
 
but if I was doing that why would I not just hardcode each card as a string in that queue "King of Hearts" etc...
 
You could do that of course, but you need the number for other cribbage functions
 
oh of course
 
For example, checking if a hand has a flush, etc.
 
yes ok, so you would store them as what for example? Im trying to imagine this myself but its not happening.
OH!!!
So just the numbers one through 52 in the queue
 
8:27 PM
0 - 51
but yes
shuffled of course
 
and then each number has its own unique identity when put into each enum
 
Exactly
 
because of the functions they are fed through
that makes a ton of sense now
ok. That is awesome
One would think that it would be super easy to find this info on the web somewhere compiled for standard things like a deck of cards; like you had stated above. It just wasnt showing up no matter where and how I looked.
 
I'm sure its out there somewhere
 
The issue with being a beginner in any language I guess is that I dont know how to ask my questions lol rather than what to ask
Im sure youre right lol
 
8:29 PM
That tends to be the problem
For instance, a copy of my solution appears to be here: satalketo.com/2013/04/deck-of-cards-in-c
Though it doesn't use the numbers the way I do
Just goes to show there is more than one way to skin the cat
 
Thank you so much for your help. I am going to try and digest this all some more and then re-post summarizing your answer within an example of how I fixed it after you told me to so that slower people like myself can get through things lol
And that is most definitely true with this any kind of coding Im finding out. And it looks like as a project gets larger the ways to complete it grow exponentially
 
Thats definitely true
If you would like to simply suggest an edit to my existing answer, I'd be happy to include it
 
Anyways thank you very much! You were without a doubt the best answer to the question, and easiest to understand
 
No problem, glad to help
I'm around in the WPF chat room most days if you have any other quick questions.
Also consider marking the answer that helped the most as "accepted". There's no obligation to do so of course.
 
Im new to the forums, this is my second post. Would that be better to do? I had just seen a button that stated "answer your question" so I thought that was to be concluding thoughts acknowledging the person who gave me the answer that solved my problems with the solution in my code
 
8:36 PM
Stack Overflow doesn't work like a "traditional" forum
You indicate that the answer helped you by upvoting, and if you are the asker, you can "accept" the one that helped you the most
You typically don't self-answer
Though you certainly can
New users tend to mis-use that feature though
 
I will of course, as it most certainly will occur in the code for this program. I will include citations if I ever re post it. I know that this isnt a groundbreaking chunk of code but you have definitely done a lot of work for me here
gottcha
 
Now, if you liked a particular answer, but feel that it needs some extra information, feel free to suggest it as an edit (with the "edit" link below it)
 
Well then I will simply just acccept yours as that it what happened and that will be that lol
 
or just leave a comment asking the poster to include the information
That works too :)
Just trying to make sure you have all the options
You may want to consider reading some of the articles here: stackoverflow.com/help
 
Sweet. Well I gotta eat some lunch before my break is over lol Thank you again so much. I know it might seem goofy to someone who does this all the time, but I get pretty stoked when I figure something like this out and you just did that for me so I owe ya lol
 
8:40 PM
I get stoked for stuff like this all the time
Couldn't do the job if I didn't
Enjoy your lunch!
 
I will try to before posting again, I try not to sound too ignorant when on these things. I know how irritating it can be when someone comes into forum and starts asking all the wrong questions the wrong way
you enjoy your day! thank you very much
 
No problem, and you didn't do that :) Your question was very good, especially for someone new.
 

  last day (20 days later) »