Thanks for the help Christian :-d Thank you very much, John :-D Aloha from Hawaii :-)
John Cruz
Posts
-
Sort algorithm -
Sort algorithmsorry about that Christian. here is my code now: #include #include using std::sort; using std::cout; using std::cin; struct SPRITE { int x; int y; }; // Maximum number of sprites const int N_SPRITES = 10; bool Compare (const SPRITE &one, const SPRITE &two) /* Pre: Enter value for one and two * Post: Compares all of both strings */ { return (one.y < two.y); } int main() { // Array of sprites SPRITE sprites[N_SPRITES]; // Number value int value; for (int i=0; i> value; sprites[i].y = value; } sort(sprites[0], sprites[9], Compare); for (i=0; i &)' : could not deduce template argument for 'const struct std::iterator<_C,_Ty,_D> &' from 'struc t SPRITE' 3rd error: error C2780: 'void __cdecl std::_Sort_0(_RI,_RI,_Ty *)' : expects 3 arguments - 4 provided c:\program files\microsoft visual studio\vc98\include\algorithm(541) : see declaration of '_Sort_0' C:\DOCUMENTS AND SETTINGS\JOHN CRUZ.JCRUZ495\MY DOCUMENTS\MY PROJECTS\C++\Sort\main.cpp(46) : see reference to function template instantiation 'void __cdecl std::sort(struct SPRITE,struct SPRITE,bool (__cdecl *)(const struct SPRITE &,const s truct SPRITE &))' being compiled hey am really sorry for not providing what the errors were earlier. well anyways. I REALLY APPRECIATE ALL YOU GUYS HELP :-D Thank you very much, John :-D Aloha from Hawaii :-)
-
Sort algorithmChristian Graus wrote: Oh - your one include was iostream and your error was unable to find sort ? It's in algorithm. You'll still need to move Compare so it's defined before you call it, or forward declare it. i got both of that and i have included it like this: #include #include using std::sort; using std::cout; using std::cin; struct SPRITE { int x; int y; }; // Maximum number of sprites const int N_SPRITES = 10; // Array of sprites SPRITE sprites[N_SPRITES]; bool Compare (const SPRITE &one, const SPRITE &two) /* Pre: Enter value for one and two * Post: Compares all of both strings */ { return (one.y < two.y); } int main() { int value; for (int i=0; i> value; sprites[i].y = value; } sort(sprites[0], sprites[9], Compare); for (i=0; i
-
Sort algorithmWhat header is sort under? thank you very much Christian :-D Thank you very much, John :-D Aloha from Hawaii :-)
-
Sort algorithmCan anyone help me fix this. i am trying to sort the y's of my sprite from highest to lowest values and then print it out. this is what i have but my compiler wont compile it. can anyone kind enough to help me fix this to allow it work. anyways, thank you very very much. i really appreciate it. :-D #include using namespace std; struct SPRITE { int x; int y; }; // Maximum number of sprites const int N_SPRITES = 10; // Array of sprites SPRITE sprites[N_SPRITES]; bool Compare (const SPRITE &one, const SPRITE &two); /* Pre: Enter a Sprite value for one and two * Post: Compares all of both strings */ int main() { int value; for (int i=0; i> value; sprites[i].y = value; } int* begin = &sprites[0]; int* end = &sprites[9]; sort(begin, end, Compare); for (i=0; i
-
can anyone kind enough to point out my bug here.i got your number my first mistake fixed. but the second mistake: Niklas Lindquist wrote: one and two are pointing to SPRITE objects. So it should be something like: return strcmp(((SPRITE*)one).y, ((SPRITE*)two).y); that is if the y member is a char*. this wont compile because i am using strcmp which has needs 2 const char parameters and because y is not a member of char. does any know how to fix this thing? well anyways, thank you very much. Thank you very much, John :-D Aloha from Hawaii :-)
-
DATE/TIMEPICKERTry say that again in english?? Thank you very much, John :-D Aloha from Hawaii :-)
-
can anyone kind enough to point out my bug here.i am trying to use qsort so that i can sort out y from highest to lowest. can anyone help me? anyways, thank you very much. struct SPRITE { int x; int y; }; // Maximum number of sprites const int N_SPRITES = 10; // Array of sprites SPRITE sprites[N_SPRITES]; int Compare (const void *one, const void *two); /* Pre: Enter value for one and two * Post: Compares all of both strings */ int main() { int value; for (int i=0; i> value; sprites[i].y = value; } qsort(sprites, N_SPRITES, sizeof(int), Compare); for (i=0; i
-
qsort problemthank you very much for you guys help. i really appreciate it. i dont have a MSDN library so i couldnt do this problem. thank you very much again. Thank you very much, John :-D Aloha from Hawaii :-)
-
qsort problemcan anyone help me on how to use the stl qsort and if possible give me examples. i am try to use qsort so that i can sort out values from smaller value to higher values. how do i do that? anyways, thank you very much... Thank you very much, John :-D Aloha from Hawaii :-)
-
Debugging Recursive functionscan anyone tell me how to debug and test recrusive functions??? i have trying putting trace statements and using the VC++ debugger but i always get lost on what i was doing. i trying looking at the call stacks but it is useless. Can anyone tell me what's the most efficient and the most easiest way to debug my recrusive function???? Thank you very much, John :-D Aloha from Hawaii :-)
-
MFC Tictactoe alpha-beta pruning bug...can anyone help me find my bug. i wrote a function that would search the tictactoe board for the best possible computer move. i am using alpha beta pruning to optimize my search. the function returns the score from the search and the row and column where the computer should move. ok here is the function... the PossiblePlayerMove function is the same thing but it searches for the best possible player move. int CComputer::CheckForMoves(const CBoard &rConstBoard,int nDepth, int nAlpha, int nBeta, int &nRow, int &nCol) { // Check for invalid data ASSERT(mnDepth >= 0 && mnDepth <= MAXDEPTH); // Check if the row and column return is a valid value ASSERT(nRow < MAXROW && nCol < MAXCOL); int nScore = 0; // The score from the search mnDepth = nDepth; // Set the Depth to the new depth. int Row = nRow; // Copy the Row and Column int Col = nCol; // Create a new Board and Copy the values of other board. CBoard Board = rConstBoard; // Base Case if (Winner(Board) || mnDepth == 0) { nRow = Row; nCol = Col; return Evaluate(Board); } else { // Try all the possible move on a different Board // then return the best move. for (int row = 0; row < MAXROW; row++) for (int col = 0; col < MAXCOL; col++) if (Board.IsEmpty(row,col)) { Board.SetCellValue(row,col,'O'); if (mnDepth == 0) break; nScore = PossiblePlayerMove(Board,mnDepth - 1,nBeta,nAlpha,Row,Col); // Set Row and Column nRow = Row; nCol = Col; if (nAlpha < nScore) nAlpha = nScore; Board.SetCellValue(row,col,NULL); if (nAlpha >= nBeta) break; } } return nAlpha; } i hope this is enough... by the way.. the possible moves function is the same thing ... Thank you very much, John :-D Aloha from Hawaii :-)
-
adding MAILTO for MFCthanks... Thank you very much, John
-
adding MAILTO for MFChow do you put a code like mailto: so that when a user clicked the email address it will open up the outlook express so that the user can email someone... i am trying to put my email address in my about dialog box for my program but i cant seem to figure out how to put mailto. is there any way to do that??? Thank you very much, John
-
My Copy Constructor bug problemI think now i see that i have a bad program design. my whole tictactoe design is wrong because i only made 3 objects. Board, Player, and Computer. Board handles all the drawing on the board, Player handles all the player moves and stuff. Computer is derived from the Player but it has some additional functions like the Alpha-beta pruning function. IS THERE ANYWAY I CAN FIX MY PROBLEM WITHOUT TRASHING ALL MY CODE. i am sorry, i am still new at this stuff... Thank you very much, John
-
My Copy Constructor bug problemI have tried it but the compiler gave me an error saying operator= not available. Does CPen and CFont have an Assignment operator... here is what i did.. // Create new objects mpPen = new CPen; mpFont = new CFont; // Set the values to the new values *mpPen = *Copy.mpPen; *mpFont = *Copy.mpFont; Thank you very much, John
-
My Copy Constructor bug problemok ill try that alexandru. :-) Thank you very much, John
-
My Copy Constructor bug problemOh, i am very sorry... i made a mistake in typing my copy constructor... my copy constructor does look like the one u have. here it is and this is whats inside. CBoard::CBoard(const CBoard& Copy) { // Create new objects mpPen = new CPen; mpFont = new CFont; // Set the values to the new values mpPen = Copy.mpPen; mpFont = Copy.mpFont; // Set the values to default for now mpDefaultPen = NULL; mpDefaultFont = NULL; // Sets the rectangle to a certain point, width and height for (int r = 0; r < MAXROW; r++) for (int c = 0; c < MAXCOL; c++) { mCell[r][c] = Copy.mCell[r][c]; mpGrid[r][c] = new CRect(mLeftTopPt,CSize(mCellWidth,mCellHt)); mpGrid[r][c] = Copy.mpGrid[r][c]; } } thank you very much.
-
My Copy Constructor bug problemhello. i am currently writing a program tictactoe for windows. i got mostly everything working. i got the program to draw the board and draw the X's and O's. the game start by beginning with the player then wait for the computer to move. i got the part where the player clicks on the board and an X is drawn in the grid. i only have to make the computer move but Everything seems to work OK, until last nite when I created a function CheckForMoves which returns an integer and also returns the row and column which is best move. inside the function CheckForMoves, i created a Board then i assigned it to a pointer to Board like this: CBoard board = *pBoard; pBoard is the Board i am using to draw my X's and O's for the game. i am copying it to a new board so i can try out all the possible moves in a new board without touching the board i am using in the game. because my board class was implemented dynamically, i wrote my own assignment operator and my own copy constructor. in my assignment operator function, i delete what ever the pointer is point to, then call new then point it to whatever is in the right of the operator. Copy constructor, because it is empty, i just point the pointers to what ever is on the right side. i went along and debugged it using the VC++ debugger then when i was walking through the code i saw that it was calling the Copy constructor. then as i walk over the Copy Constructor everything seems fine. by using asserts, if found out that all the pointers are being copied right. the cells where i store the X's and O's are copied right too. i tried using TRACE statements but i cant find the bug causing the BOARD TO BE EMPTY. i tried using MessageBox before and after calling the copy constructor. as i moved the MessageBox i saw my move X on the Board. but as soon as i clicked the MessageBox that Outputs "After" called after the copy constructor was called. the X in the board disappears. MY CONCLUSION IS THE BOARD I AM USING IN THE GAME IS BEING CHANGED SOMEHOW IN THE COPY CONSTRUCTOR. the copy constructors parameters is like this: CBoard& CBoard::CBoard(const CBoard& Copy) I Hope this helps explain my problem. sorry if its very long, i just want to explain it with much detail so i can tell you whats going on. Can anyone tell me whats wrong wid my program and how i can fix it? i would appreciate any method on how to find the bug. Thank you very very much. John
-
Where is a Trace Statement outputtedThanks Christian.