| | |
Tic Tac Toe AI help, where to reset variables.
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2005
Posts: 23
Reputation:
Solved Threads: 0
I have just started using C++ after a year or two of a BASIC language, and I wanted to do something that required some logic, but not a lot of different commands. I decided to do a tic tac toe playing program where your opponent was the program.
The way this is supposed to work is that the program goes through loops and put down pieces until the game ends, and keeping track of wins, losses, and draws in all of those possibilities, and find the best move based on the count. My question comes as pieces are put down, and after the sim-game has ended inside the counting cycle. I'm almost sure that if the spaces are not reset to empty before the next time it is used, it will interefere with the simulations. I was wondering when an where to reset the spaces.
My time on the computer is almost up for a while so I will post the start of my code and return tomorrow.
Thank you for whatever help I get and I am sorry for not being able to answer any questions today.
The way this is supposed to work is that the program goes through loops and put down pieces until the game ends, and keeping track of wins, losses, and draws in all of those possibilities, and find the best move based on the count. My question comes as pieces are put down, and after the sim-game has ended inside the counting cycle. I'm almost sure that if the spaces are not reset to empty before the next time it is used, it will interefere with the simulations. I was wondering when an where to reset the spaces.
My time on the computer is almost up for a while so I will post the start of my code and return tomorrow.
C++ Syntax (Toggle Plain Text)
//simple AI for tic tac toe. //load headers and namespace #include <iostream> #include <conio.h> #include <windows.h> using namespace std; //begin main function int main() { int pos [9] ; int turn ; turn=9 ; int space [9] ; int wins [9] ; int move [9] ; /* space positions 1 2 3 4 5 6 7 8 9 Winning possibilities 1 2 3 - - - - - - - - - 4 5 6 - - - - - - - - - 7 8 9 1 - - 4 - - 7 - - - 2 - - 5 - - 8 - - - 3 - - 6 - - 9 1 - - - 5 - - - 9 - - 3 - 5 - 7 - - */ //first turn if (turn==9) { //first turn, layer 1 for (pos [1]=1; pos [1]<4; pos [1]++) { //reset all spaces to unocupied (0) pos [1]=0; pos [2]=0; pos [3]=0; pos [4]=0; pos [5]=0; pos [6]=0; pos [7]=0; pos [8]=0; pos [9]=0; //occupy chosen space with an AI piece (1) if (pos [1]==1) {space [1]=1;} if (pos [1]==1) {space [2]=1;} if (pos [1]==1) {space [5]=1;} //first turn, layer 2 for (pos [2]=1; pos [2]<10; pos [2]++) { //check to see if chosen space is unoccupied or not if (space [pos [2]]=0) { //occupy space with human piece (2) space [pos [2]]=2; //first turn, layer 3 for (pos [3]=1; pos [3]<10; pos [3]++) {
Thank you for whatever help I get and I am sorry for not being able to answer any questions today.
![]() |
Similar Threads
- TIC TAC TOE automized player....is me!! (C++)
- Critique this code (my own simple tic tac toe) (C++)
- Tic-Tac-Toe (C++)
- Tic Tac Toe help (Java)
- Tic-Tac-Toe Game (Visual Basic 4 / 5 / 6)
- Tic-Tac-Toe Game - Need some information or help (C++)
- C++ Tic Tac Toe using classes & operator overloading (C++)
Other Threads in the C++ Forum
- Previous Thread: Base converter
- Next Thread: keystroke help
| Thread Tools | Search this Thread |
api array based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news node numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets





