文档详情

解推箱子的一个算法,算法应该挺难的,我看不明白(It should be hard to solve an algorithm for pushing the box, I cant see it).doc

发布:2017-07-23约9.89千字共20页下载文档
文本预览下载声明
解推箱子的一个算法,算法应该挺难的,我看不明白(It should be hard to solve an algorithm for pushing the box, I cant see it) This time, Im still using the poor lift method to write a robot that automatically pushes the problem of the box. Accidentally use yzwykkldczsh comrades write a state machine template and the template matching algorithm universal smart super iterative dynamic programming recursive algorithm is infinite (in honor of friends Jornathan Ding, this algorithm is also known as H D algorithm). Its basic principle is: 1. Put the data of each step and the box into a record, which represents the current state 2. Set the current status to be accessed Go through each of the sub-states. If all child states are accessed or unsolved, the current step is unsolved 4. If the child has a solution, the state is restored to an unvisited state. Repeat 1-4 for all substates. This algorithm can solve many puzzles, such as pouring wine, crossing the river, etc. I wrote the map in my test program. The actual application should be loaded from the file. Heres the test code: ACIter. H source / * * CACIter: auxiliary template class for recording node access state. The TNodeKey is the only hash value type that determines the current state, which should be a struct. * three states: nsNone: no or not in node access status table; Nsvisit: visiting; NsDead: dead * / # pragma once # include map Enum NodeStatus { NsNone, NsVisiting, nsDead }; The template typename _Ty The class CMemLessTempl : public STD: : binary_function _Ty, _Ty, bool { Public: Bool operator () (const _Ty _Left, const _Ty _Right) const { / * compare the two structs with byte byte comparison. Note that if the struct is not aligned by byte, the memset needs to be full 0 at initialization time, otherwise there may be interference data * / Unsigned char * p1 = (unsigned char *) _Left, * p2 = (unsigned char *) _Right; Return memcmp (p1, p2, sizeof (_Ty)) 0; } }; The template typename TNodeKey The class CACIter { Private: Typed
显示全部
相似文档