Ok here is a situation.
"I have to create tic tac toe game.
The program provides a level playing field for two players , check the correctness of the march , followed by the situation on the field , and removes the winner.
The program play against people in every walk searching for the best variant of the current situation.
At the beginning you choose to offer - to play against people or against the computer . At the end of the game offers to play again. "
Besically i have to create game with menu where you chose to play with player 2 or PC.
i have some ideas how to do this by creating a field with numbers
123
456
789
and than when you enter number it changes to "x" or "o"...
also if i could create a field with lines it would be awesome like this or something like that:
1 | 2 | 3
----------
4 | 5 | 6
----------
7 | 8 | 9
I would appreciate any help you guys could provide ;)
yep something like that but i just thought that fields should be filed with something first so its easier to mark the right field... maybe i dont know maybe sounds crazi but is it possible to mark fields with numbers but hide them llike it works by entering number but on screen it apears as blank like
1 | 2 | 3
----------
4 | 5 | 6
----------
7 | 8 | 9
ok i was able to make a game against player still need to figure out how to:
*make mennu where you can chose to play against player or PC
*after every game how to add "do you want to play again" and return to menu
*and make player 2 PC VI who will play with player :)
*make mennu where you can chose to play against player or PC
1) Move actual game outside of main.
2) Create menu like that:
1 2 3 4 5 6 7 8 9 10
int main()
{
int choice;
std::cout << "1. VS Human\n2. VS PC"
std::cin >> choice;
switch(choice) {
case 1: play_vs_human(); break;
case 2: play_vs_PC(); break;
}
}
You will need to implement play_vs_* functions (or replace them with something equivalent)
*after every game how to add "do you want to play again" and return to menu
Wrap your menu selection in loop:
1 2 3 4 5 6 7 8 9 10
int main()
{
std::string answer;
do {
//Menu from previous point
std::cout << "Do you want to play again? (y/n)\n";
std::cin >> answer
} while(answer == "y");
}
*and make player 2 PC VI who will play with player :)
When it is PC turn, instead of asking for input, call function which checks board state and returns position. Implement AI in that function (good strategy to begin will be selecting random move from avaliable positions)
thanks @MiiNiPaa couldn't have done it without your help guess i have figured everything out and now i only have to add some tweaks but it works perfectly :)