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. MFC Tictactoe alpha-beta pruning bug...

MFC Tictactoe alpha-beta pruning bug...

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++beta-testingcode-review
1 Posts 1 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

    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 :-)

    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