Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
sudoku_apa
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
btomi96
sudoku_apa
Commits
692df17a
Commit
692df17a
authored
7 years ago
by
Tamas Bunth
Browse files
Options
Downloads
Patches
Plain Diff
Add symbol constraint
parent
d6dd84be
No related branches found
No related tags found
No related merge requests found
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
element.cxx
+15
-0
15 additions, 0 deletions
element.cxx
element.hxx
+4
-1
4 additions, 1 deletion
element.hxx
matrix.cxx
+89
-6
89 additions, 6 deletions
matrix.cxx
matrix.hxx
+4
-1
4 additions, 1 deletion
matrix.hxx
processor.cxx
+13
-9
13 additions, 9 deletions
processor.cxx
processor.hxx
+2
-1
2 additions, 1 deletion
processor.hxx
with
127 additions
and
18 deletions
element.cxx
+
15
−
0
View file @
692df17a
#include
<algorithm>
#include
<algorithm>
#include
<cassert>
#include
<cassert>
#include
<iostream>
#include
"element.hxx"
#include
"element.hxx"
...
@@ -42,3 +43,17 @@ bool Element::nextState()
...
@@ -42,3 +43,17 @@ bool Element::nextState()
dir
=
Direction
::
Ordered
;
dir
=
Direction
::
Ordered
;
return
false
;
return
false
;
}
}
bool
Element
::
contains
(
Symbol
smybol
)
const
{
return
std
::
find
(
symbols_
.
begin
(),
symbols_
.
end
(),
smybol
)
!=
symbols_
.
end
();
}
void
Element
::
print
()
const
{
for
(
auto
symbol
:
symbols_
)
{
std
::
cout
<<
symbol
<<
", "
;
}
std
::
cout
<<
std
::
endl
;
}
This diff is collapsed.
Click to expand it.
element.hxx
+
4
−
1
View file @
692df17a
...
@@ -12,7 +12,6 @@ private:
...
@@ -12,7 +12,6 @@ private:
Alignment
align
=
Alignment
::
Horizontal
;
Alignment
align
=
Alignment
::
Horizontal
;
Direction
dir
=
Direction
::
Ordered
;
Direction
dir
=
Direction
::
Ordered
;
std
::
vector
<
Symbol
>
symbols_
;
std
::
vector
<
Symbol
>
symbols_
;
bool
used_
=
false
;
public:
public:
Element
(
std
::
vector
<
Symbol
>
symbols
);
Element
(
std
::
vector
<
Symbol
>
symbols
);
Element
(
const
Element
&
);
Element
(
const
Element
&
);
...
@@ -24,6 +23,10 @@ public:
...
@@ -24,6 +23,10 @@ public:
Alignment
getAlign
()
const
{
return
align
;
}
Alignment
getAlign
()
const
{
return
align
;
}
Direction
getDir
()
const
{
return
dir
;
}
Direction
getDir
()
const
{
return
dir
;
}
bool
contains
(
Symbol
symbol
)
const
;
void
print
()
const
;
/**
/**
* Sets the Element into a new state. State is determined by the alignment
* Sets the Element into a new state. State is determined by the alignment
* and direction of the Element.
* and direction of the Element.
...
...
This diff is collapsed.
Click to expand it.
matrix.cxx
+
89
−
6
View file @
692df17a
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
#include
"utils.hxx"
#include
"utils.hxx"
#include
"element.hxx"
#include
"element.hxx"
#include
<cassert>
#include
<cassert>
#include
<iostream>
Matrix
::
Matrix
(
std
::
size_t
dim
)
Matrix
::
Matrix
(
std
::
size_t
dim
)
:
board_
{
dim
,
std
::
vector
<
int
>
(
dim
,
0
)}
:
board_
{
dim
,
std
::
vector
<
int
>
(
dim
,
0
)}
...
@@ -12,25 +13,71 @@ bool Matrix::put(const Element& element, const Position& pos)
...
@@ -12,25 +13,71 @@ bool Matrix::put(const Element& element, const Position& pos)
Direction
dir
=
element
.
getDir
();
Direction
dir
=
element
.
getDir
();
Alignment
align
=
element
.
getAlign
();
Alignment
align
=
element
.
getAlign
();
// check if free
// check out of bound
if
((
align
==
Alignment
::
Horizontal
&&
pos
.
y
+
element
.
size
()
>
size
())
||
(
align
==
Alignment
::
Vertical
&&
pos
.
x
+
element
.
size
()
>
size
()))
return
false
;
// check if position not free
for
(
std
::
size_t
i
=
0
;
i
<
element
.
size
();
++
i
)
for
(
std
::
size_t
i
=
0
;
i
<
element
.
size
();
++
i
)
{
{
if
(
align
==
Alignment
::
Horizontal
)
if
(
align
==
Alignment
::
Horizontal
)
{
{
if
(
pos
.
y
+
i
>=
size
()
)
return
false
;
if
(
board_
.
at
(
pos
.
x
).
at
(
pos
.
y
+
i
)
>
0
)
if
(
board_
.
at
(
pos
.
x
).
at
(
pos
.
y
+
i
)
>
0
)
return
false
;
return
false
;
}
}
else
// Alignment::Vertical
else
// Alignment::Vertical
{
{
if
(
pos
.
x
+
i
>=
size
()
)
return
false
;
if
(
board_
.
at
(
pos
.
x
+
i
).
at
(
pos
.
y
)
>
0
)
if
(
board_
.
at
(
pos
.
x
+
i
).
at
(
pos
.
y
)
>
0
)
return
false
;
return
false
;
}
}
}
}
// check symbol collision
if
(
align
==
Alignment
::
Horizontal
)
{
std
::
size_t
x
=
pos
.
x
;
for
(
std
::
size_t
i
=
0
;
i
<
size
();
++
i
)
if
(
element
.
contains
(
at
(
Position
{
x
,
i
})))
return
false
;
if
(
dir
==
Direction
::
Ordered
)
{
for
(
std
::
size_t
i
=
0
;
i
<
size
();
++
i
)
for
(
std
::
size_t
j
=
0
;
j
<
element
.
size
();
j
++
)
if
(
element
.
get
(
j
)
==
at
(
Position
{
i
,
j
+
pos
.
y
}))
return
false
;
}
else
{
for
(
std
::
size_t
i
=
0
;
i
<
size
();
++
i
)
for
(
std
::
size_t
j
=
0
;
j
<
element
.
size
();
j
++
)
if
(
element
.
getReversed
(
j
)
==
at
(
Position
{
i
,
j
+
pos
.
y
}))
return
false
;
}
}
else
if
(
align
==
Alignment
::
Vertical
)
{
std
::
size_t
y
=
pos
.
y
;
for
(
std
::
size_t
i
=
0
;
i
<
size
();
++
i
)
if
(
element
.
contains
(
at
(
Position
{
i
,
y
})))
return
false
;
if
(
dir
==
Direction
::
Ordered
)
{
for
(
std
::
size_t
i
=
0
;
i
<
size
();
++
i
)
for
(
std
::
size_t
j
=
0
;
j
<
element
.
size
();
j
++
)
if
(
element
.
get
(
j
)
==
at
(
Position
{
j
+
pos
.
x
,
i
}))
return
false
;
}
else
{
for
(
std
::
size_t
i
=
0
;
i
<
size
();
++
i
)
for
(
std
::
size_t
j
=
0
;
j
<
element
.
size
();
j
++
)
if
(
element
.
getReversed
(
j
)
==
at
(
Position
{
j
+
pos
.
x
,
i
}))
return
false
;
}
}
// fill in
// fill in
for
(
std
::
size_t
i
=
0
;
i
<
element
.
size
();
++
i
)
for
(
std
::
size_t
i
=
0
;
i
<
element
.
size
();
++
i
)
{
{
...
@@ -53,19 +100,44 @@ bool Matrix::put(const Element& element, const Position& pos)
...
@@ -53,19 +100,44 @@ bool Matrix::put(const Element& element, const Position& pos)
return
true
;
return
true
;
}
}
bool
Matrix
::
putFirst
(
const
Element
&
elem
)
bool
Matrix
::
putFirst
(
const
Element
&
elem
,
Position
&
posIn
)
{
{
for
(
std
::
size_t
i
=
0
;
i
<
board_
.
size
();
++
i
)
for
(
std
::
size_t
i
=
0
;
i
<
board_
.
size
();
++
i
)
for
(
std
::
size_t
j
=
0
;
j
<
board_
.
size
();
++
j
)
for
(
std
::
size_t
j
=
0
;
j
<
board_
.
size
();
++
j
)
{
{
Position
pos
{
i
,
j
};
Position
pos
{
i
,
j
};
if
(
isFree
(
pos
)
)
if
(
isFree
(
pos
)
)
{
posIn
=
pos
;
return
put
(
elem
,
pos
);
return
put
(
elem
,
pos
);
}
}
}
assert
(
false
);
// matrix is full (solved)
assert
(
false
);
// matrix is full (solved)
return
false
;
return
false
;
}
}
void
Matrix
::
free
(
const
Element
&
elem
,
const
Position
&
pos
)
{
Alignment
align
=
elem
.
getAlign
();
if
(
align
==
Alignment
::
Horizontal
)
assert
(
pos
.
y
+
elem
.
size
()
<=
size
());
else
assert
(
pos
.
x
+
elem
.
size
()
<=
size
());
for
(
std
::
size_t
i
=
0
;
i
<
elem
.
size
();
++
i
)
{
if
(
align
==
Alignment
::
Horizontal
)
{
board_
[
pos
.
x
][
pos
.
y
+
i
]
=
0
;
}
else
// Alignment::Vertical
{
board_
[
pos
.
x
+
i
][
pos
.
y
]
=
0
;
}
}
}
Symbol
Matrix
::
at
(
const
Position
&
pos
)
const
Symbol
Matrix
::
at
(
const
Position
&
pos
)
const
{
{
return
board_
.
at
(
pos
.
x
).
at
(
pos
.
y
);
return
board_
.
at
(
pos
.
x
).
at
(
pos
.
y
);
...
@@ -75,3 +147,14 @@ bool Matrix::isFree(const Position& pos)
...
@@ -75,3 +147,14 @@ bool Matrix::isFree(const Position& pos)
{
{
return
at
(
pos
)
<=
0
;
return
at
(
pos
)
<=
0
;
}
}
void
Matrix
::
print
()
const
{
for
(
auto
&
row
:
board_
)
{
for
(
auto
symbol
:
row
)
std
::
cout
<<
symbol
<<
" "
;
std
::
cout
<<
std
::
endl
;
}
std
::
cout
<<
"--------------------"
<<
std
::
endl
;
}
This diff is collapsed.
Click to expand it.
matrix.hxx
+
4
−
1
View file @
692df17a
...
@@ -16,11 +16,14 @@ protected:
...
@@ -16,11 +16,14 @@ protected:
public:
public:
Matrix
(
std
::
size_t
dim
);
Matrix
(
std
::
size_t
dim
);
bool
put
(
const
Element
&
elem
,
const
Position
&
pos
);
bool
put
(
const
Element
&
elem
,
const
Position
&
pos
);
bool
putFirst
(
const
Element
&
elem
);
bool
putFirst
(
const
Element
&
elem
,
Position
&
posIn
);
void
free
(
const
Element
&
elem
,
const
Position
&
pos
);
bool
isFree
(
const
Position
&
pos
);
bool
isFree
(
const
Position
&
pos
);
std
::
size_t
size
()
const
{
return
board_
.
size
();
}
std
::
size_t
size
()
const
{
return
board_
.
size
();
}
bool
isSolved
()
const
{
return
solved
;
}
bool
isSolved
()
const
{
return
solved
;
}
void
print
()
const
;
};
};
...
...
This diff is collapsed.
Click to expand it.
processor.cxx
+
13
−
9
View file @
692df17a
...
@@ -18,8 +18,8 @@ void Processor::process(std::list<Element> list)
...
@@ -18,8 +18,8 @@ void Processor::process(std::list<Element> list)
if
(
list
.
size
()
==
0
)
if
(
list
.
size
()
==
0
)
{
{
// TODO do something with the matrix
rMatrix_
.
print
();
std
::
cout
<<
"kesz"
<<
std
::
endl
;
ready_
=
true
;
return
;
return
;
}
}
...
@@ -29,20 +29,24 @@ void Processor::process(std::list<Element> list)
...
@@ -29,20 +29,24 @@ void Processor::process(std::list<Element> list)
auto
it
=
list
.
begin
();
auto
it
=
list
.
begin
();
while
(
hasMoreState
||
it
!=
list
.
end
()
)
while
(
hasMoreState
||
it
!=
list
.
end
()
)
{
{
success
=
rMatrix_
.
putFirst
(
*
it
);
Position
pos
{
0
,
0
};
success
=
rMatrix_
.
putFirst
(
*
it
,
pos
);
if
(
success
)
if
(
success
)
{
{
// rMatrix_.print();
// copy everything except current
// copy everything except current
std
::
list
<
Element
>
copy
;
std
::
list
<
Element
>
copy
;
std
::
copy
(
list
.
begin
(),
it
,
std
::
back_inserter
(
copy
));
std
::
copy
(
list
.
begin
(),
it
,
std
::
back_inserter
(
copy
));
copy
.
insert
(
copy
.
end
(),
std
::
next
(
it
),
list
.
end
());
copy
.
insert
(
copy
.
end
(),
std
::
next
(
it
),
list
.
end
());
process
(
std
::
move
(
copy
));
process
(
std
::
move
(
copy
));
if
(
ready_
)
it
->
print
();
rMatrix_
.
free
(
*
it
,
pos
);
}
}
else
{
hasMoreState
=
it
->
nextState
();
hasMoreState
=
it
->
nextState
();
if
(
!
hasMoreState
)
if
(
!
hasMoreState
)
it
++
;
it
++
;
}
}
}
}
}
This diff is collapsed.
Click to expand it.
processor.hxx
+
2
−
1
View file @
692df17a
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
class
Processor
class
Processor
{
{
private:
private:
bool
ready_
=
false
;
Matrix
&
rMatrix_
;
Matrix
&
rMatrix_
;
public:
public:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment