Solved

Quick help please

Posted on 2013-12-02
7
320 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
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 35

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

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

Suggested Solutions

See the related links at the bottom of the tutorial for downloads and supplemental information. Introduction The Nvidia 3D Vision Kit is a [not so] new gaming technology which allows you to play the newest computer games in "Stereo 3D" (like …
As we all know Counter Strike is a very popular computer game. Usually it is played over a network for which people create a server and users join it but it is interesting to know that one can creates a dedicated server which not only hosts the game…
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…

827 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