-
December 31st, 2008, 06:15 PM
#1
Junior Member
master mind game
HALLO
i need to write a " mastermind game " and i have some problems with the functions ...hope your can help me..
#define DIGITS 4
#define LINES_IN_PAGE 20
#define NUMBERS_IN_ROW 9
#define ROWS 10
#define COLS 1000
#define STR_CHECK "CHECK"
#define STR_ALL "ALL"
#define STR_QUIT "QUIT"
#include <stdio.h> //for printf, scanf
#include <stdlib.h> //for system
#include <ctype.h> //for isupper
/***************************************************************/
/********** Functions/Functions-Declarations section *********/
/***************************************************************/
int MakeValidsMatrix(int Matrix[][COLS]); //מייצרת מטריצת מספרים תקינים
void DisplayAllValids(int Matrix[][COLS]); //מציגה את המספרים
int check(int NumToCheck); //בודקת תקינות מספר
//מחזירה מספר עמודה עם הכי הרבה מספרים תקניים
int ColWithMostValids(int Matrix[][COLS]);
int TotalInCol(int Matrix[][COLS],int col); // מחזירה סכום עמודה מבוקשת
void GetRequest(char strInp[]); //קולטת מחרוזת עם בקשת המשתמש
int CheckOne(); // קולטת מספר ומודיעה אם חוקי
int Same(char str1[],char str2[]); // בודקת שוויון מחרוזות
/***************************************************************/
/* ,התכנית מייצרת את כל המספרים הרלוונטיים למשחק בול פגיעה */
/* .כלומר כל המספרים בני 4 ספרות ללא ספרות חוזרות */
/* .השיטה: מעבר על כל המספרים הקטנים מ-10000 ובדיקת חוקיותם */
/* .התוצאה מוכנסת למטריצת תוצאות - 1 עבור מספר חוקי ו0- אחרת */
/***************************************************************/
main()
/***************************************************************/
{
char strRequest[256];
int MatrixOfValids[ROWS][COLS]={0},most;
do
{
//קליטת בקשת המשתמש
GetRequest(strRequest);
//ביצוע הבקשה
if (Same(strRequest,STR_CHECK))
{
//============================
//בדיקת מספר אחד
//============================
if (CheckOne())
printf("\n\t<<<<<<<< VALID >>>>>>>>\n");
else
printf("\n\t<<<<<<<< NOT VALID >>>>>>>>\n");
}
else
{
if(Same(strRequest,STR_ALL))
{
//============================
//טבלה שלמה
//============================
// יצירת מטריצת חוקיים והצגת כמות החוקיים
printf("\nTotal Valid Numbers:\t%d\n",MakeValidsMatrix(MatrixOfValids));;
// הצגת המספרים
DisplayAllValids(MatrixOfValids);
// הצגת מספר העמודה שמכילה הכי הרבה מספרים תקניים,וסכום התקניים בעמודה זו
printf("\nColumn %d has most valids (%d)\n\n",
most=ColWithMostValids(MatrixOfValids),TotalInCol(MatrixOfValids,most));
}
}
}while(!Same(strRequest,STR_QUIT));
}
void GetRequest(char strInp[]) //קולטת מחרוזת עם בקשת המשתמש
{
char strRequest[256]={0};
printf ("please enter:\n CHECK\n ALL\n QUIT\n");
fflush(stdin);
gets(strRequest);
}
int Same(char str1[],char str2[]) // בודקת שוויון מחרוזות
{
char strRequest[256]={0};
int same=0 ;
int i;
strcmp (strRequest,STR_CHECK);
//if (strcmp==0)
// same=1 ;
// return same;
}
int CheckOne() // קולטת מספר ומודיעה אם חוקי
{
char arr[4];
int z;
int flag=0;
printf (" please enter 4 digits num:\n ");
gets (arr);
for (z=1;z<arr;z++)
{
if (arr[0] == arr[z])
flag=1 ;
}
for (z=2;z<arr;z++)
{
if (arr[1] == arr[z])
flag=1 ;
}
for (z=3;z<arr;z++)
{
if (arr[2] == arr[z])
flag=1 ;
}
return flag;
}
int MakeValidsMatrix(int Matrix[][COLS]) //מייצרת מטריצת מספרים תקינים
{
int i,j,y;
char dits[4];
int flag2=0 ;
int MatrixOfValids[ROWS][COLS]={0};
int counter=0;
for (i=0;i<ROWS;i++)
{
for (j=0;j<COLS;j++)
{
dits[4]=i*1000+j ;
for (y=1;y<4;y++)
{
if (dits[0] == dits[y])
flag2=1 ;
}
for (y=2;y<dits;y++)
{
if (dits[1] == dits[y])
flag2=1 ;
}
for (y=3;y<dits;y++)
{
if (dits[2] == dits[y])
flag2=1 ;
}
if (flag2==1)
MatrixOfValids[ROWS][COLS]=0;
else
MatrixOfValids[ROWS][COLS]=1;
counter++;
}
}
return counter ;
}
void DisplayAllValids(int Matrix[][COLS]) //מציגה את המספרים
{
int c,d;
for (c=0;c<ROWS;c++)
{
for (d=0;d<COLS;d++)
{ printf ("MatrixOfValids[c][d]");
}
printf("\n");
}
}
int ColWithMostValids(int Matrix[][COLS]) //מחזירה מספר עמודה עם הכי הרבה מספרים תקניים
{
int a,b,i;
int counter2=0 ;
int mem=0;
int MatrixOfValids[ROWS][COLS];
for (b=0,counter2=0;b<COLS;b++)
{
for (a=0;a<ROWS;a++)
{
if (MatrixOfValids[a][b]==1)
counter2++;
}
if (mem<counter2)
mem=b ;
}
return mem;
}
int TotalInCol(int Matrix[][COLS],int col)// מחזירה סכום עמודה מבוקשת
{
int a,b,i;
int counter2=0 ;
int mem=0;
int MatrixOfValids[ROWS][COLS];
for (b=0,counter2=0;b<COLS;b++)
{
for (a=0;a<ROWS;a++)
{
if (MatrixOfValids[a][b]==1)
counter2++;
}
if (mem<counter2)
mem=counter2 ;
}
return mem;
}
-
December 31st, 2008, 06:24 PM
#2
for those who don't read hebrew
The program generates all the relevant numbers game bull's eye
. This means that all of 4-digit numbers without repeated digits
. Method: Beyond all the numbers from the small and legality -10,000
. Mocnst result Lmtritzt Results - 1 for a number of laws and 0 - otherwise
09:F9:11:02:9D:74:E3:5B 8:41:56:C5:63:56:88:C0
-
January 1st, 2009, 09:00 PM
#3
Junior Member
HALLO AGAIN
sorry about the the problems...its my first time i am in here for help.
do its like this:
if the user type :
check- the user is need to press anumber of 4 digits..
there will preform if the number is legel..
legel number is :
4 dig number...with no same num retreat;
legel numbers: 1234 2703 0485
ilegel numbers: 123 12345 1232
all- (0 or 1) true or false parmaters will write into the matrix
all the legel nums should be shown
the number of the column with most legel numbers should be shown
quit- should quit
the function - MakeValidsMatrix gets matrix (with 0 inside) of ROWS(10)
(1000)COLS and puts 1 were there is fitting a legel number ..
example:
the number 1234 is legel so..Matrix[1][234] gets 1.
the number 0595 is ilegel so..Matrix[0][595] stay with 0.
i get amission to write only the 8 fucnctions....so the problem is over there
my first problem is that after the menu screen
if i write no matter what... it ask me to enter 4 numbers..
thanx for all the helpers and for your posts....i appraiser you...
sorry for the deficient spelling....
Similar Threads
-
By ThePreacher in forum Miscellaneous Security Discussions
Replies: 17
Last Post: December 14th, 2006, 09:37 PM
-
By phishphreek in forum Microsoft Security Discussions
Replies: 9
Last Post: September 25th, 2003, 08:09 PM
-
By MemorY in forum Cosmos
Replies: 31
Last Post: September 24th, 2003, 12:33 AM
-
By jethro in forum Cosmos
Replies: 1
Last Post: June 23rd, 2002, 09:14 PM
-
By Ennis in forum The Security Tutorials Forum
Replies: 4
Last Post: November 15th, 2001, 07:42 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|