I'm asked to implement this method:
You must use a 2D array to store the moves history table.
Definition of what moves are stored:
Enter 1 or 0, trying to outsmart the computer, which is going to attempt to forecast your guesses. On each move the score indicator moves to the left if the computer guesses correctly, and moves to the right if the computer does not.
Example of moves:
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
|
void DisplayBoard() {
int start = 10;
const int width = 19;
char boardSize[width] = { " " };
boardSize[start] = '^';
cout << "x---------x+++++++++x" << endl;
for (int i = 0; i < width; i++) {
cout << boardSize[i];
}
cout << "\n";
start = start - 1;
start = start + 1;
if (start == 5)
cout << "You're going to lose!" << endl;
else (start == 15);
cout << "You're winning!" << endl;
}
|
The table must be updated each move (starting on the 4th move) to reflect what was chosen in each last-three-moves situation. [However there is no penalty if you use the general-case code for the first three moves.]
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
|
int main(){
int userInput;
int i,j;
int historyTable[8][2] = { {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0} };
*/
DisplayBoard();
cout << turnCounter << Your input: ";
cout << endl;
cin userInput;
turncounter++
// i have not implemented fully yet, this table should only be displayed when pressing T
// i need some type of dynamic array, to store and later on compare my last 3 moves and predict the next move.
if (lastThree == 000) && (nextMove = 0){
historyTable[1][1] = historyTable[1][1] = + 1;
}
else if (lastThree == 000) && (nextMove == 1){
historyTable[1][2] = historyTable[1][2] = + 1;
}
for (i = 0 ; i < 8; i++)
{
for (j = 0; j < 2; j++) { // made into 3 rather than 2
cout << setw(2) << historyTable[i][j];
}
cout << endl;
}
return 0;
}
|
the expected output of the table looks like this
-----0 1
--- ---
000 0 0
001 0 0
010 0 0
011 0 0
100 0 0
101 0 0
110 0 0
111 0 0
How can i print the binary converted numbers 1-8 on the left hand side of my array?
Second,
How can i create a second array, which is a dynamic array that stores all user inputs of either 1 or 0's to take the last 3 entered, update the table, and make a prediction of the next move if the prediction for the next move is based on the last 3 moves.
If the first three moves are 001, the computer would predict a random number 0 or 1 since there is no history of the this combination stored in the table. If the computer picks 0 and the players 4th move is 0, historyTable[2][1] will increment by 1 and computer will get a point. and if the historyTable[2][1] > historyTable[2][2] computer will predict a 0 for the 4th number next time the user enters 0 0 1, however if this time the user enters a 1, Increment historyTable[2][2] by +1, and so on for every possible combination.
What i described above is what ill be basing my predictions and output to the historyTable.