Tic-Tac-Toe Challenge Project (C++)

Wow, what an amazing full one week to develop this. I can say it is quite challenging project for beginner, and it helps me learn a lot. The code is 95% completion with just a little bit polishing to make the implementation to be more beautiful. However, it works really well. Now, time to proceed to the next lesson.

tictactoe jamil

Well, I’ll upload my TTT project to github later as I study github as a block (somehow I can’t share from my codecademy page, no button for sharing).

What I would like to say is that solution from codecademy has at least 2 bugs. After I finished my project I decided to check an example. It was clear except functions I haven’t met before - std::cin.clear() and std::cin.ignore(). well…

  1. …you call them in loop set_position() function. So if I try to set position as “wtf7”, loop will roll 4 times: ignore symbols for 3 times and print a message and then set position to 7. It doesn’t look nice but program still works.
    you can set parameters to std::cin.ignore() and make it ignore whole “wtf7” and ask for valid position.

  2. I keep debugging and there’s more. 1st loop in set_position() checks the position to be int. Okay. Let’s try 42. Loop ends and there’s the second one. It checks if chosen position is still free. If there’s already X or 0 it prints “something there in that position” anyway, It could be also out of 1-9. No good (we trying to use board[41], but only 9 chars there), but okay, it still works. It asks to input new position. And this time entering something instead int crushes the program.

Please find below the link to my tic-tac-tie repo. Feel free to suggest improvements !

Hardest project yet! Probs 85% finished, needs a lot of polishing.

Hi,

Following my exercise… any comments will be very valuable.

C++ Tic-Tac-Toe

Why does the link for learning to use GitHub not work? I have no clue how to navigate opening your solution.

Here is my program. Let me know if I’ve made any mistakes!

Hi everyone,
Feel free to take a look at the following link which is my version of tic-tac-toe. In my view, the key technique for building this project is the 2-D vector that is little tricky for the beginners of c++. The basic idea of this projet is that we are able to play the 3X3 tic-tac-toe game with the computer that draws ‘x’ or ‘o’ alternately with human.
For saving time, the computer only takes the second position and randomly draws either ‘x’ or ‘o’ depending on what human took at first. Have a fun!

https://github.com/oddmanru/tic-tac-toe

Here is my code which seems to do the trick. It is not pretty and I wanted to clean it up before posting but figured it might be more beneficial if left as originally coded. I’ll clean it up for my own practice outside of the Codecademy editor. This is my first project completed without referencing any other solutions first, just a few Google searches.

https://www.codecademy.com/workspaces/6337a4b9709898a43b929c9e

(im new and dont actually understand how these forums work yet so bare with me)
ive just started this and my code isnt working? there isnt an error message or anything, maybe is obvious but i dont understand why my code isnt working
sorry for how unspeciffic the question is i jsut dont know what im looking for either :((
https://www.codecademy.com/workspaces/633e481f263c76afb40b11d4

Tic-tac-toe game please review :slight_smile: it also has a very dumb computer (random number gen.)
did take some inspiration from the game board from the code academy solution.

Hi all,

Here’s my go at it. Hope it’s helpful for someone out there! Thank you.

Tic tac toe github link

I feel this - it took me awhile to finish the project, but it is done now! Good job to you as well!

Check out my Tic-Tac-Toe project on Github! Here is the link to the repository:

If it runs correctly, the application has a number of features:

  1. Asks for player names and uses these identifiers in many output statements throughout the application.
  2. Checks each answer for originality
  3. Checks if the answer is correct and will tell you when you have one
  4. Possibly my favorite feature is a function that outputs an updated grid with an “X” replacing the grid square number for p1 choices and an “O” for p2.

I appreciate any and all feedback! I mean hopefully don’t be too harsh, I am still definitely learning and know I have a long way to go.

Sorry - here is an updated link to the repository - I had to make some changes to the repository I was using.

Tic-Tac-Toe Challenge Project

I am having issues with my first project. I believe my “logic” is sound, but I am getting tons of errors relating to vectors being passed as the variable in my functions. Any suggestions:

ttt.cpp
#include
#include
#include"ttt_functions.hpp"

int main()
{
introductions();
char user1 = ‘X’;
char user2 = ‘O’;
int pos;
int t;

std::vector grid = {‘1’,‘2’,‘3’,‘4’,‘5’,‘6’,‘7’,‘8’,‘9’};
initial_grid(grid);

while (win(grid)!= true && t < 10)
{
std::cin >> pos;
if (grid[pos] != user1 && grid[pos] != user2)
{
grid[pos]=user1;
}
else
{
std::cout << “Improper Move”;
}
win(grid);
std::cout << “Now it is ‘O’ turn.\n”;
//std::cout << grid << “\n”;
std::cin >> pos;
if (grid[pos] != user1 && grid[pos] != user2)
{
grid[pos]=user2;
}
else
{
std::cout << “Improper Move”;
}
win(grid);
t++;
}
std::cout << “Game ended in a draw. Better luck next time.\n”;

}

ttt_functions.hpp

void introductions();
void initial_grid(vectorgrid);
bool win(vectorgrid);

ttt_functions.cpp
#include
#include
#include

void introductions(){
std::cout << “Welcome to Tic-Tac-Toe! You are the ‘X’, please select your first move:\n”;
}

void initial_grid(vectorgrid)
{
std::cout << grid[0] << " | " << grid[1] << " | " << grid [2] << “\n”;
std::cout << grid[3] << " | " << grid[4] << " | " << grid [5] << “\n”;
std::cout << grid[6] << " | " << grid[7] << " | " << grid [8] << “\n”;
}

bool win(vectorgrid)
{
if ((grid[0] == grid [1] && grid [0] == grid [2]) ||
(grid[3] == grid [4] && grid [4] == grid [5]) ||
(grid[6] == grid [7] && grid [7] == grid [8]) ||
(grid[0] == grid [3] && grid [3] == grid [6]) ||
(grid[1] == grid [4] && grid [4] == grid [7]) ||
(grid[2] == grid [5] && grid [5] == grid [9]) ||
(grid[0] == grid [4] && grid [4] == grid [8]) ||
(grid[6] == grid [4] && grid [4] == grid [2]))
{
std::cout << grid[0] << " Wins!\n";
return true;
}
else
{
return false;
}

}

Don’t know why it pasted funny,
this is the code i have establishing my vector (grid) in ttt.cpp.

std::vector grid = {‘1’,‘2’,‘3’,‘4’,‘5’,‘6’,‘7’,‘8’,‘9’};