Click here to Skip to main content
15,895,084 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralDraw Sound wave Pin
Dang Xuan Ky2-Oct-03 18:37
Dang Xuan Ky2-Oct-03 18:37 
Generalmoving character on screen Pin
sunju2-Oct-03 17:49
sunju2-Oct-03 17:49 
Generaltypedef explanation needed Pin
Steve Messer2-Oct-03 15:58
Steve Messer2-Oct-03 15:58 
GeneralRe: typedef explanation needed Pin
Michael Dunn2-Oct-03 17:43
sitebuilderMichael Dunn2-Oct-03 17:43 
GeneralRe: typedef explanation needed Pin
Steve Messer2-Oct-03 18:28
Steve Messer2-Oct-03 18:28 
GeneralRe: typedef explanation needed Pin
Michael Dunn2-Oct-03 18:47
sitebuilderMichael Dunn2-Oct-03 18:47 
GeneralRe: typedef explanation needed Pin
Steve Messer2-Oct-03 19:24
Steve Messer2-Oct-03 19:24 
GeneralHelp in a simple game Pin
Snyp2-Oct-03 15:52
Snyp2-Oct-03 15:52 
I'm using the old style of c++(console) and would like to know if there are some ingenius people out there and would like to find out how can a game of tic-tac-toe be artificially intelligent. How would I make the computer check anything. Please do help!Confused | :confused: little person.
#include <iostream>
using namespace std;

char array [3] [3]; //Tic Tac Toe array

char check();
void init_array();
void get_player_move();
void get_computer_move();
void disp_array();

int main()
{
char done = ' ';

init_array();

do{
disp_array();
get_player_move();
done = check(); //See if any winner
if(done != ' ') break; //Winner!!!
get_computer_move();
done = check(); //See if any winner again
system("cls");
} while(done == ' ');

disp_array(); //Display final array

if(done=='X')
cout << "You won!\n";

cout << "Programmed by:\n Tom Dziedzic \n";
if(done=='O')
cout << "I won!\n";

cout << "Programmed by:\n Tom Dziedzic \n";

return 0;
}

//Initialize the array
void init_array()
{
int i, j;

for(i=0; i<3; i++)
for(j=0; j<3; j++) array[i][j] = ' ';
}

//Get the player's move
void get_player_move()
{
int x, y;

cout << "Enter X,Y coordinates for your move: ";
cin >> x;
cin >> y;

x--; y--;

if(array[x][y]!= ' '){
cout << "Invalid move, try again.\n";
get_player_move();
}
else array[x][y] = 'X';
}

//Get a move from the computer
void get_computer_move()
{
if(array[1][1] == ' ')
{
array[1][1] = 'O';
goto e;
}
else if((array[0][0] == ' ' || array[0][0] == 'O') && (array[0][1] == ' ' || array[0][1] == 'O') && (array[0][2] == ' ' || array[0][2] == 'O'))
{
array[0][2] = 'O';
goto e;
}
e: ;
}

//Display the array
void disp_array()
{
int t;

for(t=0; t<3; t++) {
cout << array[t][0] << " | " << array[t][1] << " | " << array[t][2];
if(t != 2)
cout << "\n---|---|---\n";
}
cout << "\n";
}

//See if any winner
char check()
{
int i;

for(i=0; i<3; i++) /* check rows */
if(array[i][0]==array[i][1] && array[i][0]==array[i][2])
return array[i][0];

for(i=0; i<3; i++) /* check columns */
if(array[0][i]==array[1][i] && array[0][i]==array[2][i])
return array[0][i];

//Test diagonals for winner
if(array[0][0]==array[1][1] && array[1][1]==array[2][2])
return array[0][0];

if(array[0][2]==array[1][1] && array[1][1]==array[2][0])
return array[0][2];

return ' ';
}
GeneralRe: Help in a simple game Pin
Maxwell Chen2-Oct-03 16:31
Maxwell Chen2-Oct-03 16:31 
GeneralRe: Help in a simple game Pin
Snyp3-Oct-03 16:18
Snyp3-Oct-03 16:18 
GeneralRe: Help in a simple game Pin
spiritualfields2-Oct-03 18:20
spiritualfields2-Oct-03 18:20 
GeneralRe: Help in a simple game Pin
Snyp3-Oct-03 16:17
Snyp3-Oct-03 16:17 
GeneralTaskbar Text Pin
skallestad2-Oct-03 14:51
skallestad2-Oct-03 14:51 
GeneralRe: Taskbar Text Pin
Jagadeesh VN3-Oct-03 1:40
Jagadeesh VN3-Oct-03 1:40 
QuestionWhat version of Crystal Report have we got in VS.Net? Pin
Link26002-Oct-03 13:30
Link26002-Oct-03 13:30 
GeneralReally bizarre problem Pin
Joel Holdsworth2-Oct-03 12:55
Joel Holdsworth2-Oct-03 12:55 
GeneralRe: Really bizarre problem Pin
Tim Smith2-Oct-03 13:03
Tim Smith2-Oct-03 13:03 
GeneralRe: Really bizarre problem Pin
Joel Holdsworth2-Oct-03 13:07
Joel Holdsworth2-Oct-03 13:07 
GeneralCFont size Pin
@LX2-Oct-03 12:14
@LX2-Oct-03 12:14 
GeneralRe: CFont size Pin
alex.barylski2-Oct-03 17:14
alex.barylski2-Oct-03 17:14 
GeneralRe: CFont size Pin
@LX3-Oct-03 10:38
@LX3-Oct-03 10:38 
QuestionHow do I unload ActiveXObject in IE Pin
pbonner2-Oct-03 12:12
pbonner2-Oct-03 12:12 
AnswerRe: How do I unload ActiveXObject in IE Pin
igor19603-Oct-03 8:31
igor19603-Oct-03 8:31 
GeneralSpecify items to step over when using F11 in VC Pin
Grailman2-Oct-03 9:09
Grailman2-Oct-03 9:09 
GeneralRe: Specify items to step over when using F11 in VC Pin
vcplusplus2-Oct-03 10:44
vcplusplus2-Oct-03 10:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.