• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 358
  • Last Modified:

Quick help please

In an uno game, how do i return an array with the number of cards in each players hand ? no wild cards. do i need two loops or one ? please
0
chocolatelover911
Asked:
chocolatelover911
3 Solutions
 
käµfm³d 👽Commented:
Just the number of cards? Why would you need two loops for that? Number of cards constitutes a single dimension.
0
 
MajorBigDealCommented:
You need two loops, one to iterate the players, and one to iterate the cards in that players hand.  For example:

initialize card count array to zeros
for each player
   for each card in hand
       Add 1 to player's card count
return card count array
0
 
käµfm³d 👽Commented:
Ah, keyword "each" player's hand  : \

I agree with MajorBigDeal, though you could keep all cards inside a single array with sentinel values between each player, but that would be harder to maintain, I think.
0
 
mccarlIT Business Systems Analyst / Software DeveloperCommented:
do i need two loops or one ?
It would depend on what sort of data structures you are using. One assumption is that the cards in each players hand would be stored in a List (or a Set) type of collection, and if so then you eliminate the inner loop from MajorBigDeal's solution by replacing it with a method that returns the ".size()" of the List holding each player's cards.
0
 
TommySzalapskiCommented:
I would say don't have a loop at all. You should be maintaining that information during the game. Just keep an array that already has the number of cards in each player's hand. Every time someone plays a card, subtract one etc. Since this is for AI, you will need this information a lot. Simply keeping track will take a lot less time then going through and counting every iteration. (I'm assuming this is part of the project detailed here http:Q_28308505.html)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now