Hey folks,
Thought I could use some help with this. I have the basic foundation around the app, but cannot seem to get things working correctly.
Can someone have a look at the code below and help me to tweak it to get it working correctly?
Thanks in advance,
VPascuzzi. -
// TicTacToe.cpp : Defines the entry point for the console application.
-
//
-
-
#include "stdafx.h"
-
#include <cctype>
-
#include <conio.h>
-
#include <iostream>
-
#include <iomanip>
-
//#include <stdlib.h>
-
using std::cin;
-
using std::endl;
-
-
// Function Prototypes
-
int Display_Grid( int* Cells ); // Displays tic tac toe grid; refreshed every turn
-
int Check_Game_State( int* Cells ); // Tracks game status to determine WIN, LOSE, TIE, CONTINUE
-
int Machine_Move( int* Cells ); // AI computer move
-
int Open_Spots( int* Cells ); // Function to display open cells
-
-
int _tmain(int argc, _TCHAR* argv[])
-
{
-
int Player1_Move = NULL; // Player1 move temporary storage
-
int Cells[9] = { NULL }; // Array for storing cell contents
-
int Open_Cells[9] = { NULL }; // Array for storing list of open cells
-
int Game_State_Flag = 0; //{ "CONTINUE", "WIN", "LOSE", "DRAW" );
-
-
for ( int Move_Counter = 0; Move_Counter < 9; Move_Counter++ ){
-
Display_Grid( Cells );
-
Open_Spots( Open_Cells );
-
-
printf( "\nPlayer please select a number from 1 - 9: " );
-
cin >> Player1_Move;
-
-
Open_Cells[Player1_Move-1] = 1;
-
Cells[Player1_Move-1] = 79;
-
-
Open_Cells[Machine_Move( Cells )]; // CPU makes move depending on Cells[] values
-
-
system( "CLS" );
-
}
-
return 0;
-
}
-
-
// Function Definitions
-
int Display_Grid( int* Cells ){
-
printf( " %c | %c | %c \n", Cells[0], Cells[1], Cells[2]);
-
printf( "---+---+---\n");
-
printf( " %c | %c | %c \n", Cells[3], Cells[4], Cells[5]);
-
printf( "---+---+---\n");
-
printf( " %c | %c | %c \n", Cells[6], Cells[7], Cells[8]);
-
-
return 0;
-
} // end Display_Grid function definition
-
-
int Check_Game_State( int* Cells ){
-
-
return 0;
-
}// end Check_Game_State function definition
-
-
int Machine_Move( int* Cells ){
-
for ( int i = 0; i < 9; i++ ){
-
for ( int j = 1; j <= 9; j++ ){
-
if( ( Cells[i+j] == NULL ) && ( Cells[i] + Cells[j] == 158 ) )
-
Cells[i+j] = 88;
-
}
-
}
-
return *Cells;
-
} // end Machine_Move function definition
-
-
/* Fix this function
-
It currently checks the Cells array incorrectly.*/
-
int Open_Spots( int* Cells ){
-
printf( "Open spots remaining:\n" );
-
for ( int i = 1; i <= 9; i++ ){
-
if ( Cells[i-1] == NULL )
-
printf( " %d ", i );
-
}
-
return *Cells;
-
}
-
3 6958
Try returning a pointer to the array, with &Cells. The return type would be int**.
There's also no need to have these int functions (like display) return 0 when they can be void, especially since there is no exception handling to take advantage of return states.
Also, what's up with all these nonstandard headers? I don't know 'stdafx.h', but conio has a pretty bad reputation.
- int Player1_Move = NULL; // Player1 move temporary storage
Can you explain me what is this supposed to do?
Also please explain your problem in greater detail.By telling I'm having a problem and not specifying what it is,make as guess things,instead of being able to accurately help you.It's recommended to read our posting guidelines,especially the part where it's described how to post accurate question.
What exactly is your problem? Heres a few things i see.
for ( int Move_Counter = 0; Move_Counter < 9; Move_Counter++ ){
Display_Grid( Cells );
Open_Spots( Open_Cells );
int Check_Game_State( int* Cells ) {
return 0;
}// end Check_Game_State function definition
The game can end before 9 moves. So you need to have an array that checks all rows, then all columns (straight across, then straight drown) to see if the cells equal x or o. Then you need to check the diagonals to see if any of the two diagonals is equal to 3 x's or o's. This needs to go in the Check_Game_State function. That means you would need to change you main loop to a do while loop. I would create a boolean value to keep track if the game is finished or not (used in the loop i described above). The Check_Game_State function should return the boolean value used in the loop i described above.
int Cells[9] = { NULL }; // Array for storing cell contents
If your storing the cells and setting them to NULL then if a Cell == NULL the cell is open. The open cell array is not needed.
Also I'm not quite sure what your logic is behind the machine move function mind explaining that one a little bit better? Anyways i hope this helps. If any of this is unclear let me know.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Dave |
last post by:
Hi,
I have done some research, trying to Clear The Screen in java code.
The first option was the obv:
system.out.print("\n\n\n\n\n\n\n\n\n\n\n\n");
then i heard about this method:...
|
by: Devrim Erdem |
last post by:
Hello,
I am on win32 with python2.2.
My python added C++ app is an OpenGL application so there is no real
GUI code around it. I have built in the python interpreter which works
very great. I...
|
by: porous |
last post by:
hi
i would like to develop applications for windows in c++ , but i dont
want to do any gui .i just want the program to be in console mode .
but i would like to access the widows api . can any...
|
by: Eitan |
last post by:
Hello,
I am using Visual Studio.net 2003.
I am trying to find how to create Win32 DLL & Win32 Static Library.
When going through the wizard it does not show me the option for these two
project...
|
by: Dr. Erhard Moenige |
last post by:
Hi all C-Programmers everywhere !
I 've been learning programming c in console-applications for 1 year
and now I'm tired of seeing this boring console-application in my
programms. Because of...
|
by: SheetalGandhi24 |
last post by:
Hi
I need to use the System.IO namespace in the Win32 console
application. Any clues for doing the same?
Basically, I need to load the files of a particular folder in an
array. I need to do...
|
by: jbenezech |
last post by:
Hi all ,
I have a perl/java app running under Win32. The application consists of a perl service (Win32::Daemon) and of java classes. The perl service calls every xx hours java classes to perform...
|
by: Peter Nimmo |
last post by:
Hi,
I am writting a windows application that I want to be able to act as if
it where a Console application in certain circumstances, such as error
logging.
Whilst I have nearly got it, it...
|
by: Frank Moyles |
last post by:
Hi, I want to use SciPy library. I am using W2k, and ActiveState Python
2.5. I have succesfully numpy, but when I run the
scipy-0.6.0.win32-py2.5.exe (from the downloads section on the SciPy...
|
by: =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= |
last post by:
As far as I know, the C Standard has no mention of multi-threaded
programming; it has no mention of how to achieve multi-threaded
programming, nor does it mention whether the language or its...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |