Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <time.h>
- #include <ctype.h>
- struct Entry{
- char word[32];
- struct Entry* next;
- };
- //GLOBAL VARIABLES
- char buffer[32];
- int guessDist[26];
- int handDist[26];
- struct Entry* wordList = NULL; //Head node for the dictionary
- //At least 6 characters
- //Easy Start option? Also make sure it has a minimum of high-frequency letters?
- int init(){
- srand(time(NULL));
- //FILE* dictionary = fopen("dictionary.txt","r");
- //if(dictionary==NULL){
- // dictionary = fopen("2of12.txt","r"); //I'd prefer to call the dictionary file 'dictionary.txt', but i assume you're going to test it with the default filename
- //}
- //if(dictionary==NULL){
- // printf("No Dictionary Found!");
- //}
- return 0; //Placeholder
- }
- void displayWorld(){
- printf("--------------------------\n"); //Placeholder
- }
- void getLetterDistribution(char *word, int *dist){
- for(int i=0;i<26;i++){
- printf("%c",i+65);
- }
- printf("\n");
- for(int i=0;i<26;i++){
- int j = 0;
- do{
- if(word[j] == i+65){ //The capital letters begin at 65 in the ascii table
- dist[i]++; //Increase the count for that letter
- }
- j++;
- }while(word[j] != '\0'); //Wait for end of word
- printf("%d",dist[i]);
- }
- printf("%ls\n",dist);
- }
- int compareCounts(int *tryWord, int *hand){ //Compare two distribution arrays
- int playable = 1; //Start by assuming the word can be played.
- int letter = 0;
- while(playable == 1 && letter < 26){ //26 elements in each array
- if(tryWord[letter]>hand[letter]){
- playable = 0; //If at any point we each a letter that isn't on hand, cut it off there.
- }
- letter++;
- }
- return playable; //Return 1 for playable and 0 for unplayable
- }
- void acceptInput(){
- printf("Enter a Guess: ");
- fgets(buffer, sizeof(buffer), stdin);
- if(buffer != NULL) { //Ensure there's something to read
- int i = 0;
- while(buffer[i] != '\0'){ //Loops through each char in sequence until it hits the null term
- //printf("%d",buffer[i]);
- buffer[i] = toupper((unsigned char)buffer[i]); //Replaces the char with its uppercase
- i++;
- }
- printf("%s",buffer);
- //*guess = *buffer;
- //printf("%s\n",guess);
- } else {
- printf("Invalid Entry\n");
- acceptInput(); //Retry input
- }
- }
- void teardown(){ //Teardown is ONE word!
- printf("All Done\n");
- }
- int isDone(){
- return 1; //crude implementation of boolean logic: 1 or 0
- }
- void gameLoop(){
- char testHand[12] = "ACEROLAORIO\0"; //TEST INVOCATIONS
- int testHandDist[26];
- do{
- displayWorld();
- printf("Hand: %s\n",testHand);
- acceptInput();
- getLetterDistribution(testHand,handDist);
- //printf("%s\n",buffer);
- getLetterDistribution(buffer,guessDist);
- printf("%d\n",compareCounts(guessDist,handDist));//TEST INVOCATIONS
- }while(isDone()!=1);
- }
- int main(){
- init();
- gameLoop();
- teardown();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement