Tic Tac Toe game

closed account (10oG1hU5)
I love gaming and its one of the reasons I got interested in coding and I am currently working on this tic tac toe game and I would love if you guys could help me out with a game I am working with and help me make these 5 improvements, thank you so much :)

1.Determine when a player has won with "3 in a row" ( horz., vert., or diagonal).
2.Determine who wins( has the most boxes) when all 9 boxes have been filled.
3.Do not allow a state to be repeated during the playing of a game.
4.Do not allow a box (1-9) to be selected more than once during the playing of a game.
5.Allow any case of letters typed by the player to match the answer.

#include <iostream>
#include <ctype.h>
#include <ctime>
#include <fstream>
#include <string>
#include <Windows.h>
using namespace std;

// function prototypes
void loadst(string[], string[]);
void play(string[], string[]);
void drawsq(void);
int pickst(void);

int main()
{
string states[50], caps[50];
char choice = 'y';

srand(time(NULL)); /* seed the random number sequence */
loadst(states, caps); /* get input data*/
system("cls");
while (tolower(choice) == 'y')
{
drawsq();
play(states, caps);

COORD coord = {1, 20};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
cout << "DO YOU WANT TO PLAY AGAIN? (Y/N) ";
cin >> choice;
}
}
/**************************** DRAW SQUARE FUNCTION */
void drawsq(void)
{
string board[9] = {
"1 |2 |3 ",
" | | ",
"---+---+---",
"4 |5 |6 ",
" | | ",
"---+---+---",
"7 |8 |9 ",
" | | "
};
int i, x, y;
system("cls");
y = 0;
x = 40;
for (i = 0; i < 9; i++)
{
y++;
COORD coord = {x, y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
cout << board[i];
}
}
/***************************** PICK RANDOM STATE */
int pickst()
{
return (rand() % 50);
}
/**************************** LOAD STATES FUNCTION */
void loadst(string states[], string caps[])
{
ifstream infile;
string temp;

infile.open("C:\\Users\\****\\Desktop\\usstates.dat");

for (int i = 0; i < 50; i++)
{
getline(infile, temp);
states[i] = temp.substr(0, 14);
caps[i] = temp.substr(39, 14);
}

infile.close();
}
/******************************** PLAY FUNCTION*/
void play(string states[], string caps[])
{
int gameover, iplayer, chosen, count, i, stpick;
int boxxy[2][9] = {41, 45, 49, 41, 45, 49, 41, 45, 49, 2, 2, 2, 5, 5, 5, 8, 8, 8};
string answer, blanks = " ";
char player[2] = {'X', 'O'};
COORD coord;
gameover = count = 0;
while (!gameover)
{
coord.X = 1;
coord.Y = 18;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
cout << blanks;

coord.X = 1;
coord.Y = 14;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
iplayer = count % 2;
cout << "PLAYER = " << player[iplayer];

coord.X = 1;
coord.Y = 16;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
cout << blanks;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
cout << "WHICH BOX DO YOU CHOOSE? ";
cin >> chosen;
cin.ignore();
stpick = pickst();

coord.X = 1;
coord.Y = 18;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
cout << "THE CAPITAL OF " << states[stpick] << " IS ? ";
getline(cin, answer);
for (i = answer.length(); i < 14; i++)
answer.append(" ");

//gotoxy(boxxy[0][chosen-1],boxxy[1][chosen-1]);
coord.X = boxxy[0][chosen - 1];
coord.Y = boxxy[1][chosen - 1];
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
if (answer == caps[stpick])
cout << player[iplayer];
else
cout << player[1 - iplayer];
count++;
if (count == 9)
gameover = 1;
}
}
The exact same thing you asked on stackoverflow. It's better to ask it here, even if there is less people. Stackoverflow is strict, when you asked three questions that got voted down, you get a question ban, until you give enough positive energy to the community. I got into a question ban, and I had to swich accounts. My name is Bob the zealot by the way. Nice to meet you!
Topic archived. No new replies allowed.