Changeset View
Changeset View
Standalone View
Standalone View
patsolve/abstract_fc_solve_solver.cpp
Show First 20 Lines • Show All 49 Lines • ▼ Show 20 Line(s) | |||||
50 | /* Get the possible moves from a position, and store them in Possible[]. */ | 50 | /* Get the possible moves from a position, and store them in Possible[]. */ | ||
51 | SolverInterface::ExitStatus FcSolveSolver::patsolve( int _max_positions ) | 51 | SolverInterface::ExitStatus FcSolveSolver::patsolve( int _max_positions ) | ||
52 | { | 52 | { | ||
53 | int current_iters_count; | 53 | int current_iters_count; | ||
54 | max_positions = (_max_positions < 0) ? default_max_positions : _max_positions; | 54 | max_positions = (_max_positions < 0) ? default_max_positions : _max_positions; | ||
55 | 55 | | |||
56 | init(); | 56 | init(); | ||
57 | 57 | | |||
58 | // call free once the function ends. ### Replace this mess with QScopeGuard once we can use Qt 5.12 | ||||
59 | auto cleanup = [this](){this->free();}; | ||||
60 | using CleanupFunction = decltype (cleanup); | ||||
61 | struct CleanupHandler { | ||||
62 | CleanupHandler(CleanupFunction cleanup) : m_cleanup(std::move(cleanup)) {} | ||||
63 | ~CleanupHandler() { m_cleanup();} | ||||
64 | | ||||
65 | CleanupFunction m_cleanup; | ||||
66 | } cleaner(cleanup); | ||||
67 | | ||||
58 | int no_use = 0; | 68 | int no_use = 0; | ||
59 | int num_moves = 0; | 69 | int num_moves = 0; | ||
60 | const auto get_possible_moves__ret = get_possible_moves(&no_use, &num_moves); | 70 | const auto get_possible_moves__ret = get_possible_moves(&no_use, &num_moves); | ||
61 | Q_ASSERT( num_moves == get_possible_moves__ret ); | 71 | Q_ASSERT( num_moves == get_possible_moves__ret ); | ||
62 | Q_ASSERT( m_firstMoves.count() == 0 ); | 72 | Q_ASSERT( m_firstMoves.count() == 0 ); | ||
63 | for (int j = 0; j < num_moves; ++j) | 73 | for (int j = 0; j < num_moves; ++j) | ||
64 | m_firstMoves.append( Possible[j] ); | 74 | m_firstMoves.append( Possible[j] ); | ||
65 | // Sometimes the solver is invoked with a small maximal iterations | 75 | // Sometimes the solver is invoked with a small maximal iterations | ||
▲ Show 20 Lines • Show All 204 Lines • Show Last 20 Lines |