Solved

Quick help please

Posted on 2013-12-02
7
332 Views
Last Modified: 2014-01-06
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
Comment
Question by:chocolatelover911
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39691591
Just the number of cards? Why would you need two loops for that? Number of cards constitutes a single dimension.
0
 
LVL 11

Accepted Solution

by:
MajorBigDeal earned 168 total points
ID: 39691592
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
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39691602
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
 
LVL 36

Assisted Solution

by:mccarl
mccarl earned 166 total points
ID: 39691667
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
 
LVL 37

Assisted Solution

by:TommySzalapski
TommySzalapski earned 166 total points
ID: 39692754
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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The greatest common divisor (gcd) of two positive integers is their largest common divisor. Let's consider two numbers 12 and 20. The divisors of 12 are 1, 2, 3, 4, 6, 12 The divisors of 20 are 1, 2, 4, 5, 10 20 The highest number among the c…
Prime numbers are natural numbers greater than 1 that have only two divisors (the number itself and 1). By “divisible” we mean dividend % divisor = 0 (% indicates MODULAR. It gives the reminder of a division operation). We’ll follow multiple approac…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question