Advertisement
Guest User

main.cpp

a guest
Mar 29th, 2020
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.21 KB | None | 0 0
  1. //
  2. //  main.cpp
  3. //  EightPuzzle
  4. //
  5. //  Created by 李依蓉 on 2020/3/19.
  6. //  Copyright © 2020 李依蓉. All rights reserved.
  7. //
  8.  
  9. #include <iostream>
  10. #include <fstream>
  11. #include "node.h"
  12.  
  13. using namespace std;
  14.  
  15. void GetInitial();
  16. bool DepthLimitSearch(int limit);
  17. bool RecursiveDLS(Node *solution, Node initial, int limit);
  18. bool GoalTest(Node node);
  19. void Expand();
  20. void SuccessorFn(Node* arr, Node node);
  21.  
  22. //Node* TreeSearch(Fringe *fringe, Node solution); //Search the solution of the next move
  23. Fringe fringe;
  24. int depth = 0;
  25.  
  26. int main(int argc, const char * argv[]) {
  27.     int initial_status[9] = {1, 2, 0, 4, 5, 3, 7, 8, 6};
  28.     Node firstnode(initial_status);
  29.     firstnode.displayNodeStatus();
  30.     if(GoalTest(firstnode))
  31.         cout << "True" << endl;
  32.     else
  33.         cout << "False" << endl;
  34.     return 0;
  35. }
  36.  
  37. /*
  38.  Function : GetInitial
  39.  Purpose : obtain the initial state from the txt file
  40.  Input : the array for storing the initial state
  41.  Output : void
  42.  */
  43. void GetInitial()
  44. {
  45.     char str[9];
  46.     fstream file;
  47.     file.open("init",ios::in);
  48.     file.read(str, 9);  //從檔案讀取內容給str1
  49.     cout << "Initial State: " << str << endl;
  50.     file.close();       //關閉檔案
  51. }
  52.  
  53. bool DepthLimitSearch(int limit)
  54. {
  55.     int initial_status[9] = {1, 2, 0, 4, 5, 3, 7, 8, 6};
  56.     Node initial(initial_status);
  57.     Node solution;
  58.     //fringe.InsertNode(initial);
  59.     return RecursiveDLS(&solution, initial, limit);
  60. }
  61.  
  62. bool RecursiveDLS(Node *solution, Node initial, int limit)
  63. {
  64.     bool cutoff_occurred = false;
  65.     if(GoalTest(initial))
  66.     {
  67.         solution = &initial;
  68.         return true;
  69.     }
  70.     else if(depth == limit)
  71.     {
  72.         return false;
  73.     }
  74.     else
  75.     {
  76.         for()
  77.     }
  78.    
  79. }
  80.  
  81.  
  82. void Expand(Node node)
  83. {
  84.     Fringe successors;
  85.     Node test[4];
  86.     SuccessorFn(test, node); //Generate move
  87. }
  88.  
  89. //Test if the status of the node is the same as the goal
  90. bool GoalTest(Node node)
  91. {
  92.     int goal[9] = {1, 2, 3, 4, 5, 6, 7, 8, 0};
  93.    
  94.     for(int i = 0; i < 9; i++)
  95.     {
  96.         if(node.status[i] != goal[i])
  97.             return false;
  98.     }
  99.    
  100.     return true;
  101. }
  102.  
  103. void SuccessorFn(Node* arr, Node node)
  104. {
  105.     if()
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement