I'm trying to make this NIM game and i'm having a lot of trouble trying to get the AI going.
I want to get the computer to pick a stick(s) from a specific group.However , i don't want it to be random , thats easy and dumb.
The whole goal from this game is to leave ur opponent with the last stick.
Right now all i have is one player playing by himself.
This is the code so far:-
The display function is in my previous thread (if anybody wants to see)
==============================================================
============================================================
I know i'm asking for too much , so any help is aprreciated
I just started programming in c++ , i did read up on the game , there is a mathematical theory behind winning the NIM game.The only problem is that its alot harder for me to translate it into code.
I want to get the computer to pick a stick(s) from a specific group.However , i don't want it to be random , thats easy and dumb.
The whole goal from this game is to leave ur opponent with the last stick.
Right now all i have is one player playing by himself.
This is the code so far:-
The display function is in my previous thread (if anybody wants to see)
==============================================================
Code:
int intGroup[6] = {0, 1, 2, 3, 4, 5};
int intGroupNum;
int intSticks;
Display(intGroup);
while(1)
{
cout << "Player one, choose a group between 1-5: ";
cin >> intGroupNum;
while(intGroupNum < 1 || intGroupNum > 5 || intGroup[intGroupNum] <=0)
{
cout << "Not a valid row, please try again (1-5): ";
cin >> intGroupNum;
}
cout << "How many will you take from group " << intGroupNum << "?";
cin >> intSticks;
while(intSticks < 1 || intGroup[intGroupNum] - intSticks < 0 || intSticks < 1)
{
cout << "Not a valid amount!\n" << "Pick again: ";
cin >> intSticks;
}
intGroup[intGroupNum] = intGroup[intGroupNum] - intSticks;
Display(intGroup);
Sum(intGroup);
////////////////////////COMPUTER////////////////////////////////////////////////
////////////////////////COMPUTER////////////////////////////////////////////////
}
}
============================================================
I know i'm asking for too much , so any help is aprreciated
I just started programming in c++ , i did read up on the game , there is a mathematical theory behind winning the NIM game.The only problem is that its alot harder for me to translate it into code.