qcross/libqnono/cnonogramsolver.cpp

38 lines
815 B
C++

#include "cnonogramsolver.h"
#include "cnonogram.h"
#include "nonogramsolver.h"
#include <QString>
#include <QDebug>
namespace libqnono {
CNonogramSolver::CNonogramSolver(QObject * parent)
: QObject(parent), m_Nonogram(0) {
}
CNonogramSolver::~CNonogramSolver() {
}
void CNonogramSolver::setNonogram(CNonogram * nonogram) {
m_Nonogram = nonogram;
}
bool CNonogramSolver::solve() {
if (!m_Nonogram) return false;
QList<NonogramImage> solutions = libqnono::solve(m_Nonogram->numbers());
if (!solutions.empty()) {
NonogramImage &sol(solutions.first());
for (int i = 0; i < m_Nonogram->width(); ++i) {
for (int j = 0; j < m_Nonogram->height(); ++j) {
emit markRequested(i, j, sol.pixel(i, j) ? CMT_MARKED : CMT_CROSSED);
}
}
return TRUE;
}
return FALSE;
}
}