Tic Tac Toe

Help please...

Page 1 of 1

8 Replies - 1912 Views - Last Post: 01 December 2001 - 02:14 PM Rate Topic: -----

#1 ataraxysol  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 30-November 01

Tic Tac Toe

Posted 30 November 2001 - 08:00 PM

I'm writing a tic tac toe program (as I'm sure most of you already have done) and I'm having a great deal of difficulty figuring out how to make this thing work.  In fact, my code is nowhere near done because I'm downright lost.  Can anyone help?  Thanks in advance...
Is This A Good Question/Topic? 0
  • +

Replies To: Tic Tac Toe

#2 supersloth  Icon User is offline

  • serial frotteur - RUDEST MEMBER ON D.I.C.
  • member icon


Reputation: 4503
  • View blog
  • Posts: 28,411
  • Joined: 21-March 01

Re: Tic Tac Toe

Posted 30 November 2001 - 08:05 PM

well your right, most of us have done one, but, whats confusin you, algorithims, or just the code in general, you have a sample or something that we can look at and see whats wrong?
Was This Post Helpful? 0
  • +
  • -

#3 ataraxysol  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 30-November 01

Re: Tic Tac Toe

Posted 30 November 2001 - 08:44 PM

I'm not even sure where to begin.  I've written code for my array but I have no idea how to tell the computer how a player should win nor how to define an area of the board.  Any ideas?  Should I e-mail my code?
Was This Post Helpful? 0
  • +
  • -

#4 supersloth  Icon User is offline

  • serial frotteur - RUDEST MEMBER ON D.I.C.
  • member icon


Reputation: 4503
  • View blog
  • Posts: 28,411
  • Joined: 21-March 01

Re: Tic Tac Toe

Posted 30 November 2001 - 08:56 PM

no, you can post it on the board, more people can help that way, the way i did it was with a mutlidimensional array, first going across, then down in rows

ie:
[1][1]-[1][2]-[1][3]
-------------------
[2][1]-[2][2]-[2][3]
-------------------
[3][1]-[3][2]-[3][3]

thats sorta how i did it, others would just go down the list, 1,2,3,4,5,6,7,8,9.

Was This Post Helpful? 0
  • +
  • -

#5 Teckwiz  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 120
  • Joined: --

Re: Tic Tac Toe

Posted 30 November 2001 - 09:08 PM

here is my Tic - Tac - Toe program  (undefeated, by the way), you can work off of it if you like


/////////////////////////////////
//¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿
//ööööööööööööööööööööööööööööööö
//
//            Bryan Hughes
//         Sci Fair Project
//      Artifical Intellegence
//           Tic Tac Toe
//
//ööööööööööööööööööööööööööööööö
//¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿
/////////////////////////////////

#include<iostream.h> #include<stdlib.h> #include<time.h> #include<fstream.h> #include<time.h>

int check[9] = {0,0,0,0,0,0,0,0,0}; char pause[1]; char name[30]; char hiname[30]; char board[9] = {'1','2','3','4','5','6','7','8','9'}; int offence[50][9]; int defence[50][9]; int offcount; int defcount; int offdef; int think[9];

int gamecounter; int winlossa[3]; int winlossb[3];

int turn;

char game; int x; int r; int p1char; int p2char; int reset;

int p=0; int p1winsA;  //this is p1 vs computer int highscore1;

int counter; int randnum;

ifstream infile; ofstream outfile;

void printboard(); void startgame(); void wincheck(); void exboard(); void title(); void player1(); void player2(); void comp1(); void comp2(); void game1(); void game2(); void game3(); void p1winB(); void p2win(); void p1winA(); void compwin(); void enterdata(); void gameresults(); void endgame1(); void endgame2(); void calchighscore(); void highscore(); void random();

main() { title(); return 0; }

void title() { cout << endl; cout << "************  **  ******** ";   cout << "     **       **  **       ";         cout << "     **       **  **       ";         cout << "     **       **  **       ";     cout << "     **       **  **       ";     cout << "     **       **  **       ";     cout << "     **       **  ******** "; cout << endl; cout << "       ************  ********  ******** ";   cout << "            **       **    **  **       ";         cout << "            **       ********  **       ";         cout << "            **       **    **  **       ";     cout << "            **       **    **  **       ";     cout << "            **       **    **  **       ";     cout << "            **       **    **  ******** "; cout << "               ************  *********  ******** ";   cout << "                    **       **     **  **       ";         cout << "                    **       **     **  **       ";         cout << "                    **       **     **  ****     ";     cout << "                    **       **     **  **       ";     cout << "                    **       **     **  **       ";     cout << "                    **       *********  ******** ";

cout <<"Press enter to continue...... "; cin.get(pause, 1); cin.ignore(80, ' '); system("cls"); enterdata(); }

void enterdata() { system("cls"); cout << "Welcome to Super Ultra Mega Tic Tac Toe!!!!! ";

cout << "Please enter your name player... "; cin.get(name,30); cin.ignore(80,' '); cout << " Welcome "<<name<< ", I am the UGM 9000, the ultimate Tic Tac Toe Champion... "; cout << "I look forward to seeing you in the battle Arena... ";

startgame(); }

void startgame() { int gamecounterb; gamecounter++;

do { x=0; r=49; for(x=0; x<=10; x++) {check[x]=0;} for(x=0; x<=10; x++) {board[x]=r; r++;}

system("cls"); cout << "Welcome to Super Ultra Mega Tic Tac Toe!!!!! ";

cout << " "; if(gamecounter<25) {cout<< "The AI has not finished, building yet, Please play Game 1 ";} else{if(gamecounter==25) {cout<< "The AI is ready to play, please choose Game 2 "; gamecounterb++;}} if(gamecounterb==50) {cout << "That is enough, please exit the game ";} cout << "[1] 1P VS Computer (HARD CODED AI) "; cout << "[2] 1P VS Computer (LEARNING AI) "; cout << "[3] Exit Game ";

cout << "Which option would you like? "; cin >> game; cin.ignore(80, ' '); cout << " ";

switch(game) { case '1': system("cls"); game1(); break;

case '2': system("cls"); game2(); break;

case '3': system("cls"); cout << "Thanks for playing;-) "; exit(0); break;

default: cout << "Error!!!!  Please enter the number code that cooresponds with the gaming option you want... "; break; } }while((game!='1')&&(game!='2')&&(game!='3'));

}

void printboard() { cout << "     |      |     "; cout << "  " << board[0]  <<"  | "<< "  " << board[1] << "  |  " << board[2] <<endl; cout << "     |      |     "; cout << "------------------ "; cout << "     |      |     "; cout << "  " << board[3]  <<"  | "<< "  " << board[4] << "  |  " << board[5] <<endl; cout << "     |      |     "; cout << "------------------ "; cout << "     |      |     "; cout << "  " << board[6]  <<"  | "<< "  " << board[7] << "  |  " << board[8] <<endl; cout << "     |      |     "; }

void wincheck() {

if((check[0]==1) && (check[1]==1) && (check[2]==1)) {endgame1();} else{ if((check[3]==1) && (check[4]==1) && (check[5]==1)) {endgame1();} else{ if((check[6]==1) && (check[7]==1) && (check[8]==1)) {endgame1();} else{ if((check[0]==1) && (check[3]==1) && (check[6]==1)) {endgame1();} else{ if((check[1]==1) && (check[4]==1) && (check[7]==1)) {endgame1();} else{ if((check[2]==1) && (check[5]==1) && (check[8]==1)) {endgame1();} else{ if((check[0]==1) && (check[4]==1) && (check[8]==1)) {endgame1();} else{ if((check[2]==1) && (check[4]==1) && (check[6]==1)) {endgame1();} else{

if((check[0]==2) && (check[1]==2) && (check[2]==2)) {endgame2();} else{ if((check[3]==2) && (check[4]==2) && (check[5]==2)) {endgame2();} else{ if((check[6]==2) && (check[7]==2) && (check[8]==2)) {endgame2();} else{ if((check[0]==2) && (check[3]==2) && (check[6]==2)) {endgame2();} else{ if((check[1]==2) && (check[4]==2) && (check[7]==2)) {endgame2();} else{ if((check[2]==2) && (check[5]==2) && (check[8]==2)) {endgame2();} else{ if((check[0]==2) && (check[4]==2) && (check[8]==2)) {endgame2();} else{ if((check[2]==2) && (check[4]==2) && (check[6]==2)) {endgame2();} else{ if((check[0]>=1)&&(check[1]>=1)&&(check[2]>=1)&&(check[3]>=1)&&(check[4]>=1)&&(check[5]>=1)&&(check[6]>=1)&&(check[7]>=1)&&(check[8]>=1)) {system("cls"); cout << "Tie Game, Nobody wins! "; if(game=='1') winlossa[2]++; if(game=='2') winlossb[2]++; cout <<"Press enter to continue...... "; cin.get(pause, 1); cin.ignore(80, ' '); system("cls"); startgame();}}}}}}}}}}}}}}}}}

}

void endgame1() { if(game=='1') winlossa[0]++; if(game=='2') winlossb[0]++;

system("cls"); printboard(); cout <<name<<" is the winner!!!!!!! "; cout << "Press enter to return to the main menu..."; cin.get(pause, 1); cin.ignore(80,' '); system("cls"); startgame(); }

void endgame2() { if(game=='1') winlossa[1]++; if(game=='2') winlossb[1]++;

system("cls"); printboard(); cout << "Looks like I win "; cout << "Press enter to return to the main menu..."; cin.get(pause, 1); cin.ignore(80,' '); cout<<endl; startgame(); }

void game1() {

cout << "Hello " << name << endl;

cout << "The rules of this game are simple.... "; cout << "Each player takes turns putting thier icons in the squares "; cout << "First player to make 3 in a row wins! "; cout << "You will be *The O's* "; cout << "I  will be  *The X's* ";

cout << name <<" press enter to begin!!!!! "; cin.get(pause, 1); cin.ignore(80,' '); system("cls");

p1char=1;

srand(time(0)); counter=rand()%(8); turn=0;

if(counter%2==0) {cout << "You can go first "; offcount++; offdef=0;} else{ cout << "I will go first "; offdef=1; defcount++;}

do{ if(counter%2==0) {player1();} else{ comp2(); turn++;} }while(1!=0);

}

void game2() {

cout << "Hello, "<<name<< endl; cout << endl; cout << "The rules of this game are simple.... "; cout << "Each player takes turns putting thier icons in the squares "; cout << "First player to make 3 in a row wins! "; cout << "You will be *The O's* "; cout << "I  will be  *The X's* ";

cout << name <<" press enter to begin!!!!! "; cin.get(pause, 1); cin.ignore(80,' '); system("cls"); p1char=1; turn = 0; srand(time(0)); counter=rand()%(8);

if(counter%2==0) {cout << "You can go first "; offcount++; offdef=0;} else{ cout << "I will go first "; defcount++; offdef=1;}

do{ if(counter%2==0) {player1();} else{ comp2(); turn++;} }while(1!=0); }

void player1() {

printboard(); cout << name<<" it is your turn.... "; do {

cout << "Enter the number square in which you would like to place ...  "; cin >> x; cin.ignore(80, ' ');

if((check[x-1] ==0)||(x-1 >=8) || (x-1 <=0-1)) { board[x-1] = p1char; check[x-1] = 1; if(offdef==0) {offence[offcount-1][turn]=x-1;} else {defence[defcount-1][turn]=x-1;} wincheck(); break; break; } else {system("cls"); cout << "Wait a second that square is already occupied, or is out of range!!! Please chose another... "; } printboard();

}while((check[x-1]==1)||(check[x-1]==2)); system("cls"); counter=1; }

void random() { srand(time(0)); randnum=rand()%(8); }

void comp1() { do{

//******************* //start thinking here //******************* random(); do{ if(check[randnum]==1) {srand(time(0)); randnum=rand()%(8);} }while(check[randnum]==1);

//*************** //winning pattern //***************

if(((check[1]==2)&&(check[2]==2)&&(check[0]==0))||((check[3]==2)&&(check[4]==2)&&(check[0]==0))||((check[4]==2)&&(check[8]==2)&&(check[0]==0))) {x=0;}else{ // 1 slot if(((check[0]==2)&&(check[2]==2)&&(check[1]==0))||((check[4]==2)&&(check[7]==2)&&(check[1]==0))) {x=1;}else{ // 2 slot if(((check[1]==2)&&(check[0]==2)&&(check[2]==0))||((check[5]==2)&&(check[8]==2)&&(check[2]==0))||((check[4]==2)&&(check[6]==2)&&(check[2]==0))) {x=2;}else{ // 3 slot if(((check[0]==2)&&(check[6]==2)&&(check[3]==0))||((check[4]==2)&&(check[5]==2)&&(check[0]==0))) {x=3;}else{ // 4 slot if(((check[1]==2)&&(check[7]==2)&&(check[4]==0))||((check[3]==2)&&(check[5]==2)&&(check[4]==0))||((check[0]==2)&&(check[8]==2)&&(check[4]==0))||((check[2]==2)&&(check[6]==2)&&(check[4]==0))) {x=4;}else{ // 5 slot if(((check[2]==2)&&(check[8]==2)&&(check[5]==0))||((check[3]==2)&&(check[4]==2)&&(check[5]==0))) {x=5;}else{ // 6 slot if(((check[0]==2)&&(check[3]==2)&&(check[6]==0))||((check[7]==2)&&(check[8]==2)&&(check[6]==0))||((check[4]==2)&&(check[2]==2)&&(check[6]==0))) {x=6;}else{ // 7 slot if(((check[1]==2)&&(check[4]==2)&&(check[7]==0))||((check[6]==2)&&(check[8]==2)&&(check[7]==0))) {x=7;}else{ // 8 slot if(((check[2]==2)&&(check[5]==2)&&(check[8]==0))||((check[6]==2)&&(check[7]==2)&&(check[8]==0))||((check[0]==2)&&(check[4]==2)&&(check[8]==0))) {x=8;}else{

//**************** //blocking pattern //**************** // 0 slot if(((check[1]==1)&&(check[2]==1)&&(check[0]==0))||((check[3]==1)&&(check[4]==1)&&(check[0]==0))||((check[4]==1)&&(check[8]==1)&&(check[0]==0))) {x=0;}else{ // 1 slot if(((check[0]==1)&&(check[2]==1)&&(check[1]==0))||((check[4]==1)&&(check[7]==1)&&(check[1]==0))) {x=1;}else{ // 2 slot if(((check[1]==1)&&(check[0]==1)&&(check[2]==0))||((check[5]==1)&&(check[8]==1)&&(check[2]==0))||((check[4]==1)&&(check[6]==1)&&(check[2]==0))) {x=2;}else{ // 3 slot if(((check[0]==1)&&(check[6]==1)&&(check[3]==0))||((check[4]==1)&&(check[5]==1)&&(check[0]==0))||((check[4]==1)&&(check[5]==1)&&(check[3]==0))) {x=3;}else{ // 4 slot if(((check[1]==1)&&(check[7]==1)&&(check[4]==0))||((check[3]==1)&&(check[5]==1)&&(check[4]==0))||((check[0]==1)&&(check[8]==1)&&(check[4]==0))||((check[2]==1)&&(check[6]==1)&&(check[4]==0))) {x=4;}else{ // 5 slot if(((check[2]==1)&&(check[8]==1)&&(check[5]==0))||((check[3]==1)&&(check[4]==1)&&(check[5]==0))||((check[3]==1)&&(check[4]==1)&&(check[5]==0))) {x=5;}else{ // 6 slot if(((check[0]==1)&&(check[3]==1)&&(check[6]==0))||((check[7]==1)&&(check[8]==1)&&(check[6]==0))||((check[4]==1)&&(check[2]==1)&&(check[6]==0))) {x=6;}else{ // 7 slot if(((check[1]==1)&&(check[4]==1)&&(check[7]==0))||((check[6]==1)&&(check[8]==1)&&(check[7]==0))) {x=7;}else{ // 8 slot if(((check[2]==1)&&(check[5]==1)&&(check[8]==0))||((check[6]==1)&&(check[7]==1)&&(check[8]==0))||((check[0]==1)&&(check[4]==1)&&(check[8]==0))) {x=8;}

else{

//************ //base pattern  0-8 //************

//attack pattern 0

if(randnum==0) {if(check[0]==0) {x=0;}else{ if(check[4]==0) {x=4;}else{ if(check[8]==0) {x=8;}else{ if(check[3]==0) {x=3;}else{ if(check[6]==0) {x=6;}else{ if(check[1]==0) {x=1;}else{ if(check[2]==0) {x=2;}else{ if(check[5]==0) {x=5;}else{ if(check[7]==0) {x=7;}} }}}}}}}}

else{

//attack pattern 1

if(randnum==1) {if(check[1]==0) {x=1;}else{ if(check[3]==0) {x=3;}else{ if(check[0]==0) {x=0;}else{ if(check[2]==0) {x=2;}else{ if(check[6]==0) {x=6;}else{ if(check[4]==0) {x=4;}else{ if(check[8]==0) {x=8;}else{ if(check[5]==0) {x=5;}else{ if(check[7]==0) {x=7;}} }}}}}}}}

else{

//attack pattern 2

if(randnum==2) {if(check[2]==0) {x=2;}else{ if(check[4]==0) {x=4;}else{ if(check[6]==0) {x=6;}else{ if(check[1]==0) {x=1;}else{ if(check[0]==0) {x=0;}else{ if(check[5]==0) {x=5;}else{ if(check[8]==0) {x=8;}else{ if(check[3]==0) {x=3;}else{ if(check[7]==0) {x=7;}} }}}}}}}} else{

//attack pattern 3

if(randnum==3) {if(check[3]==0) {x=3;}else{ if(check[7]==0) {x=7;}else{ if(check[6]==0) {x=6;}else{ if(check[0]==0) {x=0;}else{ if(check[8]==0) {x=8;}else{ if(check[4]==0) {x=4;}else{ if(check[2]==0) {x=2;}else{ if(check[1]==0) {x=1;}else{ if(check[5]==0) {x=5;}} }}}}}}}} else{

//attack pattern 4

if(randnum==4) {if(check[4]==0) {x=4;}else{ if(check[8]==0) {x=8;}else{ if(check[0]==0) {x=0;}else{ if(check[3]==0) {x=3;}else{ if(check[5]==0) {x=5;}else{ if(check[1]==0) {x=1;}else{ if(check[2]==0) {x=2;}else{ if(check[6]==0) {x=6;}else{ if(check[7]==0) {x=7;}} }}}}}}}} else{

//attack pattern 5

if(randnum==5) {if(check[5]==0) {x=5;}else{ if(check[7]==0) {x=7;}else{ if(check[2]==0) {x=2;}else{ if(check[8]==0) {x=8;}else{ if(check[0]==0) {x=0;}else{ if(check[1]==0) {x=1;}else{ if(check[4]==0) {x=4;}else{ if(check[6]==0) {x=6;}else{ if(check[3]==0) {x=3;}} }}}}}}}} else{

//attack pattern 6

if(randnum==6) {if(check[6]==0) {x=6;}else{ if(check[5]==0) {x=5;}else{ if(check[4]==0) {x=4;}else{ if(check[2]==0) {x=2;}else{ if(check[8]==0) {x=8;}else{ if(check[0]==0) {x=0;}else{ if(check[3]==0) {x=3;}else{ if(check[1]==0) {x=1;}else{ if(check[7]==0) {x=7;}} }}}}}}}} else{

//attack pattern 7

if(randnum==7) {if(check[7]==0) {x=7;}else{ if(check[0]==0) {x=0;}else{ if(check[6]==0) {x=6;}else{ if(check[3]==0) {x=3;}else{ if(check[8]==0) {x=8;}else{ if(check[4]==0) {x=4;}else{ if(check[2]==0) {x=2;}else{ if(check[1]==0) {x=1;}else{ if(check[5]==0) {x=5;}} }}}}}}}} else{

//attack pattern 8

if(randnum==8) {if(check[8]==0) {x=8;}else{ if(check[2]==0) {x=2;}else{ if(check[0]==0) {x=0;}else{ if(check[6]==0) {x=6;}else{ if(check[4]==0) {x=4;}else{ if(check[1]==0) {x=1;}else{ if(check[5]==0) {x=5;}else{ if(check[3]==0) {x=3;}else{ if(check[7]==0) {x=7;}} }}}}}}}}

}}}}}}}}}}}}}}}}}}}}}}}}}}

//************* // end thinking //*************

if((check[x]==0)||(x>=8) || (x<=0-1)) { board[x] = 88; check[x] = 2;

wincheck(); printboard(); cout <<"Press enter to continue "; cin.get(pause,1); cin.ignore(80, ' '); break; break; } else {cout << "Wait a second that square is already occupied, or is out of range!!! Please chose another... "; cout <<"Press enter to continue "; cin.get(pause,1); cin.ignore(80, ' '); }

}while((check[x-1]==1)||(check[x-1]==2)); system("cls"); randnum=2; }

void comp2() {

random(); do{

cout << "Enter the number square in which you would like to place ...   ";

//******************* //start thinking here //*******************

//*************** //winning pattern //***************

if(((check[1]==2)&&(check[2]==2)&&(check[0]==0))||((check[3]==2)&&(check[4]==2)&&(check[0]==0))||((check[4]==2)&&(check[8]==2)&&(check[0]==0))) {x=0;}else{ // 1 slot if(((check[0]==2)&&(check[2]==2)&&(check[1]==0))||((check[4]==2)&&(check[7]==2)&&(check[1]==0))) {x=1;}else{ // 2 slot if(((check[1]==2)&&(check[0]==2)&&(check[2]==0))||((check[5]==2)&&(check[8]==2)&&(check[2]==0))||((check[4]==2)&&(check[6]==2)&&(check[2]==0))) {x=2;}else{ // 3 slot if(((check[0]==2)&&(check[6]==2)&&(check[3]==0))||((check[4]==2)&&(check[5]==2)&&(check[0]==0))) {x=3;}else{ // 4 slot if(((check[1]==2)&&(check[7]==2)&&(check[4]==0))||((check[3]==2)&&(check[5]==2)&&(check[4]==0))||((check[0]==2)&&(check[8]==2)&&(check[4]==0))||((check[2]==2)&&(check[6]==2)&&(check[4]==0))) {x=4;}else{ // 5 slot if(((check[2]==2)&&(check[8]==2)&&(check[5]==0))||((check[3]==2)&&(check[4]==2)&&(check[5]==0))) {x=5;}else{ // 6 slot if(((check[0]==2)&&(check[3]==2)&&(check[6]==0))||((check[7]==2)&&(check[8]==2)&&(check[6]==0))||((check[4]==2)&&(check[2]==2)&&(check[6]==0))) {x=6;}else{ // 7 slot if(((check[1]==2)&&(check[4]==2)&&(check[7]==0))||((check[6]==2)&&(check[8]==2)&&(check[7]==0))) {x=7;}else{ // 8 slot if(((check[2]==2)&&(check[5]==2)&&(check[8]==0))||((check[6]==2)&&(check[7]==2)&&(check[8]==0))||((check[0]==2)&&(check[4]==2)&&(check[8]==0))) {x=8;}else{

//**************** //blocking pattern //**************** // 0 slot if(((check[1]==1)&&(check[2]==1)&&(check[0]==0))||((check[3]==1)&&(check[4]==1)&&(check[0]==0))||((check[4]==1)&&(check[8]==1)&&(check[0]==0))) {x=0;}else{ // 1 slot if(((check[0]==1)&&(check[2]==1)&&(check[1]==0))||((check[4]==1)&&(check[7]==1)&&(check[1]==0))) {x=1;}else{ // 2 slot if(((check[1]==1)&&(check[0]==1)&&(check[2]==0))||((check[5]==1)&&(check[8]==1)&&(check[2]==0))||((check[4]==1)&&(check[6]==1)&&(check[2]==0))) {x=2;}else{ // 3 slot if(((check[0]==1)&&(check[6]==1)&&(check[3]==0))||((check[4]==1)&&(check[5]==1)&&(check[0]==0))||((check[4]==1)&&(check[5]==1)&&(check[3]==0))) {x=3;}else{ // 4 slot if(((check[1]==1)&&(check[7]==1)&&(check[4]==0))||((check[3]==1)&&(check[5]==1)&&(check[4]==0))||((check[0]==1)&&(check[8]==1)&&(check[4]==0))||((check[2]==1)&&(check[6]==1)&&(check[4]==0))) {x=4;}else{ // 5 slot if(((check[2]==1)&&(check[8]==1)&&(check[5]==0))||((check[3]==1)&&(check[4]==1)&&(check[5]==0))||((check[3]==1)&&(check[4]==1)&&(check[5]==0))) {x=5;}else{ // 6 slot if(((check[0]==1)&&(check[3]==1)&&(check[6]==0))||((check[7]==1)&&(check[8]==1)&&(check[6]==0))||((check[4]==1)&&(check[2]==1)&&(check[6]==0))) {x=6;}else{ // 7 slot if(((check[1]==1)&&(check[4]==1)&&(check[7]==0))||((check[6]==1)&&(check[8]==1)&&(check[7]==0))) {x=7;}else{ // 8 slot if(((check[2]==1)&&(check[5]==1)&&(check[8]==0))||((check[6]==1)&&(check[7]==1)&&(check[8]==0))||((check[0]==1)&&(check[4]==1)&&(check[8]==0))) {x=8;}

else{ //******************* //base pattern  0-8 //*******************

srand(time(0)); randnum=rand()%(8); x=randnum;

}}}}}}}}}}}}}}}}}}

//************* // end thinking //*************

if((check[x]==0)||(x>=8) || (x<=0-1)) { board[x] = 88; check[x] = 2;

if(offdef==0) {offence[offcount-1][turn]=x-1;} else {defence[defcount-1][turn]=x-1;}

wincheck(); printboard(); cout <<"Press enter to continue "; cin.get(pause,1); cin.ignore(80, ' '); break; break; } else{} }while((check[x-1]==1)||(check[x-1]==2)); system("cls"); counter=2; }

/* void highscore() { system("cls"); infile.open("highscore.dat", ios::in); infile >> highscore1; infile.ignore(80, ' '); infile.close(); infile.open("name.dat", ios::in); infile.get(hiname, 30); infile.ignore(80, ' '); infile.close();

cout <<"*************************************************************************** "; cout <<"*************************************************************************** "; cout <<"Highscore held by: "<<hiname<< ", with "<<highscore1<< " consecutive wins! "; cout <<"*************************************************************************** "; cout <<"*************************************************************************** ";

cout << "Press enter to return to the main menu..."; cin.get(pause, 1); cin.ignore(80, ' '); startgame(); }

*/


Was This Post Helpful? 1

#6 ataraxysol  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 30-November 01

Re: Tic Tac Toe

Posted 30 November 2001 - 10:02 PM

You guys are the coolest.  I have about another week to finish this up so you just may here from me again.  Thanks for all your help.

P.S.  Nova Dragoon - obviously my program will look nothing like your masterpiece when I'm done.  I will use it as a reference, however.  It's always easier to see how someone did it correctly.  Thanks so much.

Was This Post Helpful? 0
  • +
  • -

#7 malkiri  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 3
  • View blog
  • Posts: 364
  • Joined: 29-March 01

Re: Tic Tac Toe

Posted 01 December 2001 - 10:57 AM

Is that a challenge, Nova Dragoon? :)
Was This Post Helpful? 0
  • +
  • -

#8 supersloth  Icon User is offline

  • serial frotteur - RUDEST MEMBER ON D.I.C.
  • member icon


Reputation: 4503
  • View blog
  • Posts: 28,411
  • Joined: 21-March 01

Re: Tic Tac Toe

Posted 01 December 2001 - 11:03 AM

my program wasnt half bad, but novas kicks ass, he had two levels of difficulty for the tic tac toe for skool, second difficulty was undefeated, and for science fair it would learn and use your moves against you, which was kool.

i do think we should get a challenge up sometime though, just you know, lets try for after finals, ;)

Was This Post Helpful? 0
  • +
  • -

#9 runtime error  Icon User is offline

  • Lucky.Code
  • member icon

Reputation: 3
  • View blog
  • Posts: 629
  • Joined: 19-March 01

Re: Tic Tac Toe

Posted 01 December 2001 - 02:14 PM

Psssssst nova have you ever heard of a switch statement.:)
way too many if else statements.

Your AI was Much better than mine though i give you that.

Oh and by the way don't ever post all of your code like that again. It makes us look bad. I won't change it because it is way too late for that now. But pleeeease don't do that.

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1