In this assignment, use mmScore that you wrote (or use mine). The general program is as follows. Your job is to implement mmConsistent in assembly language. You need to put everything in a folder called "consistent'. You need to have three files: mmScore.S, mmConsistent and testConsistent.c (the C code). A new macro needs to be defined: MM_NATTEMPTS (make it 8 to test your program).

The C code is a tester. It lets you enter the actual combination, then let you play the game (against yourself). The point is that it checks whether a guess is a good one or not. A guess is a good one if it is consistent with all previous guesses. In other words, if a new guess was the actual combination, it would have given the same numBlack and numWhite as recorded for earlier attempts.

Again, turn in your assignment as a tar file, and name it after you (how often do you get to name something after you?).




#include <stdio.h>

struct Attempt
{
char guess[(MM_NPEGS+3+3)/4*4];
int numBlack;
int numWhite;
};

struct Game
{
struct Attempt attempts[MM_NATTEMPTS];
int numAttempts;
};

int mmConsistent(struct Game *pGame);
void mmScore(const char *c1, const char *c2, int *pNumBlack, int *pNumWhite);

#if 0
int mmConsistent(struct Game *pGame)
{
int i;
int numBlack;
int numWhite;
int consistent = 1;
for (i = 0; consistent && (i < pGame->numAttempts); ++i)
{
mmScore(
pGame->attempts[i].guess,
pGame->attempts[pGame->numAttempts].guess,
&numBlack,
&numWhite
);
consistent = (numBlack == pGame->attempts[i].numBlack) &&
(numWhite == pGame->attempts[i].numWhite);
}
return consistent;
}
#endif

int main(void)
{
struct Game aGame;
char actual[MM_NPEGS+3];
int i;
aGame.numAttempts = 0;
printf("Enter the actual pattern\n");
scanf("%s",actual); // don't type excess characters, will crash the program!
do
{
printf("Enter a guess\n");
scanf("%s",aGame.attempts[aGame.numAttempts].guess);
if (mmConsistent(&aGame))
{
printf("That was a smart guess\n");
}
else
{
printf("That was not a smart guess\n");
}
mmScore(actual, aGame.attempts[aGame.numAttempts].guess,
&aGame.attempts[aGame.numAttempts].numBlack,
&aGame.attempts[aGame.numAttempts].numWhite);
printf("numBlack = %d, numWhite = %d\n",
aGame.attempts[aGame.numAttempts].numBlack,
aGame.attempts[aGame.numAttempts].numWhite);
++aGame.numAttempts;
}
while ((aGame.numAttempts < MM_NATTEMPTS) &&
aGame.attempts[aGame.numAttempts-1].numBlack < MM_NPEGS);
}
Available from: Thursday, 26 April 2007, 02:05 PM
Due date: Friday, 4 May 2007, 12:00 AM

Upload a file (Max size: 2MB)