[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Quick help please

Posted on 2013-12-02
7
Medium Priority
?
347 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 672 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 664 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 664 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Programming  of  forecasting lottery numbers for self use  on Turbo C++ is done by use of random number generator code by a program algorithm logic. Random numbers usually generates numbers between definite interval. Therefore, when entering the c…
Article by: Nadia
Suppose you use Uber application as a rider and you request a ride to go from one place to another. Your driver just arrived at the parking lot of your place. The only thing you know about the ride is the license plate number. How do you find your U…
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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

656 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