memory game

Reply

Join Date: Oct 2008
Posts: 11
Reputation: egolovin is an unknown quantity at this point 
Solved Threads: 0
egolovin egolovin is offline Offline
Newbie Poster

memory game

 
0
  #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
  1. int card[6][6],total=0,value,test;
  2. srand((unsigned)time(NULL));//randomize timer
  3.  
  4. for (int i=0;i<6;i++)
  5. {
  6. for (int j=0;j<6;j++)
  7. {
  8. value=rand()%18;//random
  9. test=0;
  10. card[i][j]=value;//sets the value
  11. for (int x=0;x<6;x++)
  12. {
  13. for (int y=0;y<6;y++)//starts the check for doubles
  14. {
  15. if(value==card[x][y])
  16. {
  17. test++;
  18. cout<<i<<endl;
  19. }
  20. if (test==3)
  21. {
  22. //need a code to stop for the 3rd one to be put in.
  23. }
  24. }
  25. }
  26. }
  27. }
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,537
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: 704
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: memory game

 
0
  #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 Quick reply to this message  
Join Date: Oct 2008
Posts: 11
Reputation: egolovin is an unknown quantity at this point 
Solved Threads: 0
egolovin egolovin is offline Offline
Newbie Poster

Re: memory game

 
0
  #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 Quick reply to this message  
Join Date: Sep 2004
Posts: 7,537
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: 704
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: memory game

 
1
  #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 Quick reply to this message  
Join Date: Oct 2008
Posts: 11
Reputation: egolovin is an unknown quantity at this point 
Solved Threads: 0
egolovin egolovin is offline Offline
Newbie Poster

Re: memory game

 
0
  #5
Nov 20th, 2008
oh wow that is a different way thinking about it. thanks
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC