Click here to Skip to main content
16,006,845 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: SetWindowPlacement Doesn't display the Dialogbox properly Pin
Jagadeesh VN17-Sep-03 21:53
Jagadeesh VN17-Sep-03 21:53 
QuestionChar[1] to UINT ??? Pin
wow999917-Sep-03 16:03
wow999917-Sep-03 16:03 
AnswerRe: Char[1] to UINT ??? Pin
Terry O'Nolley17-Sep-03 17:11
Terry O'Nolley17-Sep-03 17:11 
GeneralRe: Char[1] to UINT ??? Pin
wow999917-Sep-03 19:09
wow999917-Sep-03 19:09 
GeneralRe: Char[1] to UINT ??? Pin
jhwurmbach17-Sep-03 22:57
jhwurmbach17-Sep-03 22:57 
GeneralRe: Char[1] to UINT ??? Pin
Terry O'Nolley18-Sep-03 12:27
Terry O'Nolley18-Sep-03 12:27 
QuestionBitmap from data??? Pin
IceBerG7117-Sep-03 16:01
IceBerG7117-Sep-03 16:01 
GeneralNeed help with Tic-Tac-Toe Pin
Snyp17-Sep-03 14:34
Snyp17-Sep-03 14:34 
#include <iostream><br />
using namespace std;<br />
<br />
char matrix [3] [3];	//Tic Tac Toe Matrix<br />
<br />
char check();<br />
void init_matrix();<br />
void get_player_move();<br />
void get_computer_move();<br />
void disp_matrix();<br />
<br />
int main()<br />
{<br />
	char done = ' ';<br />
<br />
	init_matrix();<br />
<br />
	do{<br />
		disp_matrix();<br />
		get_player_move();<br />
		done = check();			//See if any winner<br />
		if(done != ' ') break;	//Winner!!!<br />
		get_computer_move();<br />
		done = check();			//See if any winner again<br />
		system("cls");<br />
	} while(done == ' ');<br />
<br />
	disp_matrix();				//Display final matrix<br />
<br />
	if(done=='X') <br />
		cout << "You won!\n";<br />
	if(done=='O')<br />
		cout << "I won!\n";<br />
<br />
	cout << "Programmed by:\n Tom Dziedzic \n";<br />
<br />
	return 0;<br />
}<br />
<br />
//Initialize the matrix<br />
void init_matrix()<br />
{<br />
	int i, j;<br />
<br />
	for(i=0; i<3; i++)<br />
		for(j=0; j<3; j++) matrix[i][j] =  ' ';<br />
}<br />
<br />
//Get the player's move<br />
void get_player_move()<br />
{<br />
	int x, y;<br />
<br />
	cout << "Enter X,Y coordinates for your move: ";<br />
	cin >> x;<br />
	cin >> y;<br />
<br />
	x--; y--;<br />
<br />
	if(matrix[x][y]!= ' '){<br />
		cout << "Invalid move, try again.\n";<br />
		get_player_move();<br />
	}<br />
  else matrix[x][y] = 'X';<br />
}<br />
<br />
//Get a move from the computer<br />
void get_computer_move()<br />
{<br />
	if(matrix[1][1] == ' ')<br />
	{<br />
		matrix[1][1] = 'O';<br />
		goto e;<br />
	}<br />
	if(matrix[0][0] == ' ' && matrix[1][1] == ' ' && matrix[2][2] == ' ')<br />
	{<br />
		matrix[2][2] = 'O';<br />
		goto e;<br />
	}<br />
e:  ;<br />
}<br />
<br />
//Display the matrix<br />
void disp_matrix()<br />
{<br />
	int t;<br />
<br />
	for(t=0; t<3; t++) {<br />
		cout << matrix[t][0] << "  | " << matrix[t][1] << " | " << matrix[t][2];<br />
		if(t != 2) <br />
			cout << "\n---|---|---\n";<br />
	}<br />
	cout << "\n";<br />
}<br />
<br />
//See if any winner<br />
char check()<br />
{<br />
	int i;<br />
<br />
	for(i=0; i<3; i++)  /* check rows */<br />
		if(matrix[i][0]==matrix[i][1] && matrix[i][0]==matrix[i][2]) <br />
			return matrix[i][0];<br />
<br />
	for(i=0; i<3; i++)  /* check columns */<br />
		if(matrix[0][i]==matrix[1][i] && matrix[0][i]==matrix[2][i]) <br />
			return matrix[0][i];<br />
<br />
	//Test diagonals for winner<br />
	if(matrix[0][0]==matrix[1][1] && matrix[1][1]==matrix[2][2])<br />
		return matrix[0][0];<br />
<br />
	if(matrix[0][2]==matrix[1][1] && matrix[1][1]==matrix[2][0])<br />
		return matrix[0][2];<br />
<br />
  return ' ';<br />
}

this is what i have so far... though I'm trying to make the computer first search if the user will win in the next move and then block it if it can, and then if it doesn't then find a row it can fill. Please I need help, comments, suggestion, articles, please anything at all which would make the computer react like a human would... Confused | :confused: Confused | :confused: Confused | :confused: Confused | :confused:
P.S. TAKE YOUR TIME, don't rush

<marquee>Universal Project... Soon to be a .net
GeneralRe: Need help with Tic-Tac-Toe Pin
Terry O'Nolley17-Sep-03 16:43
Terry O'Nolley17-Sep-03 16:43 
GeneralRe: Need help with Tic-Tac-Toe Pin
Snyp17-Sep-03 16:46
Snyp17-Sep-03 16:46 
GeneralDLLs and XP themes... Pin
LukeV17-Sep-03 14:25
LukeV17-Sep-03 14:25 
GeneralRe: DLLs and XP themes... Pin
Alexander M.,18-Sep-03 6:25
Alexander M.,18-Sep-03 6:25 
GeneralJPG width and height Pin
alex.barylski17-Sep-03 14:19
alex.barylski17-Sep-03 14:19 
GeneralRe: JPG width and height Pin
JWood18-Sep-03 12:20
JWood18-Sep-03 12:20 
GeneralRe: JPG width and height Pin
alex.barylski18-Sep-03 15:38
alex.barylski18-Sep-03 15:38 
GeneralProblems moving to .NET studio Pin
Tom Wright17-Sep-03 12:24
Tom Wright17-Sep-03 12:24 
GeneralRe: Problems moving to .NET studio Pin
valikac17-Sep-03 12:42
valikac17-Sep-03 12:42 
GeneralRe: Problems moving to .NET studio Pin
Tom Wright17-Sep-03 17:06
Tom Wright17-Sep-03 17:06 
GeneralRe: Problems moving to .NET studio Pin
Steve S18-Sep-03 1:47
Steve S18-Sep-03 1:47 
GeneralRe: Problems moving to .NET studio Pin
Alexander M.,18-Sep-03 6:21
Alexander M.,18-Sep-03 6:21 
GeneralAnother question in tabCtrl Pin
Ruben93817-Sep-03 12:01
Ruben93817-Sep-03 12:01 
GeneralCreating a DialogBox in NT Service Pin
john.angel17-Sep-03 11:26
john.angel17-Sep-03 11:26 
GeneralRe: Creating a DialogBox in NT Service Pin
Peter Weyzen17-Sep-03 12:07
Peter Weyzen17-Sep-03 12:07 
GeneralRe: Creating a DialogBox in NT Service Pin
john.angel18-Sep-03 6:38
john.angel18-Sep-03 6:38 
QuestionHow to set up a scroll bar inside a tabctrl Pin
Ruben93817-Sep-03 11:22
Ruben93817-Sep-03 11:22 

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.