Solved

Quick help please

Posted on 2013-12-02
7
301 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 74

Expert Comment

by:käµfm³d 👽
Comment Utility
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
Comment Utility
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 74

Expert Comment

by:käµfm³d 👽
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

For those of you searching for a fun but also medium paced MMORPG game I would highly suggest Ragnarok Online. This MMORPG is a bit older than World of Warcraft and in a way is extremely different. Compared to WoW's 3D environment and massive wor…
Author Cited: Konstantinos Dimopoulos URL Cited From: Article from Indie Games: http://indiegames.com/2012/07/browser_game_pick_the_grid.html The Grid (http://codeelf.com/games/grid/) is the sort of game I haven't played in over 10 years. It is …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now