|
Okay that makes more sense. As you said it is bizarre.
Thanks,
Steve
|
|
|
|
|
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! 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 ' ';
}
|
|
|
|
|
|
thankyou
<marquee>Universal Project... Soon to be a .net
|
|
|
|
|
I'm assuming that what you want is the computer to play tic tac toe against a human, with the human being the x's. I'm not into A.I, but you can do this by brute force, since it's only tic tac toe with so many possible combinations. There are eight ways that the computer can win, and 8 ways that a human can win, for a total of sixteen winning combinations (3 vertical rows, 3 horizontal rows, and the two diagnols for each of the players). When it is the computer's turn, check all of the combinations for a win. If there is not immediate win, then check all of the human's combinations for a win and block it. Your check() function would have to be modified. What I would do, say for checking the computer for a win, is count the number of o's per combination, with the only possible counts being 0, 1, or 2. Save the combinations that don't have x's. This will be used for the computer's move, once it's determined that the human doesn't have a pending win forcing the computer to block. Now check all the combinations again, this time for x's to see if the human has a pending win that the computer must block. If there were 2 x's in a combination with a blank, then the computer would have to put an o in the blank to block the human's win. If the player didn't have a pending win, then go back to the saved combinations for the computer and programatically determine the best move, based on the counts in the combinations of o's. This is brute force, but with careful maniupulation, this would get the computer playing a human.
Ed
|
|
|
|
|
Thank you
<marquee>Universal Project... Soon to be a .net
|
|
|
|
|
I have a dialog based application - the dialog being a derivitave of CDialog.
The dialog does not have a title bar. I can customize the icon shown in the taskbar when I run the application, but I have no idea how to change the text on the taskbar.
When I enable the title bar, the taskbar shows the text that I enter in the caption field in properties. When I disable the title bar, and delete the caption, the text of course disappears from the taskbar. If I enable it, enter text in the caption, and disable it, my dialog acts pretty funky and the taskbar text does not appear.
|
|
|
|
|
You can use the SetWindowText(...) function in your InitDialog.
"A robust program is resistant to errors -- it either works correctly, or it does not work at all; whereas a fault tolerant program must actually recover from errors."
|
|
|
|
|
I know that VS.Net have included the Crystal Report. And I do know that
it is third-party software. The company is now releasing Crystal Report
version 9, so I wonder what kind of Crystal Report have we got in the
VS.Net? Is it a full version or simplified version? or even worse, a
trial version?
|
|
|
|
|
It's starting to tick me off here! I have this template class (may or may not be relevant), and my code seems to crash somtimes. Thing is I can't see much more than just a vague pattern, and it seems to move around a lot. I think it's somthing to do with the heap... When I first tested the code, it somhow crashed within a _tcsdup command, somwhere within the allocation part. So as I havn't used this command too much in the past I just replaced it with
LPTSTR mystr = new TCHAR[_tcslen(str)+1];
_tcscpy(mystr, str); That seemed to move the problem somewhere else:
newbuckets = new Bucket[newarraysize]; Bucket is a nested struct in my class. And newarraysize is sensible value around 11ish. Stepping inside stack scope, I came to a place in malloc.c (ln 211) right before things descend into assembler of ntdll.dll.
return HeapAlloc(_crtheap, 0, size); Baffling because _crtheap seemed to have a value of 0x00320000 (or somthing), and size was not dissimilar to what I'd requested up above. Ok; then somthing triggered the problem to move elsewhere onto a memset function of mine; used to initialise this array of buckets with zeros. That was crashing on in some kind of inline assembly loop routine. So I replaced the memset command with a ZeroMemory , and that caused the problem to descend back on my string allocation routine above! Has anyone seen this before? any ideas? any at all?
*¨¨`)
¸¸.·´ ¸.·*¨¨`)
(¸¸.·* ¸ .·*
¸¸.·*
(¸¸.~~> Joel Holdsworth.
|
|
|
|
|
Make 1000058108829489190289840 calls to _CrtCheckMemory all through your code. It is an ugly hack, but the most effective way I have seen, other than the use of specialized tools, to handle this problem.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Yes I was beginning to wonder about the validity of the memory myself, but I even have a try block around the bucket allocation, and which survives ok! It's almost like the system's giving me bogus allocations!
*¨¨`)
¸¸.·´ ¸.·*¨¨`)
(¸¸.·* ¸ .·*
¸¸.·*
(¸¸.~~> Joel Holdsworth.
|
|
|
|
|
How can I now the size of CFont object?
I wnat print the real size of a font like microsoft word. I use MM_TEXT mode anf DrawText function.
aLeXs
|
|
|
|
|
i'm not sure I understand...
sizeof I think works on classes...unless you mean height...?
GetTextMetrics()
tm.tmHeight; + tmExternalLeading; // Maybe Internal...can't remmeber
Cheers
I'm drinking triples, seeing double and acting single
|
|
|
|
|
I just want to print a text with the real HEIGHT points. For example, in word when I print a text with font arial 12 points, in the papper the font height is @3mm, but when I use textout function (with Cfont object selected by HDC) the height in papper is @1mm and change with the printer type.
|
|
|
|
|
I have developed a C++ ActiveXObject (dll) which gets loaded in IE with javascript using:
oMyObject = new ActiveXObject( "myDLL" );
The problem is that I need to be able to unload that dll so that I can replace (overwrite) it during a web update.
I have tried deleting oMyObject and setting oMyObject=null but neither seem to work.
The only thing that seems to work is quitting IE which I really don't want to do.
There has to be a way to force IE to let go of the dll.
Any help here would be greatly appreciated.
Thanks,
Pace
|
|
|
|
|
There has to be a way to force IE to let go of the dll.
Unfortunately, you can't. And this is not IE -- in your case, it's JavaScript object.
Your object will probably stay untill next CoFreeUnusedLibraries() will be called.
You may ask yourself however, why do you need your ActiveX dll to unload?
Maybe there is other way to perform what you need?
For example, setting oMyObject=null in javascript will cause FinalRelease and destructor of your object being called -- maybe you can put that logic in there?
"...Ability to type is not enough to become a Programmer. Unless you type in VB. But then again you have to type really fast..."
Me
|
|
|
|
|
There is a file you can modify in Visual Studio which allows you to specify things not to step into when F11 stepping but I don't remember where it is or how to set it up. I know you can just step right back out (Shift F11) of code block, but since there is a way to bypass it in the first place, I'd rather do that.
Ex.
CString cs="Hi";
MyFn(cs); // I want to step into MyFn() without
// stepping into the CString constructor
Does anyone know how to do this?
Thanks in advance!
Grailman
|
|
|
|
|
Use the right mouse button or from the debug menu (when debugging) select "step into specific function".
Example:
=======
CString strText = "abc";
MyPrintFunction(strText); // Beak point here
When clicking on "MyPrintFunction" with the right mouse buttion, a popup menu will appear and just below QuickWatch you will see "step into MyPrintFunction"
I hope this makes sense, it has been a long day.
|
|
|
|
|
That does work but it's much nicer to just continue F11-ing to the code I want rather than playing with the mouse. Like I said there is a way to do it, I just need to remember what file needs to be changed and how...
|
|
|
|
|
From the tools menu select
Customize...
Click on the Keyboard tab
From the Category Combo Box select
Debug
From the commands list box select
DebugStepIntoSpecificFunction
Click on "Press New Shortcut Key" edit box and select you new key combination.
CTRL+SHIFT+F11
Click on the [ASSIGN] button.
No you cannot reassign F11 but you can try reassigning F2.
Go to the Edit Category and delete F2 from BookMarkNext
|
|
|
|
|
A question that I didn't find answer to on MSDN or
via Google.
In Visual-C 6+ compiling with "cl /Gr" i.e. __fastcall, how do I detect this at compile time?
I need to use something like this:
#if defined(_MSC_VER)
#include <fastcall.h>
#if defined(__fastcall) || defined(FASTCALL_IN_STORE)
#error Don't even think about compiling this as fastcall (cl /Gr)
#endif
#endif
Unfortunately it doesn't work. Any hints?
Where is FASTCALL_IN_STORE set and what does it mean?
I'm not sure it's related to option /Gr (since it's not prefixed
with '__').
BTW. Watcom sets the symbols __SW_3R in this case.
Gisle V.
"If you feel paranoid it doesn't mean they're not after you!" -- Woody Allen
|
|
|
|
|
visible spaces of a Tab ('\t') character equal to 8 or 6 space (' ') characters in CRichEditCtrl by default.
now i need to change its visible spaces to 4 space characters, but i can't find idea to do that.
in visual c++ ide (not RichEdit), there is a setting which can change visible spaces of a Tab character to any space characters, i want to create a similar setting for our users.
thanks in advance for any hints and help.
includeh10
|
|
|
|
|
|
thx.
i think this is right point.
i will do a test to get it work.
includeh10
|
|
|
|