Click here to Skip to main content
15,922,574 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Modeless Dialogues Pin
KaЯl29-Oct-03 3:28
KaЯl29-Oct-03 3:28 
GeneralRe: Modeless Dialogues (box is not showing) Pin
Alton Williams29-Oct-03 21:06
Alton Williams29-Oct-03 21:06 
GeneralRe: Modeless Dialogues (box is not showing) Pin
KaЯl29-Oct-03 21:32
KaЯl29-Oct-03 21:32 
GeneralCMDIChildWnd Scrollbars Pin
alex.barylski28-Oct-03 21:06
alex.barylski28-Oct-03 21:06 
GeneralRe: CMDIChildWnd Scrollbars Pin
KaЯl29-Oct-03 3:17
KaЯl29-Oct-03 3:17 
GeneralPreventing a window from becoming maximized Pin
Vancouver28-Oct-03 19:16
Vancouver28-Oct-03 19:16 
GeneralRe: Preventing a window from becoming maximized Pin
Mumiozol28-Oct-03 22:30
Mumiozol28-Oct-03 22:30 
GeneralUnfortunately this does not work Pin
Vancouver29-Oct-03 13:41
Vancouver29-Oct-03 13:41 
GeneralRe: Unfortunately this does not work Pin
KaЯl29-Oct-03 21:38
KaЯl29-Oct-03 21:38 
GeneralRe: Preventing a window from becoming maximized Pin
Blake Miller30-Oct-03 9:12
Blake Miller30-Oct-03 9:12 
GeneralKaЯl and Blake Pin
Vancouver30-Oct-03 14:41
Vancouver30-Oct-03 14:41 
Generalint nTemp=0xe Pin
FlyingDancer28-Oct-03 19:10
FlyingDancer28-Oct-03 19:10 
GeneralRe: int nTemp=0xe Pin
Michael Dunn28-Oct-03 19:26
sitebuilderMichael Dunn28-Oct-03 19:26 
GeneralRe: int nTemp=0xe Pin
FlyingDancer28-Oct-03 20:00
FlyingDancer28-Oct-03 20:00 
Generalvi ctags to vc++ Pin
Anonymous28-Oct-03 18:17
Anonymous28-Oct-03 18:17 
GeneralRe: vi ctags to vc++ Pin
David Crow29-Oct-03 3:27
David Crow29-Oct-03 3:27 
GeneralDisplaying Text in Center of Client Area Pin
Hashim Saleem28-Oct-03 15:25
Hashim Saleem28-Oct-03 15:25 
GeneralRe: Displaying Text in Center of Client Area Pin
Hashim Saleem28-Oct-03 15:42
Hashim Saleem28-Oct-03 15:42 
GeneralPaint problem with child dialogs and tab control Pin
LukeV28-Oct-03 14:25
LukeV28-Oct-03 14:25 
GeneralRe: Paint problem with child dialogs and tab control Pin
LukeV28-Oct-03 14:53
LukeV28-Oct-03 14:53 
QuestionWhat can I do if ReleaseSemaphore return zero? Pin
EastDragon28-Oct-03 14:04
EastDragon28-Oct-03 14:04 
AnswerRe: What can I do if ReleaseSemaphore return zero? Pin
Alexander M.,28-Oct-03 23:36
Alexander M.,28-Oct-03 23:36 
GeneralHelp with AI, ASAP!!! Pin
Snyp28-Oct-03 12:31
Snyp28-Oct-03 12:31 
This is what I have to work with... I have a program of tic tac toe that is in the console, command prompt Wink | ;) , and the board is an array and have everything finished up to the point of getting the computer move. I am trying first to make the computer do random moves and then record to a seperate file, one for each win, lose, and draw and learn from which moves were good and which weren't as good. So far I have the below: (please help)
#include <iostream>
#include <fstream>
using namespace std;

char matrix [3][3]; //Tic Tac Toe Matrix

char check();
void init_matrix();
void get_player_move();
void get_computer_move();
void disp_matrix();
void f_matrix();

fstream SaveFile("wx.txt",ios::in | ios::out | ios::trunc);
fstream SaveFile2("wo.txt",ios::in | ios::out | ios::trunc);

int main()
{
char done = ' ';

init_matrix();

do
{
disp_matrix();
get_player_move();
done = check(); //See if any winner
f_matrix();
if(done != ' ')
{
break; //Winner!!!
}
get_computer_move();
done = check(); //See if any winner again
f_matrix();
} while(done == ' ');

disp_matrix(); //Display final matrix

if(done=='X')
{
SaveFile << "winner X\n;" << endl;
cout << "You won!\n";
}
else
{
SaveFile2 << "winner O\n;" << endl;
cout << "I won!!!!\n";
}

// f_matrix(); //Write to file final matrix / result
SaveFile.close();
SaveFile2.close();

return 0;
}

//Initialize the matrix
void init_matrix()
{
int i, j;

for(i=0; i<3; i++)
for(j=0; j<3; j++) matrix[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(matrix[x][y]!= ' ')
{
cout << "Invalid move, try again.\n";
get_player_move();
}
else
{
matrix[x][y] = 'X';
}
}

//Get a move from the computer
void get_computer_move()
{
int i, j;

do
{
i = rand() % 3;
j = rand() % 3;
}while(matrix[i][j] != ' ');


if(i*j==9)
{
cout << "draw\n";
system("pause");
}
else
{
matrix[i][j] = 'O';
}
}

//Display the matrix
void disp_matrix()
{
int t;

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

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

// New checking system
// check rows
for(i=0; i<3; i++)
if(matrix[i][0]==matrix[i][1] && matrix[i][0]==matrix[i][2])
{
return matrix[i][0];
}

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

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

if(matrix[0][2]==matrix[1][1] && matrix[1][1]==matrix[2][0])
{
return matrix[0][2];
}

/*
// Old checking system
// Check rows
if(matrix[0][0] == matrix[0][1] && matrix[0][0] == matrix[0][2])
{
return matrix[0][0];
}
if(matrix[1][0] == matrix[1][1] && matrix[1][0] == matrix[1][2])
{
return matrix[1][0];
}
if(matrix[2][0] == matrix[2][1] && matrix[2][0] == matrix[2][2])
{
return matrix[2][0];
}
// Check columns
if(matrix[0][0] == matrix[1][0] && matrix[0][0] == matrix[2][0])
{
return matrix[0][0];
}
if(matrix[0][1] == matrix[1][1] && matrix[0][1] == matrix[2][1])
{
return matrix[0][1];
}
if(matrix[0][2] == matrix[1][2] && matrix[0][2] == matrix[2][2])
{
return matrix[0][2];
}
// Check diagonal (left to right)
if(matrix[0][0]==matrix[1][1] && matrix[1][1]==matrix[2][2])
{
return matrix[0][0];
}
// Check diagonal (right to left)
if(matrix[0][2]==matrix[1][1] && matrix[1][1]==matrix[2][0])
{
return matrix[0][2];
}
*/

return ' ';
}

void f_matrix()
{
int t;

for(t=0; t<3; t++)
{
SaveFile << matrix[t][0] << matrix[t][1] << matrix[t][2] << "\n";
}
}

<marquee>Universal Project... Soon to be a .net</marquee>
GeneralRe: Help with AI, ASAP!!! Pin
Blake Coverett28-Oct-03 17:56
Blake Coverett28-Oct-03 17:56 
GeneralRe: Help with AI, ASAP!!! Pin
Michael P Butler29-Oct-03 1:46
Michael P Butler29-Oct-03 1:46 

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.