Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.cpp
- // EightPuzzle
- //
- // Created by 李依蓉 on 2020/3/19.
- // Copyright © 2020 李依蓉. All rights reserved.
- //
- #include <iostream>
- #include <fstream>
- #include "node.h"
- using namespace std;
- void GetInitial();
- bool DepthLimitSearch(int limit);
- bool RecursiveDLS(Node *solution, Node initial, int limit);
- bool GoalTest(Node node);
- void Expand();
- void SuccessorFn(Node* arr, Node node);
- //Node* TreeSearch(Fringe *fringe, Node solution); //Search the solution of the next move
- Fringe fringe;
- int depth = 0;
- int main(int argc, const char * argv[]) {
- int initial_status[9] = {1, 2, 0, 4, 5, 3, 7, 8, 6};
- Node firstnode(initial_status);
- firstnode.displayNodeStatus();
- if(GoalTest(firstnode))
- cout << "True" << endl;
- else
- cout << "False" << endl;
- return 0;
- }
- /*
- Function : GetInitial
- Purpose : obtain the initial state from the txt file
- Input : the array for storing the initial state
- Output : void
- */
- void GetInitial()
- {
- char str[9];
- fstream file;
- file.open("init",ios::in);
- file.read(str, 9); //從檔案讀取內容給str1
- cout << "Initial State: " << str << endl;
- file.close(); //關閉檔案
- }
- bool DepthLimitSearch(int limit)
- {
- int initial_status[9] = {1, 2, 0, 4, 5, 3, 7, 8, 6};
- Node initial(initial_status);
- Node solution;
- //fringe.InsertNode(initial);
- return RecursiveDLS(&solution, initial, limit);
- }
- bool RecursiveDLS(Node *solution, Node initial, int limit)
- {
- bool cutoff_occurred = false;
- if(GoalTest(initial))
- {
- solution = &initial;
- return true;
- }
- else if(depth == limit)
- {
- return false;
- }
- else
- {
- for()
- }
- }
- void Expand(Node node)
- {
- Fringe successors;
- Node test[4];
- SuccessorFn(test, node); //Generate move
- }
- //Test if the status of the node is the same as the goal
- bool GoalTest(Node node)
- {
- int goal[9] = {1, 2, 3, 4, 5, 6, 7, 8, 0};
- for(int i = 0; i < 9; i++)
- {
- if(node.status[i] != goal[i])
- return false;
- }
- return true;
- }
- void SuccessorFn(Node* arr, Node node)
- {
- if()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement