void CPuzzle::OnLButtonUp(HWND hWindow, int x, int y, UINT keyFlags) /***********************************************************************/ { if ( !m_bTrack ) return; ReleaseCapture(); m_bTrack = FALSE; if (!m_pDib) return; if (m_bInRect && m_iSelect >= 0) { int iColWidth = m_pDib->GetWidth() / m_iCols; int iRowHeight = m_pDib->GetHeight() / m_iRows; int iCol = x / iColWidth; int iRow = y / iRowHeight; int iNewSpot = (iRow * m_iCols) + iCol; int temp = m_iMap[m_iSelect]; m_iMap[m_iSelect] = m_iMap[iNewSpot]; m_iMap[iNewSpot] = temp; } m_iSelect = -1; if (IsSolved()) PlaySound(IDW_PUZZLESOLVED); else PlaySound(IDW_PUZZLEUP); InvalidateRect(hWindow, NULL, FALSE); }
std::string MotionPlannerInterface::Plan(MilestonePath& path,const HaltingCondition& cond) { path.edges.clear(); bool foundPath = false; Real lastCheckTime = 0, lastCheckValue = 0; Timer timer; for(int iters=0;iters<cond.maxIters;iters++) { Real t=timer.ElapsedTime(); if(t > cond.timeLimit) { if(foundPath) { //get the final path GetSolution(path); } return "timeLimit"; } //check for cost improvements if(foundPath && t > lastCheckTime + cond.costImprovementPeriod) { GetSolution(path); Real len = path.Length(); if(len < cond.costThreshold) return "costThreshold"; if(lastCheckValue - len < cond.costImprovementThreshold) return "costImprovementThreshold"; lastCheckTime = t; lastCheckValue = len; } //do planning, check if a path is found PlanMore(); if(!foundPath) { if(IsSolved()) { foundPath = true; GetSolution(path); if(cond.foundSolution) { return "foundSolution"; } lastCheckTime = t; lastCheckValue = path.Length(); } } } if(foundPath) { //get the final path GetSolution(path); } return "maxIters"; }
void CPuzzle::OnLButtonDown(HWND hWindow, BOOL fDoubleClick, int x, int y, UINT keyFlags) /***********************************************************************/ { if ( SHIFT ) return; if ( m_bTrack ) return; if (IsSolved()) return; SetCapture( hWindow ); m_bTrack = TRUE; if ( GetFocus() != hWindow ) SetFocus( hWindow ); m_bInRect = YES; if (!m_pDib) return; int iColWidth = m_pDib->GetWidth() / m_iCols; int iRowHeight = m_pDib->GetHeight() / m_iRows; int iCol = x / iColWidth; int iRow = y / iRowHeight; m_iSelect = (iRow * m_iCols) + iCol; m_ptSelect.x = iCol * iColWidth; m_ptSelect.y = iRow * iRowHeight; m_ptLast.x = x; m_ptLast.y = y; PlaySound(IDW_PUZZLEDOWN); if (m_bHintMode) { HDC hDC = GetDC(hWindow); DrawHint(m_iSelect, hDC, NULL, NULL); ReleaseDC(hWindow, hDC); } }