Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
KSudoku
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Games
KSudoku
Commits
236dbce9
Commit
236dbce9
authored
Apr 29, 2010
by
Johannes Bergmeier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- Removed deprecated class SKSolver
- Using SKGraph directly now svn path=/trunk/KDE/kdegames/ksudoku/; revision=1120693
parent
3b1e5dba
Changes
18
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
106 additions
and
295 deletions
+106
-295
src/gui/gamevariants.cpp
src/gui/gamevariants.cpp
+28
-34
src/gui/gamevariants.h
src/gui/gamevariants.h
+4
-4
src/gui/ksudoku.cpp
src/gui/ksudoku.cpp
+1
-0
src/gui/ksudokugame.cpp
src/gui/ksudokugame.cpp
+1
-10
src/gui/ksudokugame.h
src/gui/ksudokugame.h
+0
-3
src/gui/serializer.cpp
src/gui/serializer.cpp
+31
-69
src/gui/serializer.h
src/gui/serializer.h
+4
-5
src/gui/views/ksview.cpp
src/gui/views/ksview.cpp
+0
-1
src/gui/views/roxdokuview.h
src/gui/views/roxdokuview.h
+0
-1
src/gui/views/view2d.cpp
src/gui/views/view2d.cpp
+4
-5
src/logic/CMakeLists.txt
src/logic/CMakeLists.txt
+0
-1
src/logic/puzzle.cpp
src/logic/puzzle.cpp
+13
-13
src/logic/puzzle.h
src/logic/puzzle.h
+19
-24
src/logic/skgraph.cpp
src/logic/skgraph.cpp
+1
-2
src/logic/skgraph.h
src/logic/skgraph.h
+0
-4
src/logic/sksolver.cpp
src/logic/sksolver.cpp
+0
-53
src/logic/sksolver.h
src/logic/sksolver.h
+0
-64
src/main.cpp
src/main.cpp
+0
-2
No files found.
src/gui/gamevariants.cpp
View file @
236dbce9
...
...
@@ -229,7 +229,7 @@ bool GameVariantDelegate::eventFilter(QObject* watched, QEvent* event) {
///////////////////////////////////////////////////////////////////////////////
SudokuGame
::
SudokuGame
(
const
QString
&
name
,
uint
order
,
GameVariantCollection
*
collection
)
:
GameVariant
(
name
,
collection
),
m_order
(
order
),
m_
solver
(
0
)
:
GameVariant
(
name
,
collection
),
m_order
(
order
),
m_
graph
(
0
)
{
// TODO load from settings
m_symmetry
=
0
;
...
...
@@ -249,26 +249,24 @@ bool SudokuGame::canStartEmpty() const {
}
Game
SudokuGame
::
startEmpty
()
const
{
if
(
!
m_solver
)
{
GraphSudoku
*
graph
=
new
GraphSudoku
(
m_order
);
graph
->
init
();
m_solver
=
new
SKSolver
(
graph
);
if
(
!
m_graph
)
{
m_graph
=
new
GraphSudoku
(
m_order
);
m_graph
->
init
();
}
Puzzle
*
puzzle
=
new
Puzzle
(
m_
solver
,
false
);
Puzzle
*
puzzle
=
new
Puzzle
(
m_
graph
,
false
);
puzzle
->
init
();
return
Game
(
puzzle
);
}
Game
SudokuGame
::
createGame
(
int
difficulty
)
const
{
if
(
!
m_solver
)
{
GraphSudoku
*
graph
=
new
GraphSudoku
(
m_order
);
graph
->
init
();
m_solver
=
new
SKSolver
(
graph
);
if
(
!
m_graph
)
{
m_graph
=
new
GraphSudoku
(
m_order
);
m_graph
->
init
();
}
Puzzle
*
puzzle
=
new
Puzzle
(
m_
solver
,
true
);
Puzzle
*
puzzle
=
new
Puzzle
(
m_
graph
,
true
);
puzzle
->
init
(
difficulty
,
m_symmetry
);
return
Game
(
puzzle
);
...
...
@@ -284,7 +282,7 @@ KsView* SudokuGame::createView(const Game& /*game*/) const {
///////////////////////////////////////////////////////////////////////////////
RoxdokuGame
::
RoxdokuGame
(
const
QString
&
name
,
uint
order
,
GameVariantCollection
*
collection
)
:
GameVariant
(
name
,
collection
),
m_order
(
order
),
m_
solver
(
0
)
:
GameVariant
(
name
,
collection
),
m_order
(
order
),
m_
graph
(
0
)
{
// TODO load from settings
m_symmetry
=
0
;
...
...
@@ -304,26 +302,24 @@ bool RoxdokuGame::canStartEmpty() const {
}
Game
RoxdokuGame
::
startEmpty
()
const
{
if
(
!
m_solver
)
{
GraphRoxdoku
*
graph
=
new
GraphRoxdoku
(
m_order
);
graph
->
init
();
m_solver
=
new
SKSolver
(
graph
);
if
(
!
m_graph
)
{
m_graph
=
new
GraphRoxdoku
(
m_order
);
m_graph
->
init
();
}
Puzzle
*
puzzle
=
new
Puzzle
(
m_
solver
,
false
);
Puzzle
*
puzzle
=
new
Puzzle
(
m_
graph
,
false
);
puzzle
->
init
();
return
Game
(
puzzle
);
}
Game
RoxdokuGame
::
createGame
(
int
difficulty
)
const
{
if
(
!
m_solver
)
{
GraphRoxdoku
*
graph
=
new
GraphRoxdoku
(
m_order
);
graph
->
init
();
m_solver
=
new
SKSolver
(
graph
);
if
(
!
m_graph
)
{
m_graph
=
new
GraphRoxdoku
(
m_order
);
m_graph
->
init
();
}
Puzzle
*
puzzle
=
new
Puzzle
(
m_
solver
,
true
);
Puzzle
*
puzzle
=
new
Puzzle
(
m_
graph
,
true
);
puzzle
->
init
(
difficulty
,
m_symmetry
);
return
Game
(
puzzle
);
...
...
@@ -340,7 +336,7 @@ KsView* RoxdokuGame::createView(const Game& /*game*/) const {
CustomGame
::
CustomGame
(
const
QString
&
name
,
const
KUrl
&
url
,
GameVariantCollection
*
collection
)
:
GameVariant
(
name
,
collection
),
m_url
(
url
),
m_
solver
(
0
)
:
GameVariant
(
name
,
collection
),
m_url
(
url
),
m_
graph
(
0
)
{
}
bool
CustomGame
::
canConfigure
()
const
{
...
...
@@ -356,26 +352,24 @@ bool CustomGame::canStartEmpty() const {
}
Game
CustomGame
::
startEmpty
()
const
{
if
(
!
m_solver
)
{
m_solver
=
ksudoku
::
Serializer
::
loadCustomShape
(
m_url
,
0
,
0
);
if
(
!
m_solver
)
return
Game
();
if
(
!
m_graph
)
{
m_graph
=
ksudoku
::
Serializer
::
loadCustomShape
(
m_url
,
0
,
0
);
if
(
!
m_graph
)
return
Game
();
}
Puzzle
*
puzzle
=
new
Puzzle
(
m_
solver
,
false
);
Puzzle
*
puzzle
=
new
Puzzle
(
m_
graph
,
false
);
puzzle
->
init
();
return
Game
(
puzzle
);
}
Game
CustomGame
::
createGame
(
int
difficulty
)
const
{
if
(
!
m_solver
)
{
m_solver
=
ksudoku
::
Serializer
::
loadCustomShape
(
m_url
,
0
,
0
);
if
(
!
m_solver
)
return
Game
();
if
(
!
m_graph
)
{
m_graph
=
ksudoku
::
Serializer
::
loadCustomShape
(
m_url
,
0
,
0
);
if
(
!
m_graph
)
return
Game
();
}
Puzzle
*
puzzle
=
new
Puzzle
(
m_
solver
,
true
);
Puzzle
*
puzzle
=
new
Puzzle
(
m_
graph
,
true
);
puzzle
->
init
(
difficulty
,
1
);
return
Game
(
puzzle
);
...
...
src/gui/gamevariants.h
View file @
236dbce9
...
...
@@ -26,7 +26,7 @@
#include <QItemDelegate>
#include <QAbstractListModel>
class
SK
Solver
;
class
SK
Graph
;
namespace
ksudoku
{
class
KsView
;
...
...
@@ -138,7 +138,7 @@ private:
uint
m_order
;
uint
m_symmetry
;
mutable
SK
Solver
*
m_solver
;
mutable
SK
Graph
*
m_graph
;
};
class
RoxdokuGame
:
public
GameVariant
{
...
...
@@ -157,7 +157,7 @@ private:
uint
m_order
;
uint
m_symmetry
;
mutable
SK
Solver
*
m_solver
;
mutable
SK
Graph
*
m_graph
;
};
class
CustomGame
:
public
GameVariant
{
...
...
@@ -174,7 +174,7 @@ public:
private:
KUrl
m_url
;
mutable
SK
Solver
*
m_solver
;
mutable
SK
Graph
*
m_graph
;
};
}
...
...
src/gui/ksudoku.cpp
View file @
236dbce9
...
...
@@ -65,6 +65,7 @@
#include "settings.h"
#include "config.h"
using
namespace
ksudoku
;
void
KSudoku
::
onCompleted
(
bool
isCorrect
,
const
QTime
&
required
,
bool
withHelp
)
{
if
(
!
isCorrect
)
{
...
...
src/gui/ksudokugame.cpp
View file @
236dbce9
...
...
@@ -21,8 +21,6 @@
#include "ksudokugame.h"
#include "sksolver.h"
#include "puzzle.h"
#include "history.h"
...
...
@@ -219,13 +217,6 @@ Puzzle* Game::puzzle() const {
return
m_private
->
puzzle
;
}
bool
Game
::
hasSolver
()
{
if
(
!
m_private
)
return
0
;
return
m_private
->
puzzle
->
hasSolver
();
}
void
Game
::
setUrl
(
const
KUrl
&
url
)
{
if
(
!
m_private
)
return
;
...
...
@@ -351,7 +342,7 @@ bool Game::giveHint() {
// i = RANDOM(size());
// } while (m_private->isGiven(i));
int
start
=
RANDOM
(
size
()
);
int
start
=
rand
()
%
size
(
);
int
i
;
for
(
i
=
start
;
i
<
size
();
++
i
)
if
(
!
given
(
i
))
...
...
src/gui/ksudokugame.h
View file @
236dbce9
...
...
@@ -123,9 +123,6 @@ public:
Game
&
operator
=
(
const
Game
&
game
);
public:
bool
hasSolver
();
int
order
()
const
;
bool
marker
(
int
index
,
int
value
)
const
;
...
...
src/gui/serializer.cpp
View file @
236dbce9
...
...
@@ -20,7 +20,6 @@
***************************************************************************/
#include "serializer.h"
//#include "sksolver.h"
#include "ksudokugame.h"
#include "puzzle.h"
...
...
@@ -86,8 +85,8 @@ Game Serializer::deserializeGame(QDomElement element) {
}
Puzzle
*
Serializer
::
deserializePuzzle
(
QDomElement
element
)
{
bool
has
Solver
=
false
;
SK
Solver
*
solver
=
0
;
bool
has
Graph
=
false
;
SK
Graph
*
graph
=
0
;
bool
hasValues
=
false
;
QString
valuesStr
;
bool
hasSolution
=
false
;
...
...
@@ -98,16 +97,16 @@ Puzzle* Serializer::deserializePuzzle(QDomElement element) {
while
(
!
child
.
isNull
())
{
if
(
child
.
isElement
())
{
if
(
child
.
nodeName
()
==
"graph"
)
{
if
(
has
Solver
)
{
delete
solver
;
if
(
has
Graph
)
{
delete
graph
;
return
0
;
}
solver
=
deserializeGraph
(
child
.
toElement
());
has
Solver
=
true
;
graph
=
deserializeGraph
(
child
.
toElement
());
has
Graph
=
true
;
}
else
if
(
child
.
nodeName
()
==
"values"
)
{
if
(
hasValues
)
{
delete
solver
;
delete
graph
;
return
0
;
}
...
...
@@ -116,7 +115,7 @@ Puzzle* Serializer::deserializePuzzle(QDomElement element) {
}
else
if
(
child
.
nodeName
()
==
"solution"
)
{
// TODO remove deserialization of solution, it is no longer required
if
(
hasSolution
)
{
delete
solver
;
delete
graph
;
return
0
;
}
...
...
@@ -127,30 +126,30 @@ Puzzle* Serializer::deserializePuzzle(QDomElement element) {
child
=
child
.
nextSibling
();
}
if
(
!
solver
)
return
0
;
if
(
valuesStr
.
length
()
!=
solver
->
g
->
size
())
{
delete
solver
;
if
(
!
graph
)
return
0
;
if
(
valuesStr
.
length
()
!=
graph
->
size
())
{
delete
graph
;
return
0
;
}
// TODO remove deserialization of solution, it is no longer required
if
(
solutionStr
.
length
()
!=
0
&&
solutionStr
.
length
()
!=
solver
->
g
->
size
())
{
delete
solver
;
if
(
solutionStr
.
length
()
!=
0
&&
solutionStr
.
length
()
!=
graph
->
size
())
{
delete
graph
;
return
0
;
}
Puzzle
*
puzzle
=
new
Puzzle
(
solver
,
hasSolution
);
Puzzle
*
puzzle
=
new
Puzzle
(
graph
,
hasSolution
);
QByteArray
values
;
values
.
resize
(
solver
->
g
->
size
());
for
(
int
i
=
0
;
i
<
solver
->
g
->
size
();
++
i
)
{
values
.
resize
(
graph
->
size
());
for
(
int
i
=
0
;
i
<
graph
->
size
();
++
i
)
{
values
[
i
]
=
Symbols
::
ioSymbol2Value
(
valuesStr
[
i
]);
}
// TODO remove deserialization of solution, it is no longer required
QByteArray
solution
;
if
(
solutionStr
.
length
()
!=
0
)
{
solution
.
resize
(
solver
->
g
->
size
());
for
(
int
i
=
0
;
i
<
solver
->
g
->
size
();
++
i
)
{
solution
.
resize
(
graph
->
size
());
for
(
int
i
=
0
;
i
<
graph
->
size
();
++
i
)
{
solution
[
i
]
=
Symbols
::
ioSymbol2Value
(
solutionStr
[
i
]);
}
}
...
...
@@ -173,7 +172,7 @@ static int readInt(QDomElement element, const QString& name, int* err)
return
num
;
}
SK
Solver
*
Serializer
::
deserializeGraph
(
QDomElement
element
)
{
SK
Graph
*
Serializer
::
deserializeGraph
(
QDomElement
element
)
{
bool
noFailure
=
true
;
QString
orderStr
=
element
.
attribute
(
"order"
);
...
...
@@ -191,13 +190,11 @@ SKSolver* Serializer::deserializeGraph(QDomElement element) {
if
(
type
==
"sudoku"
)
{
GraphSudoku
*
graph
=
new
GraphSudoku
(
order
);
graph
->
init
();
SKSolver
*
solver
=
new
SKSolver
(
graph
);
return
solver
;
return
graph
;
}
else
if
(
type
==
"roxdoku"
)
{
GraphRoxdoku
*
graph
=
new
GraphRoxdoku
(
order
);
graph
->
init
();
SKSolver
*
solver
=
new
SKSolver
(
graph
);
return
solver
;
return
graph
;
}
else
if
(
type
==
"custom"
)
{
int
err
=
0
;
int
ncliques
=
readInt
(
element
,
"ncliques"
,
&
err
);
...
...
@@ -224,12 +221,10 @@ SKSolver* Serializer::deserializeGraph(QDomElement element) {
child
=
child
.
nextSibling
();
}
GraphCustom
*
gc
=
new
GraphCustom
();
gc
->
init
(
name
.
toLatin1
(),
order
,
sizeX
,
sizeY
,
sizeZ
,
ncliques
,
cliques
.
toLatin1
());
if
(
gc
->
valid
==
false
)
return
0
;
SKSolver
*
solver
=
new
SKSolver
(
gc
);
return
solver
;
GraphCustom
*
graph
=
new
GraphCustom
();
graph
->
init
(
name
.
toLatin1
(),
order
,
sizeX
,
sizeY
,
sizeZ
,
ncliques
,
cliques
.
toLatin1
());
if
(
graph
->
valid
==
false
)
return
0
;
return
graph
;
}
return
0
;
...
...
@@ -294,7 +289,7 @@ HistoryEvent Serializer::deserializeComplexHistoryEvent(QDomElement /*element*/)
return
HistoryEvent
();
}
SK
Solver
*
Serializer
::
loadCustomShape
(
const
KUrl
&
url
,
QWidget
*
window
,
QString
*
errorMsg
)
{
SK
Graph
*
Serializer
::
loadCustomShape
(
const
KUrl
&
url
,
QWidget
*
window
,
QString
*
errorMsg
)
{
if
(
url
.
isEmpty
()
)
return
0
;
QString
tmpFile
;
bool
success
=
false
;
...
...
@@ -374,24 +369,6 @@ Game Serializer::load(const KUrl& url, QWidget* window, QString *errorMsg) {
child
=
child
.
nextSibling
();
}
// SKSolver* sk = (SKSolver*) game.puzzle()->solver();
// QString name = ((GraphCustom*)sk->g)->name;
// KSudoku* p = (KSudoku*) window;
// if(!p->shapes().contains(name))
// {
// KStandardDirs myStdDir;
// const QString destDir = myStdDir.saveLocation("data", /* TODO PORT kapp->instanceName() +*/ "ksudoku/", true);
// KStandardDirs::makeDir(destDir);
//
// QString path = destDir + name + ".xml";
// KUrl url;
// url.setPath(path);
//
// Serializer::storeCustomShape( sk, url ,window );
// p->updateShapesList();
//
// }
return
game
;
}
...
...
@@ -409,7 +386,7 @@ bool Serializer::serializePuzzle(QDomElement& parent, const Puzzle* puzzle) {
QDomDocument
doc
=
parent
.
ownerDocument
();
QDomElement
element
=
doc
.
createElement
(
"puzzle"
);
serializeGraph
(
element
,
puzzle
->
solver
());
serializeGraph
(
element
,
puzzle
->
graph
());
for
(
int
i
=
0
;
i
<
puzzle
->
size
();
++
i
)
{
contentStr
+=
Symbols
::
ioValue2Symbol
(
puzzle
->
value
(
i
));
...
...
@@ -433,16 +410,16 @@ bool Serializer::serializePuzzle(QDomElement& parent, const Puzzle* puzzle) {
return
true
;
}
bool
Serializer
::
serializeGraph
(
QDomElement
&
parent
,
const
SKSolver
*
puzzle
)
{
bool
Serializer
::
serializeGraph
(
QDomElement
&
parent
,
const
SKGraph
*
graph
)
{
QDomElement
element
=
parent
.
ownerDocument
().
createElement
(
"graph"
);
element
.
setAttribute
(
"order"
,
puzzle
->
g
->
order
());
element
.
setAttribute
(
"order"
,
graph
->
order
());
//element.setAttribute("size", puzzle->size());
GameType
type
=
puzzle
->
g
->
type
();
GameType
type
=
graph
->
type
();
element
.
setAttribute
(
"type"
,
(
type
==
TypeSudoku
)
?
"sudoku"
:
(
type
==
TypeRoxdoku
)
?
"roxdoku"
:
"custom"
);
if
(
type
==
TypeCustom
)
{
GraphCustom
*
g
=
(
GraphCustom
*
)
puzzle
->
g
;
GraphCustom
*
g
=
(
GraphCustom
*
)
graph
;
element
.
setAttribute
(
"ncliques"
,
(
int
)
g
->
cliques
.
size
());
element
.
setAttribute
(
"name"
,
g
->
name
);
element
.
setAttribute
(
"sizeX"
,
g
->
sizeX
());
...
...
@@ -567,19 +544,4 @@ bool Serializer::store(const Game& game, const KUrl& url, QWidget* window) {
return
true
;
}
bool
Serializer
::
storeCustomShape
(
const
SKSolver
*
solver
,
const
KUrl
&
/*url*/
,
QWidget
*
/*window*/
)
{
QDomDocument
doc
(
"ksudoku-graph"
);
QDomElement
root
=
doc
.
createElement
(
"ksudoku-graph"
);
doc
.
appendChild
(
root
);
serializeGraph
(
root
,
solver
);
KTemporaryFile
tmp
;
//(*tmp.textStream()) << doc.toString(); //TODO PORT
tmp
.
close
();
//KIO::NetAccess::upload(tmp.name(), url, window); //TODO PORT
//tmp.unlink(); //TODO PORT
return
true
;
}
}
src/gui/serializer.h
View file @
236dbce9
...
...
@@ -24,7 +24,7 @@
#include <QList>
class
SK
Solver
;
class
SK
Graph
;
class
QDomElement
;
class
KUrl
;
class
QWidget
;
...
...
@@ -39,23 +39,22 @@ class Serializer {
public:
static
Game
deserializeGame
(
QDomElement
element
);
static
Puzzle
*
deserializePuzzle
(
QDomElement
element
)
;
static
SK
Solver
*
deserializeGraph
(
QDomElement
element
);
static
SK
Graph
*
deserializeGraph
(
QDomElement
element
);
static
QList
<
HistoryEvent
>
deserializeHistory
(
QDomElement
element
);
static
HistoryEvent
deserializeSimpleHistoryEvent
(
QDomElement
element
);
static
HistoryEvent
deserializeComplexHistoryEvent
(
QDomElement
element
);
static
Game
load
(
const
KUrl
&
url
,
QWidget
*
window
,
QString
*
errorMsg
=
0
);
static
SK
Solver
*
loadCustomShape
(
const
KUrl
&
url
,
QWidget
*
window
,
QString
*
errorMsg
=
0
);
static
SK
Graph
*
loadCustomShape
(
const
KUrl
&
url
,
QWidget
*
window
,
QString
*
errorMsg
=
0
);
static
bool
serializeGame
(
QDomElement
&
parent
,
const
Game
&
game
);
static
bool
serializePuzzle
(
QDomElement
&
parent
,
const
Puzzle
*
puzzle
);
static
bool
serializeGraph
(
QDomElement
&
parent
,
const
SK
Solver
*
solver
);
static
bool
serializeGraph
(
QDomElement
&
parent
,
const
SK
Graph
*
graph
);
static
bool
serializeHistory
(
QDomElement
&
parent
,
const
Game
&
game
);
static
bool
serializeHistoryEvent
(
QDomElement
&
parent
,
const
HistoryEvent
&
event
);
static
bool
store
(
const
Game
&
game
,
const
KUrl
&
url
,
QWidget
*
window
);
static
bool
storeCustomShape
(
const
SKSolver
*
solver
,
const
KUrl
&
url
,
QWidget
*
window
);
};
}
...
...
src/gui/views/ksview.cpp
View file @
236dbce9
...
...
@@ -29,7 +29,6 @@
#include "ksview.moc"
#include "sksolver.h"
#include "puzzle.h"
#ifdef OPENGL_SUPPORT
...
...
src/gui/views/roxdokuview.h
View file @
236dbce9
...
...
@@ -29,7 +29,6 @@
//Added by qt3to4:
#include <QWheelEvent>
#include <QMouseEvent>
#include "sksolver.h"
#include "ArcBall.h"
#include "ksudokugame.h"
...
...
src/gui/views/view2d.cpp
View file @
236dbce9
...
...
@@ -29,7 +29,6 @@
#include <kdebug.h>
#include "sksolver.h"
#include "puzzle.h"
#include "gameactions.h"
...
...
@@ -366,11 +365,11 @@ void View2DScene::init(const Game& game) {
m_cellLayer
->
setHandlesChildEvents
(
false
);
addItem
(
m_cellLayer
);
SKGraph
*
g
=
m_game
.
puzzle
()
->
solver
()
->
g
;
SKGraph
*
g
=
m_game
.
puzzle
()
->
graph
()
;
m_cells
.
resize
(
m_game
.
size
());
m_cursorPos
=
-
1
;
for
(
int
i
=
0
;
i
<
m_game
.
size
();
++
i
)
{
bool
notConnectedNode
=
((
GraphCustom
*
)
m_game
.
puzzle
()
->
solver
()
->
g
)
->
optimized_d
[
i
]
==
0
;
bool
notConnectedNode
=
((
GraphCustom
*
)
m_game
.
puzzle
()
->
graph
()
)
->
optimized_d
[
i
]
==
0
;
if
(
notConnectedNode
)
{
m_cells
[
i
]
=
0
;
continue
;
...
...
@@ -416,7 +415,7 @@ void View2DScene::init(const Game& game) {
void
View2DScene
::
setSceneSize
(
const
QSize
&
size
)
{
m_background
->
setPixmap
(
Renderer
::
instance
()
->
renderBackground
(
size
));
SKGraph
*
g
=
m_game
.
puzzle
()
->
solver
()
->
g
;
SKGraph
*
g
=
m_game
.
puzzle
()
->
graph
()
;
setSceneRect
(
QRectF
(
0
,
0
,
size
.
width
(),
size
.
height
()));
int
width
=
size
.
width
()
/
(
g
->
sizeX
()
+
1
);
...
...
@@ -558,7 +557,7 @@ void View2DScene::flipMarkValue(int value, int cell) {
}
void
View2DScene
::
moveCursor
(
int
dx
,
int
dy
)
{
SKGraph
*
g
=
m_game
.
puzzle
()
->
solver
()
->
g
;
SKGraph
*
g
=
m_game
.
puzzle
()
->
graph
()
;
QPoint
oldPos
=
m_cells
[
m_cursorPos
]
->
pos
();
QPoint
relPos
;
int
newCursorPos
=
-
1
;
...
...
src/logic/CMakeLists.txt
View file @
236dbce9
set
(
ksudoku_logic_SRCS
skgraph.cpp
sksolver.cpp
puzzle.cpp
)
...
...
src/logic/puzzle.cpp
View file @
236dbce9
...
...
@@ -29,23 +29,23 @@
namespace
ksudoku
{
Puzzle
::
Puzzle
(
SK
Solver
*
solver
,
bool
withSolution
)
Puzzle
::
Puzzle
(
SK
Graph
*
graph
,
bool
withSolution
)
:
m_withSolution
(
withSolution
)
,
m_
solver
(
solver
)
,
m_
graph
(
graph
)
,
m_difficulty
(
0
)
,
m_symmetry
(
0
)
,
m_initialized
(
false
)
{
}
int
Puzzle
::
value
(
int
x
,
int
y
,
int
z
)
const
{
Item
*
item
=
m_
solver
->
g
->
board
()
->
itemAt
(
x
,
y
,
z
);
Item
*
item
=
m_
graph
->
board
()
->
itemAt
(
x
,
y
,
z
);
if
(
item
&&
m_puzzle2
.
ruleset
())
return
static_cast
<
ChoiceItem
*>
(
item
)
->
value
(
&
m_puzzle2
);
return
0
;
}
int
Puzzle
::
solution
(
int
x
,
int
y
,
int
z
)
const
{
Item
*
item
=
m_
solver
->
g
->
board
()
->
itemAt
(
x
,
y
,
z
);
Item
*
item
=
m_
graph
->
board
()
->
itemAt
(
x
,
y
,
z
);
if
(
item
&&
m_solution2
.
ruleset
())
return
static_cast
<
ChoiceItem
*>
(
item
)
->
value
(
&
m_solution2
);
return
0
;
...
...
@@ -57,14 +57,14 @@ bool Puzzle::init() {
if
(
m_withSolution
)
return
false
;
m_puzzle2
=
Problem
(
m_
solver
->
g
->
rulset
());
m_puzzle2
=
Problem
(
m_
graph
->
rulset
());
return
true
;
}
bool
Puzzle
::
createPartial
(
Solver
*
solver
)
{
// TODO after finding a solution try to find simpler ones
const
ItemBoard
*
board
=
m_
solver
->
g
->
board
();
const
ItemBoard
*
board
=
m_
graph
->
board
();
for
(;;)
{
ChoiceItem
*
choiceItem
;
for
(;;)
{
...
...
@@ -117,7 +117,7 @@ bool Puzzle::init(int difficulty, int symmetry) {
if
(
m_initialized
)
return
false
;
Solver
solver
;
solver
.
setLimit
(
2
);
solver
.
loadEmpty
(
m_
solver
->
g
->
rulset
());
solver
.
loadEmpty
(
m_
graph
->
rulset
());
if
(
createPartial
(
&
solver
))
{
return
true
;
...
...
@@ -129,12 +129,12 @@ bool Puzzle::init(int difficulty, int symmetry) {
int
Puzzle
::
init
(
const
QByteArray
&
values
)
{
if
(
m_initialized
)
return
-
1
;
m_puzzle2
=
Problem
(
m_
solver
->
g
->
rulset
());
for
(
int
x
=
0
;
x
<
m_
solver
->
g
->
sizeX
();
++
x
)
{
for
(
int
y
=
0
;
y
<
m_
solver
->
g
->
sizeY
();
++
y
)
{
for
(
int
z
=
0
;
z
<
m_
solver
->
g
->
sizeZ
();
++
z
)
{
int
value
=
values
[
m_
solver
->
g
->
cellIndex
(
x
,
y
,
z
)];
Item
*
item
=
m_
solver
->
g
->
board
()
->
itemAt
(
x
,
y
,
z
);
m_puzzle2
=
Problem
(
m_
graph
->
rulset
());
for
(
int
x
=
0
;
x
<
m_
graph
->
sizeX
();
++
x
)
{
for
(
int
y
=
0
;
y
<
m_
graph
->
sizeY
();
++
y
)
{
for
(
int
z
=
0
;
z
<
m_
graph
->
sizeZ
();
++
z
)
{
int
value
=
values
[
m_
graph
->
cellIndex
(
x
,
y
,
z
)];
Item
*
item
=
m_
graph
->
board
()
->
itemAt
(
x
,
y
,
z
);
if
(
item
&&
value
)
static_cast
<
ChoiceItem
*>
(
item
)
->
setValue
(
&
m_puzzle2
,
value
);
}
...
...
src/logic/puzzle.h
View file @
236dbce9
...
...
@@ -22,8 +22,8 @@
#ifndef _KSUDOKUPUZZLE_H_
#define _KSUDOKUPUZZLE_H_
#include "s
ks
olver.h"
#include "
ksudoku_types
.h"
#include "solver.h"
#include "
skgraph
.h"
class
QChar
;
...
...
@@ -35,8 +35,8 @@ public:
* @param[in] sovler The solver used for this puzzle (the GameType) (not deleted when Puzzle is deleted)
* @param[in] withSolution Whether a the solution for this puzzle should be stored
*/
explicit
Puzzle
(
SK
Solver
*
solver
,
bool
withSolution
=
true
);
explicit
Puzzle
(
SK
Graph
*
graph
,
bool
withSolution
=
true
);
public:
/**
* Creates a puzzle without any content
...
...
@@ -44,9 +44,8 @@ public:
bool
init
();
/**
* Creates a new puzzle based on the solver
* @param[in] difficulty The difficulty of the new game (for valid values see
* code of @c SKSolver)
* @param[in] symmetry The symmetry (for valid values see code of @c SKSolver)
* @param[in] difficulty The difficulty of the new game.
* @param[in] symmetry The symmetry
*/
bool
init
(
int
difficulty
,
int
symmetry
);
/**
...
...
@@ -62,43 +61,39 @@ public:
* Return game type
*/