2010-06-16 12:53:56 +00:00
|
|
|
#include "cnonogramsolver.h"
|
|
|
|
#include "cnonogram.h"
|
|
|
|
|
2012-04-19 15:30:54 +00:00
|
|
|
#include "nonogramsolver.h"
|
|
|
|
|
2011-12-21 11:49:33 +00:00
|
|
|
#include <QString>
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
namespace libqnono {
|
2012-04-19 15:30:54 +00:00
|
|
|
CNonogramSolver::CNonogramSolver(QObject * parent)
|
|
|
|
: QObject(parent), m_Nonogram(0) {
|
2011-12-21 11:49:33 +00:00
|
|
|
}
|
|
|
|
|
2012-04-11 13:01:54 +00:00
|
|
|
CNonogramSolver::~CNonogramSolver() {
|
2011-12-21 11:49:33 +00:00
|
|
|
}
|
|
|
|
|
2012-04-11 13:01:54 +00:00
|
|
|
void CNonogramSolver::setNonogram(CNonogram * nonogram) {
|
|
|
|
m_Nonogram = nonogram;
|
2011-12-21 11:49:33 +00:00
|
|
|
}
|
|
|
|
|
2012-04-11 13:01:54 +00:00
|
|
|
bool CNonogramSolver::solve() {
|
|
|
|
if (!m_Nonogram) return false;
|
|
|
|
|
2012-04-19 15:30:54 +00:00
|
|
|
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);
|
2011-12-21 11:49:33 +00:00
|
|
|
}
|
|
|
|
}
|
2012-04-19 15:30:54 +00:00
|
|
|
return TRUE;
|
2011-12-21 11:49:33 +00:00
|
|
|
}
|
|
|
|
|
2012-04-11 13:01:54 +00:00
|
|
|
return FALSE;
|
2010-06-16 12:53:56 +00:00
|
|
|
}
|
|
|
|
}
|