Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
org.benoitharrault.sudoku
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
android
org.benoitharrault.sudoku
Compare revisions
ef17b6c8f7455d674333f861dd2ff65b9d8c3917 to 81234494cec7fd69bf827981347ae0ec6fedacde
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
android/org.benoitharrault.sudoku
Select target project
No results found
81234494cec7fd69bf827981347ae0ec6fedacde
Select Git revision
Swap
Target
android/org.benoitharrault.sudoku
Select target project
android/org.benoitharrault.sudoku
1 result
ef17b6c8f7455d674333f861dd2ff65b9d8c3917
Select Git revision
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/screens/home.dart
+17
-0
17 additions, 0 deletions
lib/screens/home.dart
lib/utils/game_utils.dart
+82
-1
82 additions, 1 deletion
lib/utils/game_utils.dart
with
99 additions
and
1 deletion
lib/screens/home.dart
View file @
81234494
...
...
@@ -17,6 +17,23 @@ class Home extends StatelessWidget {
if
(
myProvider
.
stateRunning
)
{
menuActions
=
[
FlatButton
(
child:
Container
(
decoration:
BoxDecoration
(
borderRadius:
BorderRadius
.
circular
(
4
),
border:
Border
.
all
(
color:
Colors
.
blue
,
width:
4
,
),
),
margin:
EdgeInsets
.
all
(
8
),
child:
Image
(
image:
AssetImage
(
'assets/icons/button_help.png'
),
fit:
BoxFit
.
fill
),
),
onPressed:
()
=
>
GameUtils
.
showTip
(
myProvider
),
),
FlatButton
(
child:
Container
(
decoration:
BoxDecoration
(
...
...
This diff is collapsed.
Click to expand it.
lib/utils/game_utils.dart
View file @
81234494
import
'../provider/data.dart'
;
import
'../utils/board_utils.dart'
;
import
'../utils/game_utils.dart'
;
class
GameUtils
{
...
...
@@ -8,10 +9,90 @@ class GameUtils {
}
static
Future
<
void
>
startGame
(
Data
myProvider
)
async
{
print
(
'Start new game: '
+
myProvider
.
size
);
myProvider
.
updateSize
=
myProvider
.
size
;
myProvider
.
updateStateRunning
=
true
;
myProvider
.
updateCells
=
BoardUtils
.
createEmptyBoard
(
myProvider
.
blockSizeHorizontal
*
myProvider
.
blockSizeVertical
);
BoardUtils
.
pickGrid
(
myProvider
);
}
static
void
showTip
(
Data
myProvider
)
{
if
(
myProvider
.
currentCellCol
==
null
||
myProvider
.
currentCellRow
==
null
)
{
// no selected cell -> pick one
GameUtils
.
helpSelectCell
(
myProvider
);
}
else
{
// currently selected cell -> set value
GameUtils
.
helpFillCell
(
myProvider
);
}
}
static
void
helpSelectCell
(
Data
myProvider
)
{
List
cells
=
myProvider
.
cells
;
int
boardSize
=
myProvider
.
blockSizeHorizontal
*
myProvider
.
blockSizeVertical
;
// pick one of conflicting cells, if found
List
conflictingCells
=
[];
for
(
var
row
=
0
;
row
<
boardSize
;
row
++
)
{
for
(
var
col
=
0
;
col
<
boardSize
;
col
++
)
{
if
(
!
cells
[
row
][
col
]
.
isFixed
&&
cells
[
row
][
col
]
.
value
!=
0
)
{
if
(
cells
[
row
][
col
]
.
conflictsCount
!=
0
&&
!
BoardUtils
.
isValueAllowed
(
myProvider
,
col
,
row
,
cells
[
row
][
col
]
.
value
))
{
conflictingCells
.
add
([
col
,
row
]);
}
}
}
}
if
(
conflictingCells
.
length
!=
0
)
{
GameUtils
.
pickRandomFromList
(
myProvider
,
conflictingCells
);
return
;
}
// pick one form cells with unique non-conflicting candidate value
List
candidateCells
=
[];
for
(
var
row
=
0
;
row
<
boardSize
;
row
++
)
{
for
(
var
col
=
0
;
col
<
boardSize
;
col
++
)
{
if
(
cells
[
row
][
col
]
.
value
==
0
)
{
int
allowedValuesCount
=
0
;
for
(
var
value
=
1
;
value
<
=
boardSize
;
value
++
)
{
if
(
BoardUtils
.
isValueAllowed
(
myProvider
,
col
,
row
,
value
))
{
allowedValuesCount
++
;
}
}
if
(
allowedValuesCount
==
1
)
{
candidateCells
.
add
([
col
,
row
]);
}
}
}
}
if
(
candidateCells
.
length
!=
0
)
{
GameUtils
.
pickRandomFromList
(
myProvider
,
candidateCells
);
return
;
}
}
static
void
pickRandomFromList
(
Data
myProvider
,
List
cellsCoordinates
)
{
if
(
cellsCoordinates
.
length
>
0
)
{
cellsCoordinates
.
shuffle
();
List
cell
=
cellsCoordinates
[
0
];
myProvider
.
selectCell
(
cell
[
0
],
cell
[
1
]);
}
}
static
void
helpFillCell
(
Data
myProvider
)
{
int
boardSize
=
myProvider
.
blockSizeHorizontal
*
myProvider
.
blockSizeVertical
;
int
eligibleValue
=
0
;
// ensure there is only one eligible value for this cell
int
allowedValuesCount
=
0
;
for
(
var
value
=
1
;
value
<
=
boardSize
;
value
++
)
{
if
(
BoardUtils
.
isValueAllowed
(
myProvider
,
myProvider
.
currentCellCol
,
myProvider
.
currentCellRow
,
value
))
{
allowedValuesCount
++
;
eligibleValue
=
value
;
}
}
myProvider
.
updateCellValue
(
myProvider
.
currentCellCol
,
myProvider
.
currentCellRow
,
allowedValuesCount
==
1
?
eligibleValue
:
0
);
myProvider
.
selectCell
(
null
,
null
);
BoardUtils
.
computeConflictsInBoard
(
myProvider
);
}
}
This diff is collapsed.
Click to expand it.
Prev
1
2
Next