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
130557eae2a3943cd6cd7b4c1c23c66c2ea9eca9 to 733cfb653f94e1befe80d96270135438b48c78d0
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
733cfb653f94e1befe80d96270135438b48c78d0
Select Git revision
Branches
23-add-timer
65-update-icons
82-fix-colors
84-improve-app-metadata
master
Tags
Release_0.0.16_16
Release_0.0.17_17
Release_0.0.18_18
Release_0.0.19_19
Release_0.0.20_20
Release_0.0.21_21
Release_0.0.22_22
Release_0.0.23_23
Release_0.0.24_24
Release_0.0.25_25
Release_0.0.26_26
Release_0.0.27_27
Release_0.0.28_28
Release_0.0.29_29
Release_0.0.30_30
Release_0.0.31_31
Release_0.0.32_32
Release_0.0.33_33
Release_0.0.34_34
Release_0.0.35_35
Release_0.0.36_36
Release_0.0.37_37
Release_0.0.38_38
Release_0.0.39_39
Release_0.0.40_40
Release_0.0.41_41
Release_0.0.42_42
Release_0.0.43_43
Release_0.0.44_44
Release_0.0.45_45
Release_0.0.46_46
Release_0.0.47_47
Release_0.0.48_48
Release_0.1.0_49
Release_0.1.10_59
Release_0.1.11_60
Release_0.1.12_61
Release_0.1.13_62
Release_0.1.14_63
Release_0.1.15_64
Release_0.1.16_65
Release_0.1.17_66
Release_0.1.18_67
Release_0.1.19_68
Release_0.1.1_50
Release_0.1.20_69
Release_0.1.21_70
Release_0.1.22_71
Release_0.1.2_51
Release_0.1.3_52
Release_0.1.4_53
Release_0.1.5_54
Release_0.1.6_55
Release_0.1.7_56
Release_0.1.8_57
Release_0.1.9_58
Release_0.10.0_87
Release_0.2.0_72
Release_0.2.1_73
Release_0.3.0_74
Release_0.3.1_75
Release_0.4.0_76
Release_0.4.1_77
Release_0.5.0_78
Release_0.5.1_79
Release_0.5.2_80
Release_0.6.0_81
Release_0.7.0_82
Release_0.8.0_83
Release_0.9.0_84
Release_0.9.1_85
Release_0.9.2_86
77 results
Swap
Target
android/org.benoitharrault.sudoku
Select target project
android/org.benoitharrault.sudoku
1 result
130557eae2a3943cd6cd7b4c1c23c66c2ea9eca9
Select Git revision
Branches
23-add-timer
65-update-icons
82-fix-colors
84-improve-app-metadata
master
Tags
Release_0.0.16_16
Release_0.0.17_17
Release_0.0.18_18
Release_0.0.19_19
Release_0.0.20_20
Release_0.0.21_21
Release_0.0.22_22
Release_0.0.23_23
Release_0.0.24_24
Release_0.0.25_25
Release_0.0.26_26
Release_0.0.27_27
Release_0.0.28_28
Release_0.0.29_29
Release_0.0.30_30
Release_0.0.31_31
Release_0.0.32_32
Release_0.0.33_33
Release_0.0.34_34
Release_0.0.35_35
Release_0.0.36_36
Release_0.0.37_37
Release_0.0.38_38
Release_0.0.39_39
Release_0.0.40_40
Release_0.0.41_41
Release_0.0.42_42
Release_0.0.43_43
Release_0.0.44_44
Release_0.0.45_45
Release_0.0.46_46
Release_0.0.47_47
Release_0.0.48_48
Release_0.1.0_49
Release_0.1.10_59
Release_0.1.11_60
Release_0.1.12_61
Release_0.1.13_62
Release_0.1.14_63
Release_0.1.15_64
Release_0.1.16_65
Release_0.1.17_66
Release_0.1.18_67
Release_0.1.19_68
Release_0.1.1_50
Release_0.1.20_69
Release_0.1.21_70
Release_0.1.22_71
Release_0.1.2_51
Release_0.1.3_52
Release_0.1.4_53
Release_0.1.5_54
Release_0.1.6_55
Release_0.1.7_56
Release_0.1.8_57
Release_0.1.9_58
Release_0.10.0_87
Release_0.2.0_72
Release_0.2.1_73
Release_0.3.0_74
Release_0.3.1_75
Release_0.4.0_76
Release_0.4.1_77
Release_0.5.0_78
Release_0.5.1_79
Release_0.5.2_80
Release_0.6.0_81
Release_0.7.0_82
Release_0.8.0_83
Release_0.9.0_84
Release_0.9.1_85
Release_0.9.2_86
77 results
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
lib/utils/board_animate.dart
+10
-10
10 additions, 10 deletions
lib/utils/board_animate.dart
lib/utils/board_utils.dart
+91
-65
91 additions, 65 deletions
lib/utils/board_utils.dart
lib/utils/game_utils.dart
+8
-7
8 additions, 7 deletions
lib/utils/game_utils.dart
pubspec.yaml
+1
-1
1 addition, 1 deletion
pubspec.yaml
with
110 additions
and
83 deletions
lib/utils/board_animate.dart
View file @
733cfb65
...
@@ -4,14 +4,14 @@ import 'package:sudoku/provider/data.dart';
...
@@ -4,14 +4,14 @@ import 'package:sudoku/provider/data.dart';
class
BoardAnimate
{
class
BoardAnimate
{
// Start game animation: blinking tiles
// Start game animation: blinking tiles
static
List
<
List
<
List
<
bool
>>>
createStartGameAnimationPatterns
(
Data
myProvider
)
{
static
AnimatedBoardSequence
createStartGameAnimationPatterns
(
Data
myProvider
)
{
List
<
List
<
List
<
bool
>>>
patterns
=
[];
AnimatedBoardSequence
patterns
=
[];
int
patternsCount
=
3
;
int
patternsCount
=
3
;
int
boardSideLength
=
myProvider
.
blockSizeHorizontal
*
myProvider
.
blockSizeVertical
;
int
boardSideLength
=
myProvider
.
blockSizeHorizontal
*
myProvider
.
blockSizeVertical
;
for
(
int
patternIndex
=
0
;
patternIndex
<
patternsCount
;
patternIndex
++
)
{
for
(
int
patternIndex
=
0
;
patternIndex
<
patternsCount
;
patternIndex
++
)
{
List
<
List
<
bool
>>
pattern
=
[];
AnimatedBoard
pattern
=
[];
for
(
int
row
=
0
;
row
<
boardSideLength
;
row
++
)
{
for
(
int
row
=
0
;
row
<
boardSideLength
;
row
++
)
{
List
<
bool
>
patternRow
=
[];
List
<
bool
>
patternRow
=
[];
for
(
int
col
=
0
;
col
<
boardSideLength
;
col
++
)
{
for
(
int
col
=
0
;
col
<
boardSideLength
;
col
++
)
{
...
@@ -26,14 +26,14 @@ class BoardAnimate {
...
@@ -26,14 +26,14 @@ class BoardAnimate {
}
}
// Win game animation: fill board with colored rows, from bottom to top
// Win game animation: fill board with colored rows, from bottom to top
static
List
<
List
<
List
<
bool
>>>
createWinGameAnimationPatterns
(
Data
myProvider
)
{
static
AnimatedBoardSequence
createWinGameAnimationPatterns
(
Data
myProvider
)
{
List
<
List
<
List
<
bool
>>>
patterns
=
[];
AnimatedBoardSequence
patterns
=
[];
int
boardSideLength
=
myProvider
.
blockSizeHorizontal
*
myProvider
.
blockSizeVertical
;
int
boardSideLength
=
myProvider
.
blockSizeHorizontal
*
myProvider
.
blockSizeVertical
;
int
patternsCount
=
boardSideLength
+
6
;
int
patternsCount
=
boardSideLength
+
6
;
for
(
int
patternIndex
=
0
;
patternIndex
<
patternsCount
;
patternIndex
++
)
{
for
(
int
patternIndex
=
0
;
patternIndex
<
patternsCount
;
patternIndex
++
)
{
List
<
List
<
bool
>>
pattern
=
[];
AnimatedBoard
pattern
=
[];
for
(
int
row
=
0
;
row
<
boardSideLength
;
row
++
)
{
for
(
int
row
=
0
;
row
<
boardSideLength
;
row
++
)
{
List
<
bool
>
patternRow
=
[];
List
<
bool
>
patternRow
=
[];
for
(
int
col
=
0
;
col
<
boardSideLength
;
col
++
)
{
for
(
int
col
=
0
;
col
<
boardSideLength
;
col
++
)
{
...
@@ -48,14 +48,14 @@ class BoardAnimate {
...
@@ -48,14 +48,14 @@ class BoardAnimate {
}
}
// Default multi-purpose animation: sliding stripes, from top left to right bottom
// Default multi-purpose animation: sliding stripes, from top left to right bottom
static
List
<
List
<
List
<
bool
>>>
createDefaultAnimationPatterns
(
Data
myProvider
)
{
static
AnimatedBoardSequence
createDefaultAnimationPatterns
(
Data
myProvider
)
{
List
<
List
<
List
<
bool
>>>
patterns
=
[];
AnimatedBoardSequence
patterns
=
[];
int
boardSideLength
=
myProvider
.
blockSizeHorizontal
*
myProvider
.
blockSizeVertical
;
int
boardSideLength
=
myProvider
.
blockSizeHorizontal
*
myProvider
.
blockSizeVertical
;
int
patternsCount
=
boardSideLength
;
int
patternsCount
=
boardSideLength
;
for
(
int
patternIndex
=
0
;
patternIndex
<
patternsCount
;
patternIndex
++
)
{
for
(
int
patternIndex
=
0
;
patternIndex
<
patternsCount
;
patternIndex
++
)
{
List
<
List
<
bool
>>
pattern
=
[];
AnimatedBoard
pattern
=
[];
for
(
int
row
=
0
;
row
<
boardSideLength
;
row
++
)
{
for
(
int
row
=
0
;
row
<
boardSideLength
;
row
++
)
{
List
<
bool
>
patternRow
=
[];
List
<
bool
>
patternRow
=
[];
for
(
int
col
=
0
;
col
<
boardSideLength
;
col
++
)
{
for
(
int
col
=
0
;
col
<
boardSideLength
;
col
++
)
{
...
@@ -70,7 +70,7 @@ class BoardAnimate {
...
@@ -70,7 +70,7 @@ class BoardAnimate {
}
}
static
void
startAnimation
(
Data
myProvider
,
String
animationType
)
{
static
void
startAnimation
(
Data
myProvider
,
String
animationType
)
{
List
<
List
<
List
<
bool
>>>
patterns
=
[];
AnimatedBoardSequence
patterns
=
[];
switch
(
animationType
)
{
switch
(
animationType
)
{
case
'start'
:
case
'start'
:
...
...
This diff is collapsed.
Click to expand it.
lib/utils/board_utils.dart
View file @
733cfb65
...
@@ -6,7 +6,7 @@ import 'package:sudoku/utils/random_pick_grid.dart';
...
@@ -6,7 +6,7 @@ import 'package:sudoku/utils/random_pick_grid.dart';
import
'package:sudoku/utils/tools.dart'
;
import
'package:sudoku/utils/tools.dart'
;
class
BoardUtils
{
class
BoardUtils
{
static
printGrid
(
List
<
List
<
Cell
>>
cells
,
List
<
List
<
Cell
>>
solvedCells
)
{
static
printGrid
(
Board
cells
,
Board
solvedCells
)
{
String
stringValues
=
'0123456789ABCDEFG'
;
String
stringValues
=
'0123456789ABCDEFG'
;
printlog
(
''
);
printlog
(
''
);
printlog
(
'-------'
);
printlog
(
'-------'
);
...
@@ -42,16 +42,21 @@ class BoardUtils {
...
@@ -42,16 +42,21 @@ class BoardUtils {
myProvider
.
updateCellsSolved
(
BoardUtils
.
getSolvedGrid
(
myProvider
));
myProvider
.
updateCellsSolved
(
BoardUtils
.
getSolvedGrid
(
myProvider
));
myProvider
.
selectCell
(
null
,
null
);
myProvider
.
selectCell
(
null
,
null
);
printGrid
(
myProvider
.
cells
,
myProvider
.
cells
Solved
);
printGrid
(
myProvider
.
board
,
myProvider
.
board
Solved
);
}
}
}
}
static
List
<
List
<
Cell
>>
createEmptyBoard
(
final
int
boardSize
)
{
static
Board
createEmptyBoard
(
final
int
boardSize
)
{
final
List
<
List
<
Cell
>>
cells
=
[];
final
Board
cells
=
[];
for
(
int
rowIndex
=
0
;
rowIndex
<
boardSize
;
rowIndex
++
)
{
for
(
int
rowIndex
=
0
;
rowIndex
<
boardSize
;
rowIndex
++
)
{
final
List
<
Cell
>
row
=
[];
final
List
<
Cell
>
row
=
[];
for
(
int
colIndex
=
0
;
colIndex
<
boardSize
;
colIndex
++
)
{
for
(
int
colIndex
=
0
;
colIndex
<
boardSize
;
colIndex
++
)
{
row
.
add
(
Cell
(
0
,
false
));
row
.
add
(
Cell
(
row:
rowIndex
,
col:
colIndex
,
value:
0
,
isFixed:
false
,
));
}
}
cells
.
add
(
row
);
cells
.
add
(
row
);
}
}
...
@@ -59,8 +64,8 @@ class BoardUtils {
...
@@ -59,8 +64,8 @@ class BoardUtils {
return
cells
;
return
cells
;
}
}
static
List
<
List
<
Cell
>>
createBoardFromSavedState
(
Data
myProvider
,
String
savedBoard
)
{
static
Board
createBoardFromSavedState
(
Data
myProvider
,
String
savedBoard
)
{
final
List
<
List
<
Cell
>>
cells
=
[];
final
Board
cells
=
[];
final
int
boardSize
=
int
.
parse
(
pow
((
savedBoard
.
length
/
2
),
1
/
2
)
.
toStringAsFixed
(
0
));
final
int
boardSize
=
int
.
parse
(
pow
((
savedBoard
.
length
/
2
),
1
/
2
)
.
toStringAsFixed
(
0
));
const
String
stringValues
=
'0123456789ABCDEFG'
;
const
String
stringValues
=
'0123456789ABCDEFG'
;
...
@@ -75,7 +80,12 @@ class BoardUtils {
...
@@ -75,7 +80,12 @@ class BoardUtils {
final
String
isFixedString
=
savedBoard
[
index
++
];
final
String
isFixedString
=
savedBoard
[
index
++
];
final
bool
isFixed
=
(
isFixedString
!=
' '
);
final
bool
isFixed
=
(
isFixedString
!=
' '
);
row
.
add
(
Cell
(
value
,
isFixed
));
row
.
add
(
Cell
(
row:
rowIndex
,
col:
colIndex
,
value:
value
,
isFixed:
isFixed
,
));
}
}
cells
.
add
(
row
);
cells
.
add
(
row
);
}
}
...
@@ -83,12 +93,17 @@ class BoardUtils {
...
@@ -83,12 +93,17 @@ class BoardUtils {
return
cells
;
return
cells
;
}
}
static
List
<
List
<
Cell
>>
copyBoard
(
List
cells
)
{
static
Board
copyBoard
(
List
cells
)
{
final
List
<
List
<
Cell
>>
copiedGrid
=
[];
final
Board
copiedGrid
=
[];
for
(
int
rowIndex
=
0
;
rowIndex
<
cells
.
length
;
rowIndex
++
)
{
for
(
int
rowIndex
=
0
;
rowIndex
<
cells
.
length
;
rowIndex
++
)
{
final
List
<
Cell
>
row
=
[];
final
List
<
Cell
>
row
=
[];
for
(
int
colIndex
=
0
;
colIndex
<
cells
[
rowIndex
]
.
length
;
colIndex
++
)
{
for
(
int
colIndex
=
0
;
colIndex
<
cells
[
rowIndex
]
.
length
;
colIndex
++
)
{
row
.
add
(
Cell
(
cells
[
rowIndex
][
colIndex
]
.
value
,
false
));
row
.
add
(
Cell
(
row:
rowIndex
,
col:
colIndex
,
value:
cells
[
rowIndex
][
colIndex
]
.
value
,
isFixed:
false
,
));
}
}
copiedGrid
.
add
(
row
);
copiedGrid
.
add
(
row
);
}
}
...
@@ -96,8 +111,8 @@ class BoardUtils {
...
@@ -96,8 +111,8 @@ class BoardUtils {
return
copiedGrid
;
return
copiedGrid
;
}
}
static
List
<
List
<
Cell
>>
createBoardFromTemplate
(
String
grid
,
bool
isSymetric
)
{
static
Board
createBoardFromTemplate
(
String
grid
,
bool
isSymetric
)
{
List
<
List
<
Cell
>>
cells
=
[];
Board
cells
=
[];
final
int
boardSize
=
int
.
parse
(
pow
(
grid
.
length
,
1
/
2
)
.
toStringAsFixed
(
0
));
final
int
boardSize
=
int
.
parse
(
pow
(
grid
.
length
,
1
/
2
)
.
toStringAsFixed
(
0
));
const
String
stringValues
=
'0123456789ABCDEFG'
;
const
String
stringValues
=
'0123456789ABCDEFG'
;
...
@@ -108,7 +123,12 @@ class BoardUtils {
...
@@ -108,7 +123,12 @@ class BoardUtils {
for
(
int
colIndex
=
0
;
colIndex
<
boardSize
;
colIndex
++
)
{
for
(
int
colIndex
=
0
;
colIndex
<
boardSize
;
colIndex
++
)
{
final
String
stringValue
=
grid
[
index
++
];
final
String
stringValue
=
grid
[
index
++
];
final
int
value
=
stringValues
.
indexOf
(
stringValue
);
final
int
value
=
stringValues
.
indexOf
(
stringValue
);
row
.
add
(
Cell
(
value
,
(
value
!=
0
)));
row
.
add
(
Cell
(
row:
rowIndex
,
col:
colIndex
,
value:
value
,
isFixed:
(
value
!=
0
),
));
}
}
cells
.
add
(
row
);
cells
.
add
(
row
);
}
}
...
@@ -131,11 +151,15 @@ class BoardUtils {
...
@@ -131,11 +151,15 @@ class BoardUtils {
switch
(
flip
)
{
switch
(
flip
)
{
case
'horizontal'
:
case
'horizontal'
:
{
{
final
List
<
List
<
Cell
>>
transformedBoard
=
createEmptyBoard
(
boardSize
);
final
Board
transformedBoard
=
createEmptyBoard
(
boardSize
);
for
(
int
rowIndex
=
0
;
rowIndex
<
boardSize
;
rowIndex
++
)
{
for
(
int
rowIndex
=
0
;
rowIndex
<
boardSize
;
rowIndex
++
)
{
for
(
int
colIndex
=
0
;
colIndex
<
boardSize
;
colIndex
++
)
{
for
(
int
colIndex
=
0
;
colIndex
<
boardSize
;
colIndex
++
)
{
transformedBoard
[
rowIndex
][
colIndex
]
.
value
=
transformedBoard
[
rowIndex
][
colIndex
]
=
Cell
(
cells
[
boardSize
-
rowIndex
-
1
][
colIndex
]
.
value
;
row:
rowIndex
,
col:
colIndex
,
value:
cells
[
boardSize
-
rowIndex
-
1
][
colIndex
]
.
value
,
isFixed:
false
,
);
}
}
}
}
cells
=
transformedBoard
;
cells
=
transformedBoard
;
...
@@ -143,11 +167,15 @@ class BoardUtils {
...
@@ -143,11 +167,15 @@ class BoardUtils {
break
;
break
;
case
'vertical'
:
case
'vertical'
:
{
{
final
List
<
List
<
Cell
>>
transformedBoard
=
createEmptyBoard
(
boardSize
);
final
Board
transformedBoard
=
createEmptyBoard
(
boardSize
);
for
(
int
rowIndex
=
0
;
rowIndex
<
boardSize
;
rowIndex
++
)
{
for
(
int
rowIndex
=
0
;
rowIndex
<
boardSize
;
rowIndex
++
)
{
for
(
int
colIndex
=
0
;
colIndex
<
boardSize
;
colIndex
++
)
{
for
(
int
colIndex
=
0
;
colIndex
<
boardSize
;
colIndex
++
)
{
transformedBoard
[
rowIndex
][
colIndex
]
.
value
=
transformedBoard
[
rowIndex
][
colIndex
]
=
Cell
(
cells
[
rowIndex
][
boardSize
-
colIndex
-
1
]
.
value
;
row:
rowIndex
,
col:
colIndex
,
value:
cells
[
rowIndex
][
boardSize
-
colIndex
-
1
]
.
value
,
isFixed:
false
,
);
}
}
}
}
cells
=
transformedBoard
;
cells
=
transformedBoard
;
...
@@ -158,11 +186,15 @@ class BoardUtils {
...
@@ -158,11 +186,15 @@ class BoardUtils {
switch
(
rotate
)
{
switch
(
rotate
)
{
case
'left'
:
case
'left'
:
{
{
final
List
<
List
<
Cell
>>
transformedBoard
=
createEmptyBoard
(
boardSize
);
final
Board
transformedBoard
=
createEmptyBoard
(
boardSize
);
for
(
int
rowIndex
=
0
;
rowIndex
<
boardSize
;
rowIndex
++
)
{
for
(
int
rowIndex
=
0
;
rowIndex
<
boardSize
;
rowIndex
++
)
{
for
(
int
colIndex
=
0
;
colIndex
<
boardSize
;
colIndex
++
)
{
for
(
int
colIndex
=
0
;
colIndex
<
boardSize
;
colIndex
++
)
{
transformedBoard
[
rowIndex
][
colIndex
]
.
value
=
transformedBoard
[
rowIndex
][
colIndex
]
=
Cell
(
cells
[
colIndex
][
boardSize
-
rowIndex
-
1
]
.
value
;
row:
rowIndex
,
col:
colIndex
,
value:
cells
[
colIndex
][
boardSize
-
rowIndex
-
1
]
.
value
,
isFixed:
false
,
);
}
}
}
}
cells
=
transformedBoard
;
cells
=
transformedBoard
;
...
@@ -170,11 +202,15 @@ class BoardUtils {
...
@@ -170,11 +202,15 @@ class BoardUtils {
break
;
break
;
case
'right'
:
case
'right'
:
{
{
final
List
<
List
<
Cell
>>
transformedBoard
=
createEmptyBoard
(
boardSize
);
final
Board
transformedBoard
=
createEmptyBoard
(
boardSize
);
for
(
int
rowIndex
=
0
;
rowIndex
<
boardSize
;
rowIndex
++
)
{
for
(
int
rowIndex
=
0
;
rowIndex
<
boardSize
;
rowIndex
++
)
{
for
(
int
colIndex
=
0
;
colIndex
<
boardSize
;
colIndex
++
)
{
for
(
int
colIndex
=
0
;
colIndex
<
boardSize
;
colIndex
++
)
{
transformedBoard
[
rowIndex
][
colIndex
]
.
value
=
transformedBoard
[
rowIndex
][
colIndex
]
=
Cell
(
cells
[
boardSize
-
colIndex
-
1
][
rowIndex
]
.
value
;
row:
rowIndex
,
col:
colIndex
,
value:
cells
[
boardSize
-
colIndex
-
1
][
rowIndex
]
.
value
,
isFixed:
false
,
);
}
}
}
}
cells
=
transformedBoard
;
cells
=
transformedBoard
;
...
@@ -185,8 +221,12 @@ class BoardUtils {
...
@@ -185,8 +221,12 @@ class BoardUtils {
// Fix cells fixed states
// Fix cells fixed states
for
(
int
rowIndex
=
0
;
rowIndex
<
boardSize
;
rowIndex
++
)
{
for
(
int
rowIndex
=
0
;
rowIndex
<
boardSize
;
rowIndex
++
)
{
for
(
int
colIndex
=
0
;
colIndex
<
boardSize
;
colIndex
++
)
{
for
(
int
colIndex
=
0
;
colIndex
<
boardSize
;
colIndex
++
)
{
cells
[
rowIndex
][
colIndex
]
.
isFixed
=
cells
[
rowIndex
][
colIndex
]
=
Cell
(
(
cells
[
rowIndex
][
colIndex
]
.
value
!=
0
)
?
true
:
false
;
row:
rowIndex
,
col:
colIndex
,
value:
cells
[
rowIndex
][
colIndex
]
.
value
,
isFixed:
(
cells
[
rowIndex
][
colIndex
]
.
value
!=
0
)
?
true
:
false
,
);
}
}
}
}
...
@@ -194,7 +234,8 @@ class BoardUtils {
...
@@ -194,7 +234,8 @@ class BoardUtils {
}
}
static
bool
checkBoardIsSolved
(
Data
myProvider
)
{
static
bool
checkBoardIsSolved
(
Data
myProvider
)
{
final
List
<
List
<
Cell
>>
cells
=
myProvider
.
cells
;
final
Board
cells
=
myProvider
.
board
;
final
ConflictsCount
conflicts
=
myProvider
.
boardConflicts
;
final
int
blockSizeHorizontal
=
myProvider
.
blockSizeHorizontal
;
final
int
blockSizeHorizontal
=
myProvider
.
blockSizeHorizontal
;
final
int
blockSizeVertical
=
myProvider
.
blockSizeVertical
;
final
int
blockSizeVertical
=
myProvider
.
blockSizeVertical
;
...
@@ -207,7 +248,7 @@ class BoardUtils {
...
@@ -207,7 +248,7 @@ class BoardUtils {
// check grid is fully completed and does not contain conflict
// check grid is fully completed and does not contain conflict
for
(
int
row
=
0
;
row
<
boardSize
;
row
++
)
{
for
(
int
row
=
0
;
row
<
boardSize
;
row
++
)
{
for
(
int
col
=
0
;
col
<
boardSize
;
col
++
)
{
for
(
int
col
=
0
;
col
<
boardSize
;
col
++
)
{
if
(
cells
[
row
][
col
]
.
value
==
0
||
c
ell
s
[
row
][
col
]
.
conflictsCount
!=
0
)
{
if
(
cells
[
row
][
col
]
.
value
==
0
||
c
onflict
s
[
row
][
col
]
!=
0
)
{
return
false
;
return
false
;
}
}
}
}
...
@@ -219,7 +260,7 @@ class BoardUtils {
...
@@ -219,7 +260,7 @@ class BoardUtils {
}
}
static
bool
isValueAllowed
(
static
bool
isValueAllowed
(
List
<
List
<
Cell
>>
cells
,
Board
cells
,
int
blockSizeHorizontal
,
int
blockSizeHorizontal
,
int
blockSizeVertical
,
int
blockSizeVertical
,
int
?
candidateCol
,
int
?
candidateCol
,
...
@@ -300,7 +341,8 @@ class BoardUtils {
...
@@ -300,7 +341,8 @@ class BoardUtils {
}
}
static
void
computeConflictsInBoard
(
Data
myProvider
)
{
static
void
computeConflictsInBoard
(
Data
myProvider
)
{
final
List
<
List
<
Cell
>>
cells
=
myProvider
.
cells
;
final
Board
cells
=
myProvider
.
board
;
final
ConflictsCount
conflicts
=
myProvider
.
boardConflicts
;
final
int
blockSizeHorizontal
=
myProvider
.
blockSizeHorizontal
;
final
int
blockSizeHorizontal
=
myProvider
.
blockSizeHorizontal
;
final
int
blockSizeVertical
=
myProvider
.
blockSizeVertical
;
final
int
blockSizeVertical
=
myProvider
.
blockSizeVertical
;
...
@@ -310,7 +352,7 @@ class BoardUtils {
...
@@ -310,7 +352,7 @@ class BoardUtils {
// reset conflict states
// reset conflict states
for
(
int
row
=
0
;
row
<
boardSize
;
row
++
)
{
for
(
int
row
=
0
;
row
<
boardSize
;
row
++
)
{
for
(
int
col
=
0
;
col
<
boardSize
;
col
++
)
{
for
(
int
col
=
0
;
col
<
boardSize
;
col
++
)
{
c
ell
s
[
row
][
col
]
.
conflictsCount
=
0
;
c
onflict
s
[
row
][
col
]
=
0
;
}
}
}
}
...
@@ -328,7 +370,7 @@ class BoardUtils {
...
@@ -328,7 +370,7 @@ class BoardUtils {
printlog
(
'line
$row
contains duplicates'
);
printlog
(
'line
$row
contains duplicates'
);
// Add line to cells in conflict
// Add line to cells in conflict
for
(
int
col
=
0
;
col
<
boardSize
;
col
++
)
{
for
(
int
col
=
0
;
col
<
boardSize
;
col
++
)
{
c
ell
s
[
row
][
col
]
.
conflictsCount
++
;
c
onflict
s
[
row
][
col
]
++
;
}
}
}
}
}
}
...
@@ -347,7 +389,7 @@ class BoardUtils {
...
@@ -347,7 +389,7 @@ class BoardUtils {
printlog
(
'column
$col
contains duplicates'
);
printlog
(
'column
$col
contains duplicates'
);
// Add column to cells in conflict
// Add column to cells in conflict
for
(
int
row
=
0
;
row
<
boardSize
;
row
++
)
{
for
(
int
row
=
0
;
row
<
boardSize
;
row
++
)
{
c
ell
s
[
row
][
col
]
.
conflictsCount
++
;
c
onflict
s
[
row
][
col
]
++
;
}
}
}
}
}
}
...
@@ -378,17 +420,19 @@ class BoardUtils {
...
@@ -378,17 +420,19 @@ class BoardUtils {
for
(
int
colInBlock
=
0
;
colInBlock
<
blockSizeHorizontal
;
colInBlock
++
)
{
for
(
int
colInBlock
=
0
;
colInBlock
<
blockSizeHorizontal
;
colInBlock
++
)
{
int
row
=
(
blockRow
*
blockSizeVertical
)
+
rowInBlock
;
int
row
=
(
blockRow
*
blockSizeVertical
)
+
rowInBlock
;
int
col
=
(
blockCol
*
blockSizeHorizontal
)
+
colInBlock
;
int
col
=
(
blockCol
*
blockSizeHorizontal
)
+
colInBlock
;
c
ell
s
[
row
][
col
]
.
conflictsCount
++
;
c
onflict
s
[
row
][
col
]
++
;
}
}
}
}
}
}
}
}
}
}
myProvider
.
updateConflicts
(
conflicts
);
}
}
static
List
<
List
<
int
>>
getCellsWithWrongValue
(
static
List
<
List
<
int
>>
getCellsWithWrongValue
(
final
List
<
List
<
Cell
>>
cells
,
final
Board
cells
,
final
List
<
List
<
Cell
>>
cellsSolved
,
final
Board
cellsSolved
,
final
int
blockSizeHorizontal
,
final
int
blockSizeHorizontal
,
final
int
blockSizeVertical
,
final
int
blockSizeVertical
,
)
{
)
{
...
@@ -407,31 +451,8 @@ class BoardUtils {
...
@@ -407,31 +451,8 @@ class BoardUtils {
return
cellsWithWrongValue
;
return
cellsWithWrongValue
;
}
}
static
List
<
List
<
int
>>
getConflictingCells
(
final
List
<
List
<
Cell
>>
cells
,
final
int
blockSizeHorizontal
,
final
int
blockSizeVertical
,
)
{
final
List
<
List
<
int
>>
conflictingCells
=
[];
final
int
boardSize
=
blockSizeHorizontal
*
blockSizeVertical
;
for
(
int
row
=
0
;
row
<
boardSize
;
row
++
)
{
for
(
int
col
=
0
;
col
<
boardSize
;
col
++
)
{
if
(
!
cells
[
row
][
col
]
.
isFixed
&&
cells
[
row
][
col
]
.
value
!=
0
)
{
if
(
cells
[
row
][
col
]
.
conflictsCount
!=
0
&&
!
BoardUtils
.
isValueAllowed
(
cells
,
blockSizeHorizontal
,
blockSizeVertical
,
col
,
row
,
cells
[
row
][
col
]
.
value
))
{
conflictingCells
.
add
([
col
,
row
]);
}
}
}
}
return
conflictingCells
;
}
static
List
<
List
<
int
>>
getCellsWithUniqueAvailableValue
(
static
List
<
List
<
int
>>
getCellsWithUniqueAvailableValue
(
List
<
List
<
Cell
>>
cells
,
Board
cells
,
final
int
blockSizeHorizontal
,
final
int
blockSizeHorizontal
,
final
int
blockSizeVertical
,
final
int
blockSizeVertical
,
)
{
)
{
...
@@ -460,8 +481,8 @@ class BoardUtils {
...
@@ -460,8 +481,8 @@ class BoardUtils {
return
candidateCells
;
return
candidateCells
;
}
}
static
List
<
List
<
Cell
>>
getSolvedGrid
(
Data
myProvider
)
{
static
Board
getSolvedGrid
(
Data
myProvider
)
{
final
List
<
List
<
Cell
>>
cells
=
copyBoard
(
myProvider
.
cells
);
final
Board
cells
=
copyBoard
(
myProvider
.
board
);
final
int
blockSizeHorizontal
=
myProvider
.
blockSizeHorizontal
;
final
int
blockSizeHorizontal
=
myProvider
.
blockSizeHorizontal
;
int
blockSizeVertical
=
myProvider
.
blockSizeVertical
;
int
blockSizeVertical
=
myProvider
.
blockSizeVertical
;
...
@@ -479,7 +500,12 @@ class BoardUtils {
...
@@ -479,7 +500,12 @@ class BoardUtils {
int
col
=
cellsWithUniqueAvailableValue
[
i
][
0
];
int
col
=
cellsWithUniqueAvailableValue
[
i
][
0
];
int
row
=
cellsWithUniqueAvailableValue
[
i
][
1
];
int
row
=
cellsWithUniqueAvailableValue
[
i
][
1
];
int
value
=
cellsWithUniqueAvailableValue
[
i
][
2
];
int
value
=
cellsWithUniqueAvailableValue
[
i
][
2
];
cells
[
row
][
col
]
.
value
=
value
;
cells
[
row
][
col
]
=
Cell
(
row:
row
,
col:
col
,
value:
value
,
isFixed:
cells
[
row
][
col
]
.
isFixed
,
);
}
}
}
while
(
true
);
}
while
(
true
);
...
...
This diff is collapsed.
Click to expand it.
lib/utils/game_utils.dart
View file @
733cfb65
import
'package:sudoku/entities/cell.dart'
;
import
'package:sudoku/provider/data.dart'
;
import
'package:sudoku/provider/data.dart'
;
import
'package:sudoku/utils/board_animate.dart'
;
import
'package:sudoku/utils/board_animate.dart'
;
import
'package:sudoku/utils/board_utils.dart'
;
import
'package:sudoku/utils/board_utils.dart'
;
...
@@ -19,6 +18,8 @@ class GameUtils {
...
@@ -19,6 +18,8 @@ class GameUtils {
myProvider
.
shuffleCellValues
();
myProvider
.
shuffleCellValues
();
myProvider
.
updateCells
(
BoardUtils
.
createEmptyBoard
(
myProvider
.
updateCells
(
BoardUtils
.
createEmptyBoard
(
myProvider
.
blockSizeHorizontal
*
myProvider
.
blockSizeVertical
));
myProvider
.
blockSizeHorizontal
*
myProvider
.
blockSizeVertical
));
myProvider
.
initAnimatedBackground
();
myProvider
.
initConflictsBoard
();
BoardUtils
.
pickGrid
(
myProvider
);
BoardUtils
.
pickGrid
(
myProvider
);
BoardAnimate
.
startAnimation
(
myProvider
,
'start'
);
BoardAnimate
.
startAnimation
(
myProvider
,
'start'
);
}
}
...
@@ -57,7 +58,7 @@ class GameUtils {
...
@@ -57,7 +58,7 @@ class GameUtils {
}
}
static
void
showTip
(
Data
myProvider
)
{
static
void
showTip
(
Data
myProvider
)
{
if
(
myProvider
.
current
CellCol
==
null
||
myProvider
.
current
CellRow
==
null
)
{
if
(
myProvider
.
selected
CellCol
==
null
||
myProvider
.
selected
CellRow
==
null
)
{
// no selected cell -> pick one
// no selected cell -> pick one
GameUtils
.
helpSelectCell
(
myProvider
);
GameUtils
.
helpSelectCell
(
myProvider
);
}
else
{
}
else
{
...
@@ -68,14 +69,14 @@ class GameUtils {
...
@@ -68,14 +69,14 @@ class GameUtils {
}
}
static
void
helpSelectCell
(
Data
myProvider
)
{
static
void
helpSelectCell
(
Data
myProvider
)
{
final
List
<
List
<
Cell
>>
cells
=
myProvider
.
cells
;
final
Board
cells
=
myProvider
.
board
;
final
int
blockSizeHorizontal
=
myProvider
.
blockSizeHorizontal
;
final
int
blockSizeHorizontal
=
myProvider
.
blockSizeHorizontal
;
final
int
blockSizeVertical
=
myProvider
.
blockSizeVertical
;
final
int
blockSizeVertical
=
myProvider
.
blockSizeVertical
;
// pick one of wrong value cells, if found
// pick one of wrong value cells, if found
final
List
<
List
<
int
>>
wrongValueCells
=
BoardUtils
.
getCellsWithWrongValue
(
final
List
<
List
<
int
>>
wrongValueCells
=
BoardUtils
.
getCellsWithWrongValue
(
cells
,
cells
,
myProvider
.
cells
Solved
,
myProvider
.
board
Solved
,
blockSizeHorizontal
,
blockSizeHorizontal
,
blockSizeVertical
,
blockSizeVertical
,
);
);
...
@@ -116,7 +117,7 @@ class GameUtils {
...
@@ -116,7 +117,7 @@ class GameUtils {
}
}
static
void
helpFillCell
(
Data
myProvider
)
{
static
void
helpFillCell
(
Data
myProvider
)
{
final
List
<
List
<
Cell
>>
cells
=
myProvider
.
cells
;
final
Board
cells
=
myProvider
.
board
;
final
int
blockSizeHorizontal
=
myProvider
.
blockSizeHorizontal
;
final
int
blockSizeHorizontal
=
myProvider
.
blockSizeHorizontal
;
final
int
blockSizeVertical
=
myProvider
.
blockSizeVertical
;
final
int
blockSizeVertical
=
myProvider
.
blockSizeVertical
;
...
@@ -129,13 +130,13 @@ class GameUtils {
...
@@ -129,13 +130,13 @@ class GameUtils {
int
allowedValuesCount
=
0
;
int
allowedValuesCount
=
0
;
for
(
int
value
=
1
;
value
<
=
boardSize
;
value
++
)
{
for
(
int
value
=
1
;
value
<
=
boardSize
;
value
++
)
{
if
(
BoardUtils
.
isValueAllowed
(
cells
,
blockSizeHorizontal
,
blockSizeVertical
,
if
(
BoardUtils
.
isValueAllowed
(
cells
,
blockSizeHorizontal
,
blockSizeVertical
,
myProvider
.
current
CellCol
,
myProvider
.
current
CellRow
,
value
))
{
myProvider
.
selected
CellCol
,
myProvider
.
selected
CellRow
,
value
))
{
allowedValuesCount
++
;
allowedValuesCount
++
;
eligibleValue
=
value
;
eligibleValue
=
value
;
}
}
}
}
myProvider
.
updateCellValue
(
myProvider
.
current
CellCol
,
myProvider
.
current
CellRow
,
myProvider
.
updateCellValue
(
myProvider
.
selected
CellCol
,
myProvider
.
selected
CellRow
,
allowedValuesCount
==
1
?
eligibleValue
:
0
);
allowedValuesCount
==
1
?
eligibleValue
:
0
);
myProvider
.
selectCell
(
null
,
null
);
myProvider
.
selectCell
(
null
,
null
);
if
(
BoardUtils
.
checkBoardIsSolved
(
myProvider
))
{
if
(
BoardUtils
.
checkBoardIsSolved
(
myProvider
))
{
...
...
This diff is collapsed.
Click to expand it.
pubspec.yaml
View file @
733cfb65
name
:
sudoku
name
:
sudoku
description
:
A sudoku game application.
description
:
A sudoku game application.
publish_to
:
'
none'
publish_to
:
'
none'
version
:
0.1.1
5
+6
4
version
:
0.1.1
8
+6
7
environment
:
environment
:
sdk
:
'
^3.0.0'
sdk
:
'
^3.0.0'
...
...
This diff is collapsed.
Click to expand it.
Prev
1
2
Next