RSS Forums RSS

memory game

Please support our C++ advertiser: Programming Forums
Reply
Posts: 11
Reputation: egolovin is an unknown quantity at this point 
Solved Threads: 0
egolovin egolovin is offline Offline
Newbie Poster

memory game

  #1  
Nov 20th, 2008
Hi all i am working on a memory game and i am having problems inputing the data so it checks if a 3rd number is pulled up to ignore it
thanks in advance
int card[6][6],total=0,value,test; 
	srand((unsigned)time(NULL));//randomize timer

	for (int i=0;i<6;i++)
	{
		for (int j=0;j<6;j++)
		{
			value=rand()%18;//random
			test=0;
			card[i][j]=value;//sets the value
			for (int x=0;x<6;x++)
			{
				for (int y=0;y<6;y++)//starts the check for doubles
				{
					if(value==card[x][y])
					{
						test++;
						cout<<i<<endl;
					}
					if (test==3)
					{
						//need a code to stop for the 3rd one to be put in.
					}
				}
			}
		}
	}
AddThis Social Bookmark Button
Reply With Quote  
Posts: 7,460
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 676
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: memory game

  #2  
Nov 20th, 2008
It might help to describe how the game works and how your program logic accomplishes that. Saying that you need some code for the program to ignore a 3rd number that's pulled up means nothing to us.
I'm here to prove you wrong.
Reply With Quote  
Posts: 11
Reputation: egolovin is an unknown quantity at this point 
Solved Threads: 0
egolovin egolovin is offline Offline
Newbie Poster

Re: memory game

  #3  
Nov 20th, 2008
well it is a memory game where you match 2 numbers
and i want random numbers between 0 and 17 on the board i need 2 of the same number on the board
Reply With Quote  
Posts: 7,460
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 676
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: memory game

  #4  
Nov 20th, 2008
So you want to populate the board with random numbers in the range of [0, 18) and disallow more than two of a kind? I'd say use a frequency table for the range since it's small, and repeat getting the random number until you find one that doesn't go beyond the limit:
  1. #include <cstdlib>
  2. #include <iomanip>
  3. #include <iostream>
  4.  
  5. int main()
  6. {
  7. using namespace std;
  8.  
  9. int board[6][6];
  10. int freq[18] = {0};
  11.  
  12. for ( int i = 0; i < 6; i++ ) {
  13. for ( int j = 0; j < 6; j++ ) {
  14. int r;
  15.  
  16. do
  17. r = rand() % 18;
  18. while ( freq[r] >= 2 );
  19.  
  20. ++freq[r];
  21. board[i][j] = r;
  22. }
  23. }
  24.  
  25. for ( int i = 0; i < 6; i++ ) {
  26. for ( int j = 0; j < 6; j++ )
  27. cout<< left << setw ( 3 ) << board[i][j];
  28. cout<<'\n';
  29. }
  30. }
The frequency table holds a count of all of the values in your range.
I'm here to prove you wrong.
Reply With Quote  
Posts: 11
Reputation: egolovin is an unknown quantity at this point 
Solved Threads: 0
egolovin egolovin is offline Offline
Newbie Poster

Re: memory game

  #5  
Nov 20th, 2008
oh wow that is a different way thinking about it. thanks
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Similar Threads
Other Threads in the C++ Forum
Views: 315 | Replies: 4 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 3:24 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC