|
I'm pretty sure recursion for a function with as much code as AI would be over kill.
char gameBoard[9] = {0,0,0,
0,0,0,
0,0,0};
BOOL IsWin() const
{
char Piece = 'X';
...BEGIN loop
if(gameBoard[0] == Piece && gameBoard[1] == Piece && gameBoard[2] == Piece) return TRUE;
if(gameBoard[3] == Piece && gameBoard[4] == Piece && gameBoard[5] == Piece) return TRUE;
if(gameBoard[6] == Piece && gameBoard[7] == Piece && gameBoard[8] == Piece) return TRUE;
...
...
Piece = 'Y';
...END loop
return FALSE;
}
This is something like what I did
Cheers
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
hey thank for the help... shoq, andrew, christian and hockeydude. well, i think its not gonna be an over kill to use recursion because i am only implementing a Tictactoe board. so theres only 9 possible moves. but i think ill try do both recursion and the list idea. for recursion, ill make moves made and if the board is all occupied as my base case. as the general case it will just continue look at at possible moves - the moves done. for the list idea. ill try to immitate the deep blue idea by making a list of all the moves and putting it on a List or a stack. after i finish this ill try show you guys what i came up with...
|
|
|
|
|
if u did the tic tac toe in trees can u send it to me coz i wanna know how to do it in recursion. Hisham86@aucegypt.edu this my e-mail
thanks,
|
|
|
|
|
Hello,
I have a MDI that has 2 different document types open at all times.. (CHtmlView and CListView) how do I, from CMainFrame, activate a document of my choice?
For example.. If I have my CListView document open.. I need to pick a menu option that will activate my CHtmlView and navigate to a url. Right now I have it setup so that if the CHtmlView is active and I select the menu option it will navigate to the url.. but if I have my CListView active and I select the menu item it crashes.. I need for the app to activate CHtmlView..
Any Ideas?
Rob Jones
|
|
|
|
|
Hi again, Rob,
If you have a pointer to the HtmlView, you can just:
vptView->GetParentFrame()->BringWindowToTop();
Otherwise, what you need to do is some searching through the doc templates again. Basically, once you find the DocTemplate for the HtmlView:
CDocTemplate *vptHtmlTemplate = GetTheHtmlDocTemplate();
POSITION vtDocPos;
CDocument *vptDoc;
POSITION vtViewPos;
CView *vptView;
vtDocPos = vptHtmlTemplate->GetFirstDocPosition();
if (vtDocPos != NULL)
{
vptDoc = vptHtmlTemplate->GetNextDoc(vtDocPos);
vtViewPos = vptDoc->GetFirstViewPosition();
if (vtViewPos != NULL)
{
vptView = vptDoc->GetNextView(vtViewPos);
vptView->GetParentFrame()->BringWindowToTop();
}
}
Hope this helps.
------------------------
Derek Waters
derek@lj-oz.com
|
|
|
|
|
Derek Waters wrote:
CDocTemplate *vptHtmlTemplate = GetTheHtmlDocTemplate();
I'm lost here.. I need to provide a pointer to my CMyHtmlView? Not sure how to do this. What is happening in the GetTheHtmlDocTemplate?
Thanks
Rob
|
|
|
|
|
Yeah, sorry Rob, basically you need to get a pointer to the DocTemplate for the HtmlView document type. This is like the function I sent you the other day for creating documents at startup:
CDocTemplate *GetTheHtmlDocTemplate()
{
CWinApp *vptrTheApp = AfxGetApp();
POSITION vtPos;
CDocTemplate *vptTemplate;
CString vcstrTitle;
vtPos = vptrTheApp->GetFirstDocTemplatePosition();
while (vtPos != NULL)
{
vptTemplate = vptrTheApp->GetNextDocTemplate(vtPos);
if (vptTemplate->GetDocString(vcstrTitle, CDocTemplate::fileNewName))
{
if (vcstrTitle.CompareNoCase(_T("MyHtmlDoc")) == 0)
{
return vptTemplate;
}
}
}
return NULL;
}
------------------------
Derek Waters
derek@lj-oz.com
|
|
|
|
|
You ROCK bud!!!
Thanks again for all your help.. That worked like a charm!
Rob
|
|
|
|
|
When I place all files together, the cpp. header and data files together, I mean, lump them all in one directory, e.g. in driver.cpp files, my program runs fine.
However, when I place them seperately into the source, header and resource file folders of a win32 console application project, the file compiles ok but it could not find the data file when I enter the data file's name in the console. I can open all the files including data file in VC++.
Is there anyway I can fix it? Sorry for the rudimentary question.
padgyx
|
|
|
|
|
Data file...as in
CFile myFile("Hello.dat, options);
If you don't enter the Path in the filename...the application uses the directory of the current process.
if your file resides in say C:\myCoolProjects\data
you should do:
CFile myFile("data\\Hello.dat", options);
I think this is what your after. And I hope this all works
Peace!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
As in MSDN, ON_CBN_DBLCLK only works with CBS_SIMPLE style.
So how to catch a double click in my CMyComboBox with dropdown-style. (I tried OnLButtonDblClk, OnDblclk, OnNcLButtonDblClk...)
thx
|
|
|
|
|
After a time, I solved problem myself:
BOOL CMyComboBox::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message == WM_LBUTTONDBLCLK)
{
//....
}
else
return CComboBox::PreTranslateMessage(pMsg);
}
|
|
|
|
|
I wrote a card game in VB and was trying to port it over to MFC and it's a nightmare! Is there a class out there that works like the Image Control in VB: (1) overlapped cards are always drawn clipped correctly, (2) you can move the card on the dialog without all kinds of fancy work, etc?
|
|
|
|
|
The image control...?
What do you mean without all sorts of fancy work...?
LBUTTONDOWN LBUTTONUP....???
Theres probably an ActiveX control thats exactly what your looking for.
Micorsoft Forms 2.0 Image control maybe...?
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
The STATIC control (called the Picture control on the toolbar in VS) might work for you. To ensure it is clipped, you can set the WS_CLIPSIBLINGS style. MoveWindow() is as fancy as it gets.
farewell goodnight last one out turn out the lights Smashing Pumpkins, Tales of a Scorched Earth
|
|
|
|
|
Hi,
I wanna change the current font in a EditView with CFont Dialog.
I have placed the following lines in my code:
void CMainFrame::OnFont()
{
CMyDoc* pDoc = (CMyDoc*)GetActiveDocument();
LOGFONT logfont;
CFontDialog fontdlg;
if (fontdlg.DoModal() == IDOK)
{
pDoc->m_Font.DeleteObject();
pDoc->m_Font.CreateFontIndirect(&logfont);
POSITION pos;
pos = pDoc->GetFirstViewPosition();
CMyEditView* pMyEditView;
while (pos)
{
pMyEditView = (CMyEditView*)pDoc->GetNextView(pos);
if (pMyEditView->IsKindOf(RUNTIME_CLASS(CMyEditView)))
pMyEditView->Invalidate();
}
}
}
and
void CMyEditView::OnDraw(CDC* pDC)
{
CDocument* pDoc = GetDocument();
CEdit* pEdit = &GetEditCtrl();
pEdit->SetFont(&pDoc->m_Font);
pEdit->SetWindowText("My Text");
}
It does not work and dunno why.
Thanks for your help.
R.
|
|
|
|
|
Don't you need to call CEditView::OnDraw from CMyEditView::OnDraw ?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I have generated an empty project but there is no such call
|
|
|
|
|
Sort of. I've investigated a little further: CEditView derives from CCtrlView , which adds its own WM_PAINT handler bypassing further calls to OnDraw . So, if I'm not wrong on this, CMyEditView::OnDraw is never called (you can confirm/refute this). Move the SetFont to somewhere else (one good candidate is the very body of CMainFrame::OnFont .)
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
OnDraw was really not called (put a AfxMessageBox and no response).
Works perfectly.
Thank you very much.
R.
|
|
|
|
|
Hi,
I have a simple SDI CView in the client area of my mainframe and wanna create a splitterwindow in its bottom only when a button is pressed (and destroy it after usage).
My problem is that a splitterwindow is meant to be created in the CMainFrame::OnCreateClient which creates the splitterwindow "forever" even when I don't want it.
What is the solution?
Thak you.
R.
|
|
|
|
|
Check here under MFC controls, splitter windows...
I think there are some classes that allow easy construction of dynamic splitter windows.
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
I sould post again the question, in another light:
If C++ is an OO program, why compiler doesn't provide automaticaly a default program entry point, if it is not provided by programmer?
There are compilers that do this? Which one?
Is a way to make Visual C++ compiler to do this?
Does anyone know something about so called "nostub" programs?
Regards
|
|
|
|
|
If C++ is an OO program, why compiler doesn't provide automaticaly a default program entry point, if it is not provided by programmer?
IMHO, the object-orientation of the language has little if anything to do with the automatic provision of an entry point for a program.
There are compilers that do this? Which one?
None that I know of. It would be against the standard, which very clearly specifies how an entry program is to be provided.
What is that you're after? If you explain yourself a little longer, maybe we'll be able to help you.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
My problem is that in MFC, program entry point is encapsulated somewhere in a class. (Or maybe my understanding is wrong here??). I want to do the same, and have no global function in my application.
Thanks.
|
|
|
|