Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Simple question

Simple question

Scheduled Pinned Locked Moved C / C++ / MFC
questiondebuggingbeta-testinghelp
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    John Cruz
    wrote on last edited by
    #1

    // Creates a reference of the board then copies // the reference to a new board const CBoard& rConstBoard = *mpBoard; CBoard Board = rConstBoard; is this call rite? because it causing my whole function not to work properly. can any tell me whats the problem. here is my whole function if my question information is insufficient... // Searches for the best computer move on the board int CComputer::CheckForMoves(int Depth, int Alpha, int Beta, int& Row, int& Col) { // Check if the Entered Depth is greater than the Maximum depth ASSERT(Depth >= MAXDEPTH); // Creates a reference of the board then copies // the reference to a new board const CBoard& rConstBoard = *mpBoard; <-- the problem CBoard Board = rConstBoard; Row = Col = 1; return 0; } And i wanted to return both Row and Col but it wont do that... i have debugged 15X wid the debugger and i still can find my mistake. can anyone tell me what i am doing wrong??? :( :( :( john

    S C 2 Replies Last reply
    0
    • J John Cruz

      // Creates a reference of the board then copies // the reference to a new board const CBoard& rConstBoard = *mpBoard; CBoard Board = rConstBoard; is this call rite? because it causing my whole function not to work properly. can any tell me whats the problem. here is my whole function if my question information is insufficient... // Searches for the best computer move on the board int CComputer::CheckForMoves(int Depth, int Alpha, int Beta, int& Row, int& Col) { // Check if the Entered Depth is greater than the Maximum depth ASSERT(Depth >= MAXDEPTH); // Creates a reference of the board then copies // the reference to a new board const CBoard& rConstBoard = *mpBoard; <-- the problem CBoard Board = rConstBoard; Row = Col = 1; return 0; } And i wanted to return both Row and Col but it wont do that... i have debugged 15X wid the debugger and i still can find my mistake. can anyone tell me what i am doing wrong??? :( :( :( john

      S Offline
      S Offline
      Stan Shannon
      wrote on last edited by
      #2

      Why don't you just do this: CBoard Board = *mpBoard; // Assuming mpBoard has been properly instantiated. What makes you think you need a reference to CBoard? I mean, you've got a pointer to a board, than a reference to the same board and than a local instantiation of the same board. Looks a little convoluted to me. "There's a slew of slip 'twixt cup and lip"

      J 1 Reply Last reply
      0
      • S Stan Shannon

        Why don't you just do this: CBoard Board = *mpBoard; // Assuming mpBoard has been properly instantiated. What makes you think you need a reference to CBoard? I mean, you've got a pointer to a board, than a reference to the same board and than a local instantiation of the same board. Looks a little convoluted to me. "There's a slew of slip 'twixt cup and lip"

        J Offline
        J Offline
        John Cruz
        wrote on last edited by
        #3

        that worked but i still cant figure out the bug in my function. it returns both the row and column but it wont set the value. here is where i call the previous function... // Handles all the moves done by the computer void CChildView::ComputerMove() { // Set to default values int row = 0, col = 0; // Check for a possible move mpComputer->CheckForMoves(MAXDEPTH,Lose,Win,row,col); <-- this returns // both the row and column but the following function wont work // though the row and column is 1... mpComputer->SetMove(row,col); <-- wont work... Invalidate(); } when i comment out this: CBoard Board = *mpBoard; the whole function works just fine.... can anyone help me :( well, anways, thank you for your help... in advance :)

        S 1 Reply Last reply
        0
        • J John Cruz

          that worked but i still cant figure out the bug in my function. it returns both the row and column but it wont set the value. here is where i call the previous function... // Handles all the moves done by the computer void CChildView::ComputerMove() { // Set to default values int row = 0, col = 0; // Check for a possible move mpComputer->CheckForMoves(MAXDEPTH,Lose,Win,row,col); <-- this returns // both the row and column but the following function wont work // though the row and column is 1... mpComputer->SetMove(row,col); <-- wont work... Invalidate(); } when i comment out this: CBoard Board = *mpBoard; the whole function works just fine.... can anyone help me :( well, anways, thank you for your help... in advance :)

          S Offline
          S Offline
          Stan Shannon
          wrote on last edited by
          #4

          You have something wrong somewhere in your CBoard equal operator logic. The most likely culprit is that you are overwritting something in memory that something in SetMove does not like. Debug into CBoard& operator=( CBoard& ); "There's a slew of slip 'twixt cup and lip"

          J 1 Reply Last reply
          0
          • S Stan Shannon

            You have something wrong somewhere in your CBoard equal operator logic. The most likely culprit is that you are overwritting something in memory that something in SetMove does not like. Debug into CBoard& operator=( CBoard& ); "There's a slew of slip 'twixt cup and lip"

            J Offline
            J Offline
            John Cruz
            wrote on last edited by
            #5

            OH ok... thanx... i think your right coz i didnt write a default = operator. so i thnk thats the bug... thank you very much again stan :)

            1 Reply Last reply
            0
            • J John Cruz

              // Creates a reference of the board then copies // the reference to a new board const CBoard& rConstBoard = *mpBoard; CBoard Board = rConstBoard; is this call rite? because it causing my whole function not to work properly. can any tell me whats the problem. here is my whole function if my question information is insufficient... // Searches for the best computer move on the board int CComputer::CheckForMoves(int Depth, int Alpha, int Beta, int& Row, int& Col) { // Check if the Entered Depth is greater than the Maximum depth ASSERT(Depth >= MAXDEPTH); // Creates a reference of the board then copies // the reference to a new board const CBoard& rConstBoard = *mpBoard; <-- the problem CBoard Board = rConstBoard; Row = Col = 1; return 0; } And i wanted to return both Row and Col but it wont do that... i have debugged 15X wid the debugger and i still can find my mistake. can anyone tell me what i am doing wrong??? :( :( :( john

              C Offline
              C Offline
              CDuddley
              wrote on last edited by
              #6

              Are you writing a chess engine? -CDudd

              J 1 Reply Last reply
              0
              • C CDuddley

                Are you writing a chess engine? -CDudd

                J Offline
                J Offline
                John Cruz
                wrote on last edited by
                #7

                no... i am actually writing a Tictactoe program to so i can practice the alpha-beta pruning method.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups