Programming the computer to guess and improving the program.

I'm almost done with this program that I made. All I want to know is what are the many different ways to emit a response from the computer(AI's, garnering a response from them, making them move). You don't need to show me an example, just point me in the right direction. Don't forget to read my code and see if there's something I can improve. Thanks and have a good day.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include <iostream>
#include <ctime>
#include <limits>
#include <random>

using namespace std;

enum difficulty {EASY,NORMAL,HARD} settings;

int generator1()
{
    mt19937 randomGenerator(time(NULL));
    uniform_int_distribution<int> randomNumber(1,10);
    return randomNumber(randomGenerator);
}

int generator2()
{
    mt19937 randomGenerator(time(NULL));
    uniform_int_distribution<int> randomNumber(1,100);
    return randomNumber(randomGenerator);
}

int generator3()
{
    mt19937 randomGenerator(time(NULL));
    uniform_int_distribution<int> randomNumber(1,1000);
    return randomNumber(randomGenerator);
}

int main()
{
    int guessNumber, correctNumber = 0, guessCount = 0, guessLimit = 0;
    string gameDifficulty;

    cout << "Welcome to my guessing game program. Let's us begin. \n";
    cout << "\nPress any button to continue... ";
    cout << endl;
    cin.get();

    cout << "                    ---------------------------------";
    cout << "\nSettings available: |EASY\tNORMAL\t\tHARD|" << endl;
    cout << "                    ---------------------------------";

    cout << endl;

    cout << "                 -----------------------------------------------------";
    cout << "\nGuessing limit:  | Easy:5 Guesses  Normal:25 Guesses  Hard:50 Guesses| " << endl;
    cout << "                 -----------------------------------------------------";

    cout << "\n\nPlease enter the difficulty that you would like. ";
    getline(cin, gameDifficulty, '\n');

    cout << endl;

    while(gameDifficulty != "EASY" && gameDifficulty != "NORMAL" &&
          gameDifficulty != "HARD" && gameDifficulty != "easy" &&
          gameDifficulty != "normal" && gameDifficulty != "hard")
    {
        cerr << "This setting is nonsense. Pick a real setting. ";
        cin >> gameDifficulty;
        cin.ignore(numeric_limits<streamsize>::max(), '\n');
    }

    if(gameDifficulty == "EASY" || gameDifficulty == "easy")
    {
        guessLimit = 5;
        settings = EASY;
    }
    else if(gameDifficulty == "NORMAL" || gameDifficulty == "normal")
    {
        guessLimit = 25;
        settings =  NORMAL;
    }
    else if(gameDifficulty == "HARD" || gameDifficulty == "hard")
    {
        guessLimit = 50;
        settings = HARD;
    }

    switch(settings)
    {
    case 0:
        correctNumber = generator1();
        break;
    case 1:
        correctNumber = generator2();
        break;
    case 2:
        correctNumber = generator3();
    }
    cout << "\nGuess What number I'm thinking. ";
    cin >> guessNumber;

    do
    {
        while(!(cin))
        {
            cerr << "\nIncorrect input. Please try again. ";
            cin.clear();
            cin.ignore(numeric_limits<streamsize>::max(), '\n');
            cin >> guessNumber;
        }
        if(guessNumber < 0)
        {
            cerr << "\nThe number that you entered is negative.";
            cerr << " Please enter a positive number to \ncontinue. ";
            cin.ignore(numeric_limits<streamsize>::max(), '\n');
            cin >> guessNumber;
        }
    }
    while(guessNumber < 0);

    cout << endl;


    while(guessNumber != correctNumber && guessCount < guessLimit)
    {
        cout << "\nSorry, no cigar. ";
        cin >> guessNumber;
        guessCount++;
    }

    if(guessNumber == correctNumber)
    {
        cout << "\nCongratulations, you guessed the right number. ";
        cout << "\n\nIt only took " << guessCount << " guesses to guess ";
        cout << "the correct number. " << endl;
    }
    else
        cout << "\nBetter luck next time sucker. " << endl;

}
Last edited on
Does anybody have any input?
well, I've been digging around the internet and found that linked lists are typically useful for creating AIs. Would a linked list be appropriate for my program considering the way I structured my program?
So, I've been fixing some errors inside my program and I was wondering if you guys could test run my program to see if you guys can find any errors as well. Please respond back if you do and the line that it occurs on. Also, if you don't find any errors, I implore you to leave some ideas or suggestion on how I can further improve this program. Thanks, yours truly, deathslice.
Last edited on
Topic archived. No new replies allowed.