bool fmpAStarPathFinder::findPath(const Hexagon& start, const Hexagon& goal, std::vector<const Hexagon*>& path) { // A* implementation // assert path.clear(); // Trivial early out if (&start == &goal) { path.push_back(&start); return true; } OpenSet open; std::set<const Hexagon*> closed; // Allows for reconstruction of the path at the end. std::unordered_map<const Hexagon*, const Hexagon*> parents; OpenSetEntry startEntry = {&start, 0, heuristics(start, goal)}; open.push(startEntry); while( !open.empty() ) { OpenSetEntry currentEntry = open.top(); if (currentEntry.m_hex == &goal) { reconstructPath(start, goal, parents, path); return true; } open.pop(); closed.insert(currentEntry.m_hex); for (int i = 0 ; i < 6 ; ++i) { const Hexagon* neighbor = currentEntry.m_hex->m_neighbors[i]; if (neighbor) { auto neighborPosClosed = closed.find(neighbor); // If neighbor is not in closed if (neighborPosClosed == closed.end()) { OpenSetEntry neighborEntry = { neighbor, currentEntry.m_pastCost + 1, heuristics(*neighbor,goal) }; if (open.pushOrReplace(neighborEntry)) { parents.insert(std::pair<const Hexagon*, const Hexagon*>(neighbor, currentEntry.m_hex)); } } } } } return false; }
int min(AntiChess ob,int alpha,int beta,int depth,Move move){ int minimum = INFINITY; int temp; int i; obCorrection(ob); playMove(ob,move); if (depth == MaxDepth){ return heuristics(ob); } for (i=0 ; i < ob.totalMoves ; i++){ if (temp = max(ob,alpha,beta,depth+1,ob.validMoves[i]) < beta){ beta = temp; } if (alpha > beta) return beta; } return beta; }
int OepFinder::IsCurrentInOEP(INS ins){ int writeItemIndex=-1; BOOL checkWxorX = TRUE; ADDRINT curEip = INS_Address(ins); BOOL isLib = filterLib(curEip); if(isLib){ return INLIB; // we are inside a library } if(isWriteINS(ins)){ handleWrite(ins); } if(checkWxorX){ writeItemIndex = getWxorXindex(ins); if(writeItemIndex != -1 ){ checkWxorX = FALSE; BOOL isOEP = heuristics(ins); if(isOEP){ return FOUND_OEP; } return NOT_FOUND_OEP; } } else{ if(checkEIPInWriteitem(curEip , writeItemIndex)){ return EIP_IN_CUR_WITEM; } else checkWxorX = TRUE; return EIP_NOT_IN_CUR_WITEM; } }