                 if !result.isEmpty {
                     print("Result: \(result), total frame calcuated: \(calcuatedFramesCount)")
                     found = true
-                    DispatchQueue.main.async {
-                        NotificationCenter.default.post(name: NSNotification.Name(rawValue: "com.hanguang.app.puzzle.PuzzleFinishedNotification"),
-                                                        object: nil, userInfo: ["resutls": result])
-                    }
+                    completion(result)
                 }
                 
                 currentFramesQueue = nextFramesQueue

//            }
            self.puzzle.calcuateTheShortestWay({ (result) in
                DispatchQueue.main.async {
                    let stringResult = result.map({ (value) -> String in
                        switch value {
                        case -4:
                            return "D"
                        case 4:
                            return "U"
                        case -1:
                            return "L"
                        case 1:
                            return "R"
                        default:
                            return ""
                        }
                    })
                    
                    NotificationCenter.default.post(name: NSNotification.Name(rawValue: "com.hanguang.app.puzzle.PuzzleFinishedNotification"),
                                                    object: nil, userInfo: ["resutls": stringResult])
                }
            })
        }

    }
}

private struct PuzzleFrame {
    let previousStep: Int8
    let currentStep: Int8
    let frame: [Tile]
    let steps: [Int8]
    let key: Int
    
    init(previousStep: Int8, currentStep: Int8, frame: [Tile], steps: [Int8]) {
        self.previousStep = previousStep;
        self.currentStep = currentStep
        self.frame = frame
        self.steps = steps
        
//        var key = ""
//        for tile in frame {
//            switch tile.rawValue {
//            case 1 << 0:
//                key += "w"
//            case 1 << 1:
//                key += "r"
//            case 1 << 2:
//                key += "b"
//            default :
//                break
//            }
//        }
        
        let bytes: [UInt8] = frame.map { $0.rawValue }
        self.key = Data(bytes: bytes).hashValue // or key.hashValue
        print(key)
    }
}

