Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • 23-add-timer
  • 65-update-icons
  • 82-fix-colors
  • 84-improve-app-metadata
  • master
  • 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

Target

Select target project
  • android/org.benoitharrault.sudoku
1 result
Select Git revision
  • 23-add-timer
  • 65-update-icons
  • 82-fix-colors
  • 84-improve-app-metadata
  • master
  • 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
import 'dart:async';
import '../entities/cell.dart';
import '../provider/data.dart';
class BoardAnimate {
// Start game animation: blinking tiles
static List createStartGameAnimationPatterns(Data myProvider) {
List<List> patterns = [];
......@@ -89,9 +87,8 @@ class BoardAnimate {
myProvider.updateAnimationInProgress(true);
Timer _timerAnimateBoard;
const interval = const Duration(milliseconds: 200);
_timerAnimateBoard = new Timer.periodic(
new Timer.periodic(
interval,
(Timer timer) {
if (_patternIndex == 0) {
......
......@@ -5,7 +5,6 @@ import '../provider/data.dart';
import '../utils/random_pick_grid.dart';
class BoardUtils {
static printGrid(List cells, List solvedCells) {
String stringValues = '0123456789ABCDEFG';
print('');
......@@ -24,15 +23,13 @@ class BoardUtils {
}
static Future<void> pickGrid(Data myProvider) async {
String grid;
String grid = '';
RandomPickGrid randomPickGrid;
randomPickGrid = RandomPickGrid();
await randomPickGrid.init(myProvider.level, myProvider.size);
await randomPickGrid.init(myProvider.parameterLevel, myProvider.parameterSize);
if (randomPickGrid.grid != null) {
grid = randomPickGrid.grid;
}
int blockSizeHorizontal = myProvider.blockSizeHorizontal;
int blockSizeVertical = myProvider.blockSizeVertical;
......@@ -107,21 +104,25 @@ class BoardUtils {
print('rotate board: ' + rotate);
switch (flip) {
case 'horizontal': {
case 'horizontal':
{
List transformedBoard = createEmptyBoard(boardSize);
for (var rowIndex = 0; rowIndex < boardSize; rowIndex++) {
for (var colIndex = 0; colIndex < boardSize; colIndex++) {
transformedBoard[rowIndex][colIndex].value = cells[boardSize - rowIndex - 1][colIndex].value;
transformedBoard[rowIndex][colIndex].value =
cells[boardSize - rowIndex - 1][colIndex].value;
}
}
cells = transformedBoard;
}
break;
case 'vertical': {
case 'vertical':
{
List transformedBoard = createEmptyBoard(boardSize);
for (var rowIndex = 0; rowIndex < boardSize; rowIndex++) {
for (var colIndex = 0; colIndex < boardSize; colIndex++) {
transformedBoard[rowIndex][colIndex].value = cells[rowIndex][boardSize - colIndex - 1].value;
transformedBoard[rowIndex][colIndex].value =
cells[rowIndex][boardSize - colIndex - 1].value;
}
}
cells = transformedBoard;
......@@ -130,21 +131,25 @@ class BoardUtils {
}
switch (rotate) {
case 'left': {
case 'left':
{
List transformedBoard = createEmptyBoard(boardSize);
for (var rowIndex = 0; rowIndex < boardSize; rowIndex++) {
for (var colIndex = 0; colIndex < boardSize; colIndex++) {
transformedBoard[rowIndex][colIndex].value = cells[colIndex][boardSize - rowIndex - 1].value;
transformedBoard[rowIndex][colIndex].value =
cells[colIndex][boardSize - rowIndex - 1].value;
}
}
cells = transformedBoard;
}
break;
case 'right': {
case 'right':
{
List transformedBoard = createEmptyBoard(boardSize);
for (var rowIndex = 0; rowIndex < boardSize; rowIndex++) {
for (var colIndex = 0; colIndex < boardSize; colIndex++) {
transformedBoard[rowIndex][colIndex].value = cells[boardSize - colIndex - 1][rowIndex].value;
transformedBoard[rowIndex][colIndex].value =
cells[boardSize - colIndex - 1][rowIndex].value;
}
}
cells = transformedBoard;
......@@ -155,7 +160,8 @@ class BoardUtils {
// Fix cells fixed states
for (var rowIndex = 0; rowIndex < boardSize; rowIndex++) {
for (var colIndex = 0; colIndex < boardSize; colIndex++) {
cells[rowIndex][colIndex].isFixed = (cells[rowIndex][colIndex].value != 0) ? true : false;
cells[rowIndex][colIndex].isFixed =
(cells[rowIndex][colIndex].value != 0) ? true : false;
}
}
......@@ -170,8 +176,6 @@ class BoardUtils {
int boardSize = blockSizeHorizontal * blockSizeVertical;
bool isSolved = true;
// (re)compute conflicts
BoardUtils.computeConflictsInBoard(myProvider);
......@@ -189,8 +193,9 @@ class BoardUtils {
return true;
}
static bool isValueAllowed(List cells, int blockSizeHorizontal, int blockSizeVertical, int candidateCol, int candidateRow, int candidateValue) {
if (candidateValue == 0) {
static bool isValueAllowed(List cells, int blockSizeHorizontal, int blockSizeVertical,
int? candidateCol, int? candidateRow, int candidateValue) {
if ((candidateCol == null) || (candidateRow == null) || (candidateValue == 0)) {
return true;
}
......@@ -336,7 +341,11 @@ class BoardUtils {
List distinctValues = values.toSet().toList();
if (values.length != distinctValues.length) {
print('block [' + blockCol.toString() + ',' + blockRow.toString() + '] contains duplicates');
print('block [' +
blockCol.toString() +
',' +
blockRow.toString() +
'] contains duplicates');
// Add blocks to cells in conflict
for (var rowInBlock = 0; rowInBlock < blockSizeVertical; rowInBlock++) {
for (var colInBlock = 0; colInBlock < blockSizeHorizontal; colInBlock++) {
......@@ -350,13 +359,15 @@ class BoardUtils {
}
}
static List getCellsWithWrongValue(List cells, List cellsSolved, int blockSizeHorizontal, int blockSizeVertical) {
static List getCellsWithWrongValue(
List cells, List cellsSolved, int blockSizeHorizontal, int blockSizeVertical) {
List cellsWithWrongValue = [];
int boardSize = blockSizeHorizontal * blockSizeVertical;
for (var row = 0; row < boardSize; row++) {
for (var col = 0; col < boardSize; col++) {
if (cells[row][col].value != 0 && cells[row][col].value != cellsSolved[row][col].value) {
if (cells[row][col].value != 0 &&
cells[row][col].value != cellsSolved[row][col].value) {
cellsWithWrongValue.add([col, row]);
}
}
......@@ -372,7 +383,9 @@ class BoardUtils {
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(cells, blockSizeHorizontal, blockSizeVertical, col, row, cells[row][col].value)) {
if (cells[row][col].conflictsCount != 0 &&
!BoardUtils.isValueAllowed(cells, blockSizeHorizontal, blockSizeVertical, col,
row, cells[row][col].value)) {
conflictingCells.add([col, row]);
}
}
......@@ -382,7 +395,8 @@ class BoardUtils {
return conflictingCells;
}
static List getCellsWithUniqueAvailableValue(List cells, int blockSizeHorizontal, int blockSizeVertical) {
static List getCellsWithUniqueAvailableValue(
List cells, int blockSizeHorizontal, int blockSizeVertical) {
List candidateCells = [];
int boardSize = blockSizeHorizontal * blockSizeVertical;
......@@ -392,7 +406,8 @@ class BoardUtils {
int allowedValuesCount = 0;
int candidateValue = 0;
for (var value = 1; value <= boardSize; value++) {
if (BoardUtils.isValueAllowed(cells, blockSizeHorizontal, blockSizeVertical, col, row, value)) {
if (BoardUtils.isValueAllowed(
cells, blockSizeHorizontal, blockSizeVertical, col, row, value)) {
candidateValue = value;
allowedValuesCount++;
}
......@@ -413,7 +428,8 @@ class BoardUtils {
int blockSizeVertical = myProvider.blockSizeVertical;
do {
List cellsWithUniqueAvailableValue = BoardUtils.getCellsWithUniqueAvailableValue(cells, blockSizeHorizontal, blockSizeVertical);
List cellsWithUniqueAvailableValue = BoardUtils.getCellsWithUniqueAvailableValue(
cells, blockSizeHorizontal, blockSizeVertical);
if (cellsWithUniqueAvailableValue.length == 0) {
break;
}
......@@ -427,5 +443,4 @@ class BoardUtils {
return cells;
}
}
import '../provider/data.dart';
import '../utils/board_animate.dart';
import '../utils/board_utils.dart';
import '../utils/game_utils.dart';
class GameUtils {
static Future<void> resetGame(Data myProvider) async {
myProvider.updateGameIsRunning(false);
}
static Future<void> startGame(Data myProvider) async {
myProvider.updateSize(myProvider.size);
myProvider.updateParameterSize(myProvider.parameterSize);
myProvider.updateGameIsRunning(true);
myProvider.resetGivenTipsCount();
myProvider.shuffleCellValues();
myProvider.updateCells(BoardUtils.createEmptyBoard(myProvider.blockSizeHorizontal * myProvider.blockSizeVertical));
myProvider.updateCells(BoardUtils.createEmptyBoard(
myProvider.blockSizeHorizontal * myProvider.blockSizeVertical));
BoardUtils.pickGrid(myProvider);
BoardAnimate.startAnimation(myProvider, 'start');
}
......@@ -36,21 +35,24 @@ class GameUtils {
int blockSizeVertical = myProvider.blockSizeVertical;
// pick one of wrong value cells, if found
List wrongValueCells = BoardUtils.getCellsWithWrongValue(cells, myProvider.cellsSolved, blockSizeHorizontal, blockSizeVertical);
List wrongValueCells = BoardUtils.getCellsWithWrongValue(
cells, myProvider.cellsSolved, blockSizeHorizontal, blockSizeVertical);
if (wrongValueCells.length != 0) {
GameUtils.pickRandomFromList(myProvider, wrongValueCells);
return;
}
// pick one of conflicting cells, if found
List conflictingCells = BoardUtils.getCellsWithUniqueAvailableValue(cells, blockSizeHorizontal, blockSizeVertical);
List conflictingCells = BoardUtils.getCellsWithUniqueAvailableValue(
cells, blockSizeHorizontal, blockSizeVertical);
if (conflictingCells.length != 0) {
GameUtils.pickRandomFromList(myProvider, conflictingCells);
return;
}
// pick one form cells with unique non-conflicting candidate value
List candidateCells = BoardUtils.getCellsWithUniqueAvailableValue(cells, blockSizeHorizontal, blockSizeVertical);
List candidateCells = BoardUtils.getCellsWithUniqueAvailableValue(
cells, blockSizeHorizontal, blockSizeVertical);
if (candidateCells.length != 0) {
GameUtils.pickRandomFromList(myProvider, candidateCells);
return;
......@@ -78,17 +80,18 @@ class GameUtils {
// ensure there is only one eligible value for this cell
int allowedValuesCount = 0;
for (var value = 1; value <= boardSize; value++) {
if (BoardUtils.isValueAllowed(cells, blockSizeHorizontal, blockSizeVertical, myProvider.currentCellCol, myProvider.currentCellRow, value)) {
if (BoardUtils.isValueAllowed(cells, blockSizeHorizontal, blockSizeVertical,
myProvider.currentCellCol, myProvider.currentCellRow, value)) {
allowedValuesCount++;
eligibleValue = value;
}
}
myProvider.updateCellValue(myProvider.currentCellCol, myProvider.currentCellRow, allowedValuesCount == 1 ? eligibleValue : 0);
myProvider.updateCellValue(myProvider.currentCellCol, myProvider.currentCellRow,
allowedValuesCount == 1 ? eligibleValue : 0);
myProvider.selectCell(null, null);
if (BoardUtils.checkBoardIsSolved(myProvider)) {
BoardAnimate.startAnimation(myProvider, 'win');
}
}
}
......@@ -4,27 +4,27 @@ import 'package:flutter/services.dart';
class RandomPickGrid {
RandomPickGrid();
String _grid;
String _grid = '';
init(String difficulty, String size) async {
init(String level, String size) async {
_grid = '';
await gridFromLocalFile(difficulty, size);
await gridFromLocalFile(level, size);
}
Future<void> gridFromLocalFile(String difficulty, String size) async {
Future<void> gridFromLocalFile(String level, String size) async {
// Get global grids list
List grids;
List grids = [];
try {
String jsonString = await rootBundle.loadString('assets/files/templates.json');
final jsonResponse = await json.decode(jsonString);
grids = jsonResponse['templates'][size][difficulty];
grids = jsonResponse['templates'][size][level];
} catch (e) {
print("$e");
}
// Check we have enough grids
if (grids.length < 1) {
print('Not enough grids [' + size + ', ' + difficulty + '] in templates.');
print('Not enough grids [' + size + ', ' + level + '] in templates.');
}
// Randomize grids list
......
......@@ -14,7 +14,7 @@ packages:
name: badges
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
version: "2.0.3"
boolean_selector:
dependency: transitive
description:
......@@ -63,7 +63,7 @@ packages:
name: ffi
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.2"
version: "2.0.1"
file:
dependency: transitive
description:
......@@ -127,7 +127,7 @@ packages:
name: overlay_support
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.1"
version: "2.0.1"
path:
dependency: transitive
description:
......@@ -141,21 +141,21 @@ packages:
name: path_provider_linux
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.5"
version: "2.1.7"
path_provider_platform_interface:
dependency: transitive
description:
name: path_provider_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.3"
version: "2.0.4"
path_provider_windows:
dependency: transitive
description:
name: path_provider_windows
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.5"
version: "2.1.0"
platform:
dependency: transitive
description:
......@@ -183,42 +183,42 @@ packages:
name: provider
url: "https://pub.dartlang.org"
source: hosted
version: "6.0.2"
version: "6.0.3"
shared_preferences:
dependency: "direct main"
description:
name: shared_preferences
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.13"
version: "2.0.15"
shared_preferences_android:
dependency: transitive
description:
name: shared_preferences_android
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.11"
version: "2.0.12"
shared_preferences_ios:
dependency: transitive
description:
name: shared_preferences_ios
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.10"
version: "2.1.1"
shared_preferences_linux:
dependency: transitive
description:
name: shared_preferences_linux
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
version: "2.1.1"
shared_preferences_macos:
dependency: transitive
description:
name: shared_preferences_macos
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.3"
version: "2.0.4"
shared_preferences_platform_interface:
dependency: transitive
description:
......@@ -232,14 +232,14 @@ packages:
name: shared_preferences_web
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.3"
version: "2.0.4"
shared_preferences_windows:
dependency: transitive
description:
name: shared_preferences_windows
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
version: "2.1.1"
sky_engine:
dependency: transitive
description: flutter
......@@ -300,7 +300,7 @@ packages:
name: win32
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.0"
version: "2.7.0"
xdg_directories:
dependency: transitive
description:
......@@ -309,5 +309,5 @@ packages:
source: hosted
version: "0.2.0+1"
sdks:
dart: ">=2.17.0-0 <3.0.0"
flutter: ">=2.8.0"
dart: ">=2.17.0 <3.0.0"
flutter: ">=3.0.0"
......@@ -4,7 +4,7 @@ publish_to: 'none'
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
sdk: ">=2.16.1 <3.0.0"
dependencies:
flutter:
......@@ -12,7 +12,7 @@ dependencies:
provider: ^6.0.2
badges: ^2.0.1
shared_preferences: ^2.0.6
overlay_support: ^1.0.0
overlay_support: ^2.0.1
dev_dependencies:
flutter_test:
......
// This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility that Flutter provides. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:sudoku/main.dart';
void main() {
}