Page 1 of 1
TicTacToe Feedback (console game)
Posted: Fri Nov 28, 2008 4:27 pm
by Vortex
Hey, im gonna start by saying that i am new to c++ and programming overall so dont be to harsh.
i have started my first real "projekt" and i decided to make tictactoe in console. the game itself is complete and i have made an simple "AI" (if you now can call it that) or bot that you can play against or you could play against another player.
the thing is that i need feedback on my code on bad habbits things i could do diffrent to improve so please give me so much feed back you can
i also need you guys to check the Bot if you can beat him, i wont him to be 100% unbeatable.
if you beat him dont start a new game but first post the log that will be generated in the folder where the .exe is,
post it here so i can see what you did to beat him so i can fix it.
Dowload link, i included an complete exe file for you lazy persons
http://www.uploading.com/files/AJP4SKMD ... e.zip.html
and once again, remember that im very new to c++ and this is my first "game" and project.
Pardon my imperfect english.
Re: TicTacToe Feedback (console game)
Posted: Fri Nov 28, 2008 4:30 pm
by Vortex
Oops i now saw that you have to wait 90 secounds to download...
i uploaded it here if you dont wanna wait.
http://www.2shared.com/file/4365245/f62 ... acToe.html
also come with suggestions that i can add to my game
Re: TicTacToe Feedback (console game)
Posted: Fri Nov 28, 2008 4:34 pm
by avansc
did you make it with VS? (visual studio?)
Re: TicTacToe Feedback (console game)
Posted: Sat Nov 29, 2008 4:03 am
by Vortex
Yea, Microsoft visual c++ 2008 express.
Re: TicTacToe Feedback (console game)
Posted: Sat Nov 29, 2008 10:31 am
by ismetteren
I just made an console TicTacToe game too :D but i dont have any AI
Cant wait to see how you done it
.:Edit:.
Can't open the .exe file.
it gives me an error message(in danish, i've tried to translate it):
The program could not start, because the side by side-configuration is wrong. You will find more information in the eventlogfile.
I've looked at the source. Mine seems to be more object oriented the yours(not saying that mine is better, i guess it is about perferrence). Ive found out to check for win this way(instead of checking every win posibility):
Code: Select all
int Game::checkForWin()
{
list<int> xCord;
list<int> yCord;
for(int i = 0; i < 2; i++)
{
for(int y = 0; y < 3; y++)
{
for(int x = 0; x < 3; x++)
{
if(board.getPiece(x, y) == players.at(i).getPiece())
{
xCord.push_back(x);
yCord.push_back(y);
}
}
}
if(xCord.size() == 3 && yCord.size() == 3)
{
int xSize = xCord.size();
xCord.sort();
xCord.unique();
int ySize = yCord.size();
yCord.sort();
yCord.unique();
//checks if all xCord or yCord values are euqual, and there therfore is an horizonal or vertical win
if(xCord.size() == 1 || yCord.size() == 1)
{
cout << players.at(i).getName() << " " << " WON!!!" << endl;;
done = true;
}
//checks if all xCord or yCord values are non-euqual, and there therfore is an diagonal win
if(xCord.size() == xSize && yCord.size() == ySize)
{
cout << players.at(i).getName() << " " << " WON!!!" << endl;;
done = true;
}
}
xCord.clear();
yCord.clear();
}
}
the first part loads the coordinates of the players pieces into 2 list's. The idea is that if all x or y values are equal there is a win, and if all x AND y values are different there is a win.
Re: TicTacToe Feedback (console game)
Posted: Sat Nov 29, 2008 10:48 am
by avansc
ismetteren wrote:I just made an console TicTacToe game too :D but i dont have any AI
Cant wait to see how you done it
.:Edit:.
Can't open the .exe file.
it gives me an error message(in danish, i've tried to translate it):
The program could not start, because the side by side-configuration is wrong. You will find more information in the eventlogfile.
the reason you cant open it is because you cant take exe compiled with VS to another machine. (its MS's way of making sure you dont make money off their products.)
Re: TicTacToe Feedback (console game)
Posted: Sat Nov 29, 2008 1:48 pm
by Vortex
ismetteren wrote:I just made an console TicTacToe game too :D but i dont have any AI
Cant wait to see how you done it
.:Edit:.
Can't open the .exe file.
it gives me an error message(in danish, i've tried to translate it):
The program could not start, because the side by side-configuration is wrong. You will find more information in the eventlogfile.
I've looked at the source. Mine seems to be more object oriented the yours(not saying that mine is better, i guess it is about perferrence). Ive found out to check for win this way(instead of checking every win posibility):
the first part loads the coordinates of the players pieces into 2 list's. The idea is that if all x or y values are equal there is a win, and if all x AND y values are different there is a win.
i havent got so far into c++ so i dont know how to make a good "objekt oriented" program yet, still dont really know what it is,
about my solution for checking win.
i didint really know how to do it in any other way but i will try to change it when i get time
also i hope you could read the rest of my code, its kinda messy.
Re: TicTacToe Feedback (console game)
Posted: Sat Nov 29, 2008 7:49 pm
by MarauderIIC
avansc wrote:the reason you cant open it is because you cant take exe compiled with VS to another machine. (its MS's way of making sure you dont make money off their products.)
You can too. It's just not as easy as possible. Anyway:
http://stackoverflow.com/questions/2540 ... ins-errors
I've had this problem. The solution has two steps:
1. Compile your program in "Release" mode instead of "Debug" mode (there's usually a combo-box in the toolbar)
2. Download from Microsoft their Redistributable Package of runtime components. Make sure to download the x86 edition for 32-bit computers and the x64 edition for 64-bit computers/OSes. Install this package on the target computer, and your application should run fine
P.S. This is a SxS thing
P.P.S. Alternatively, use a different compiler (like GCC, for example with Dev-Cpp) to compile your program's source, and your headaches will disappear.