Skip to content
Snippets Groups Projects
Commit 130557ea authored by Benoît Harrault's avatar Benoît Harrault
Browse files

Merge branch '77-avoid-print-calls-in-production-code' into 'master'

Resolve "Avoid print calls in production code"

Closes #77

See merge request !71
parents 9006f4a6 63015cc9
No related branches found
No related tags found
1 merge request!71Resolve "Avoid print calls in production code"
Pipeline #5382 passed
org.gradle.jvmargs=-Xmx1536M org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true android.useAndroidX=true
android.enableJetifier=true android.enableJetifier=true
app.versionName=0.1.14 app.versionName=0.1.15
app.versionCode=63 app.versionCode=64
Avoid print calls in production code.
Supprime les appels à print dans le code de production.
...@@ -5,15 +5,15 @@ import sys ...@@ -5,15 +5,15 @@ import sys
from random import randint, shuffle from random import randint, shuffle
if (len(sys.argv) != 3): if (len(sys.argv) != 3):
print('Usage: generate.py block-size difficulty') printlog('Usage: generate.py block-size difficulty')
print('block-size: [2x2|3x2|3x3|4x4]') printlog('block-size: [2x2|3x2|3x3|4x4]')
print('difficulty: [easy|medium|hard|nightmare]') printlog('difficulty: [easy|medium|hard|nightmare]')
exit() exit()
blocksize, difficulty = sys.argv[1], sys.argv[2] blocksize, difficulty = sys.argv[1], sys.argv[2]
if blocksize not in ['2x2', '3x2', '3x3', '4x4']: if blocksize not in ['2x2', '3x2', '3x3', '4x4']:
print('wrong size given') printlog('wrong size given')
exit() exit()
splitted_blocksize = blocksize.split('x') splitted_blocksize = blocksize.split('x')
...@@ -23,7 +23,7 @@ size_vertical = int(splitted_blocksize[1]) ...@@ -23,7 +23,7 @@ size_vertical = int(splitted_blocksize[1])
boardSize = size_horizontal * size_vertical boardSize = size_horizontal * size_vertical
if difficulty not in ['easy', 'medium', 'hard', 'nightmare']: if difficulty not in ['easy', 'medium', 'hard', 'nightmare']:
print('wrong difficulty given') printlog('wrong difficulty given')
exit() exit()
debugFillGrid = False debugFillGrid = False
......
...@@ -14,14 +14,14 @@ ...@@ -14,14 +14,14 @@
import sys import sys
if (len(sys.argv) != 3): if (len(sys.argv) != 3):
print('Usage: solve.py block-size grid') printlog('Usage: solve.py block-size grid')
print('block-size: [2x2|3x2|3x3|4x4]') printlog('block-size: [2x2|3x2|3x3|4x4]')
exit() exit()
blocksize, gridTemplate = sys.argv[1], sys.argv[2] blocksize, gridTemplate = sys.argv[1], sys.argv[2]
if blocksize not in ['2x2', '3x2', '3x3', '4x4']: if blocksize not in ['2x2', '3x2', '3x3', '4x4']:
print('wrong size given') printlog('wrong size given')
exit() exit()
splitted_blocksize = blocksize.split('x') splitted_blocksize = blocksize.split('x')
...@@ -31,7 +31,7 @@ size_vertical = int(splitted_blocksize[1]) ...@@ -31,7 +31,7 @@ size_vertical = int(splitted_blocksize[1])
boardSize = size_horizontal * size_vertical boardSize = size_horizontal * size_vertical
if (len(gridTemplate) != boardSize * boardSize): if (len(gridTemplate) != boardSize * boardSize):
print('wrong grid length (should be ' + str(boardSize * boardSize) + ')') printlog('wrong grid length (should be ' + str(boardSize * boardSize) + ')')
exit() exit()
debugSolveGrid = False debugSolveGrid = False
...@@ -112,7 +112,7 @@ def hasConflict(grid, size_horizontal, size_vertical): ...@@ -112,7 +112,7 @@ def hasConflict(grid, size_horizontal, size_vertical):
if value != 0: if value != 0:
values.append(value) values.append(value)
if containsDuplicates(values): if containsDuplicates(values):
# print('Horizontal conflict found') # printlog('Horizontal conflict found')
return True return True
# Check vertical conflicts # Check vertical conflicts
...@@ -123,7 +123,7 @@ def hasConflict(grid, size_horizontal, size_vertical): ...@@ -123,7 +123,7 @@ def hasConflict(grid, size_horizontal, size_vertical):
if value != 0: if value != 0:
values.append(value) values.append(value)
if containsDuplicates(values): if containsDuplicates(values):
# print('Vertical conflict found') # printlog('Vertical conflict found')
return True return True
# Check sub-blocks conflicts # Check sub-blocks conflicts
...@@ -139,7 +139,7 @@ def hasConflict(grid, size_horizontal, size_vertical): ...@@ -139,7 +139,7 @@ def hasConflict(grid, size_horizontal, size_vertical):
if value != 0: if value != 0:
values.append(value) values.append(value)
if containsDuplicates(values): if containsDuplicates(values):
# print('Sub-block conflict found') # printlog('Sub-block conflict found')
return True return True
return False return False
...@@ -176,18 +176,18 @@ def solve(grid, size_horizontal, size_vertical): ...@@ -176,18 +176,18 @@ def solve(grid, size_horizontal, size_vertical):
break break
if debugSolveGrid: if debugSolveGrid:
print('===================================') printlog('===================================')
print('Iteration: ' + str(iterations)) printlog('Iteration: ' + str(iterations))
# Get first/next cell with only one allowed value # Get first/next cell with only one allowed value
candidates = [] candidates = []
if debugSolveGrid: if debugSolveGrid:
print('Searching for empty cells...') printlog('Searching for empty cells...')
for row in range(len(grid)): for row in range(len(grid)):
for col in range(len(grid[row])): for col in range(len(grid[row])):
if grid[row][col] == 0: if grid[row][col] == 0:
if debugSolveGrid: if debugSolveGrid:
print( printlog(
'Found empty cell [' + str(col) + ',' + str(row) + ']') 'Found empty cell [' + str(col) + ',' + str(row) + ']')
candidates.append([row, col]) candidates.append([row, col])
...@@ -198,16 +198,16 @@ def solve(grid, size_horizontal, size_vertical): ...@@ -198,16 +198,16 @@ def solve(grid, size_horizontal, size_vertical):
allowedValues = findAllowedValuesForCell( allowedValues = findAllowedValuesForCell(
grid, size_horizontal, size_vertical, candidateRow, candidateCol) grid, size_horizontal, size_vertical, candidateRow, candidateCol)
if debugSolveGrid: if debugSolveGrid:
print('Allowed values for cell [' + str(candidateCol) + ',' + str( printlog('Allowed values for cell [' + str(candidateCol) + ',' + str(
candidateRow) + ']: ' + str(allowedValues)) candidateRow) + ']: ' + str(allowedValues))
if len(allowedValues) != 1: if len(allowedValues) != 1:
if debugSolveGrid: if debugSolveGrid:
print(' Non unique allowed value for cell. Skip to next cell') printlog(' Non unique allowed value for cell. Skip to next cell')
else: else:
value = allowedValues[0] value = allowedValues[0]
grid[candidateRow][candidateCol] = value grid[candidateRow][candidateCol] = value
if debugSolveGrid: if debugSolveGrid:
print(' Found unique allowed value for cell [' + str( printlog(' Found unique allowed value for cell [' + str(
candidateCol) + ',' + str(candidateRow) + ']: ' + str(value)) candidateCol) + ',' + str(candidateRow) + ']: ' + str(value))
drawGrid(grid) drawGrid(grid)
......
...@@ -4,6 +4,7 @@ import 'package:flutter/foundation.dart'; ...@@ -4,6 +4,7 @@ import 'package:flutter/foundation.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'package:sudoku/entities/cell.dart'; import 'package:sudoku/entities/cell.dart';
import 'package:sudoku/utils/tools.dart';
class Data extends ChangeNotifier { class Data extends ChangeNotifier {
// Configuration available values // Configuration available values
...@@ -203,7 +204,7 @@ class Data extends ChangeNotifier { ...@@ -203,7 +204,7 @@ class Data extends ChangeNotifier {
if (_shufflableSkins.contains(_parameterSkin)) { if (_shufflableSkins.contains(_parameterSkin)) {
values.shuffle(); values.shuffle();
print('Shuffled tiles values: $values'); printlog('Shuffled tiles values: $values');
} }
_shuffledCellValues = values; _shuffledCellValues = values;
......
...@@ -3,12 +3,13 @@ import 'dart:math'; ...@@ -3,12 +3,13 @@ import 'dart:math';
import 'package:sudoku/entities/cell.dart'; import 'package:sudoku/entities/cell.dart';
import 'package:sudoku/provider/data.dart'; import 'package:sudoku/provider/data.dart';
import 'package:sudoku/utils/random_pick_grid.dart'; import 'package:sudoku/utils/random_pick_grid.dart';
import 'package:sudoku/utils/tools.dart';
class BoardUtils { class BoardUtils {
static printGrid(List<List<Cell>> cells, List<List<Cell>> solvedCells) { static printGrid(List<List<Cell>> cells, List<List<Cell>> solvedCells) {
String stringValues = '0123456789ABCDEFG'; String stringValues = '0123456789ABCDEFG';
print(''); printlog('');
print('-------'); printlog('-------');
for (int rowIndex = 0; rowIndex < cells.length; rowIndex++) { for (int rowIndex = 0; rowIndex < cells.length; rowIndex++) {
String row = ''; String row = '';
String rowSolved = ''; String rowSolved = '';
...@@ -16,10 +17,10 @@ class BoardUtils { ...@@ -16,10 +17,10 @@ class BoardUtils {
row += stringValues[cells[rowIndex][colIndex].value]; row += stringValues[cells[rowIndex][colIndex].value];
rowSolved += stringValues[solvedCells[rowIndex][colIndex].value]; rowSolved += stringValues[solvedCells[rowIndex][colIndex].value];
} }
print('$row | $rowSolved'); printlog('$row | $rowSolved');
} }
print('-------'); printlog('-------');
print(''); printlog('');
} }
static Future<void> pickGrid(Data myProvider) async { static Future<void> pickGrid(Data myProvider) async {
...@@ -35,7 +36,7 @@ class BoardUtils { ...@@ -35,7 +36,7 @@ class BoardUtils {
final int blockSizeVertical = myProvider.blockSizeVertical; final int blockSizeVertical = myProvider.blockSizeVertical;
if (grid.length == pow(blockSizeHorizontal * blockSizeVertical, 2)) { if (grid.length == pow(blockSizeHorizontal * blockSizeVertical, 2)) {
print('Picked grid from template: $grid'); printlog('Picked grid from template: $grid');
bool isSymetric = (blockSizeHorizontal == blockSizeVertical); bool isSymetric = (blockSizeHorizontal == blockSizeVertical);
myProvider.updateCells(BoardUtils.createBoardFromTemplate(grid, isSymetric)); myProvider.updateCells(BoardUtils.createBoardFromTemplate(grid, isSymetric));
myProvider.updateCellsSolved(BoardUtils.getSolvedGrid(myProvider)); myProvider.updateCellsSolved(BoardUtils.getSolvedGrid(myProvider));
...@@ -124,8 +125,8 @@ class BoardUtils { ...@@ -124,8 +125,8 @@ class BoardUtils {
final String flip = allowedFlip[rand.nextInt(allowedFlip.length)]; final String flip = allowedFlip[rand.nextInt(allowedFlip.length)];
final String rotate = allowedRotate[rand.nextInt(allowedRotate.length)]; final String rotate = allowedRotate[rand.nextInt(allowedRotate.length)];
print('flip board: $flip'); printlog('flip board: $flip');
print('rotate board: $rotate'); printlog('rotate board: $rotate');
switch (flip) { switch (flip) {
case 'horizontal': case 'horizontal':
...@@ -212,7 +213,7 @@ class BoardUtils { ...@@ -212,7 +213,7 @@ class BoardUtils {
} }
} }
print('-> ok sudoku solved!'); printlog('-> ok sudoku solved!');
return true; return true;
} }
...@@ -324,7 +325,7 @@ class BoardUtils { ...@@ -324,7 +325,7 @@ class BoardUtils {
} }
final List<int> distinctValues = values.toSet().toList(); final List<int> distinctValues = values.toSet().toList();
if (values.length != distinctValues.length) { if (values.length != distinctValues.length) {
print('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++) {
cells[row][col].conflictsCount++; cells[row][col].conflictsCount++;
...@@ -343,7 +344,7 @@ class BoardUtils { ...@@ -343,7 +344,7 @@ class BoardUtils {
} }
final List<int> distinctValues = values.toSet().toList(); final List<int> distinctValues = values.toSet().toList();
if (values.length != distinctValues.length) { if (values.length != distinctValues.length) {
print('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++) {
cells[row][col].conflictsCount++; cells[row][col].conflictsCount++;
...@@ -371,7 +372,7 @@ class BoardUtils { ...@@ -371,7 +372,7 @@ class BoardUtils {
List<int> distinctValues = values.toSet().toList(); List<int> distinctValues = values.toSet().toList();
if (values.length != distinctValues.length) { if (values.length != distinctValues.length) {
print('block [$blockCol,$blockRow] contains duplicates'); printlog('block [$blockCol,$blockRow] contains duplicates');
// Add blocks to cells in conflict // Add blocks to cells in conflict
for (int rowInBlock = 0; rowInBlock < blockSizeVertical; rowInBlock++) { for (int rowInBlock = 0; rowInBlock < blockSizeVertical; rowInBlock++) {
for (int colInBlock = 0; colInBlock < blockSizeHorizontal; colInBlock++) { for (int colInBlock = 0; colInBlock < blockSizeHorizontal; colInBlock++) {
......
...@@ -2,6 +2,7 @@ import 'package:sudoku/entities/cell.dart'; ...@@ -2,6 +2,7 @@ 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';
import 'package:sudoku/utils/tools.dart';
class GameUtils { class GameUtils {
static Future<void> quitGame(Data myProvider) async { static Future<void> quitGame(Data myProvider) async {
...@@ -43,7 +44,7 @@ class GameUtils { ...@@ -43,7 +44,7 @@ class GameUtils {
BoardUtils.createBoardFromSavedState(myProvider, savedState['boardValues'])); BoardUtils.createBoardFromSavedState(myProvider, savedState['boardValues']));
myProvider.updateGameIsRunning(true); myProvider.updateGameIsRunning(true);
} catch (e) { } catch (e) {
print('Failed to resume game. Will start new one instead.'); printlog('Failed to resume game. Will start new one instead.');
myProvider.resetCurrentSavedState(); myProvider.resetCurrentSavedState();
myProvider.initParametersValues(); myProvider.initParametersValues();
startNewGame(myProvider); startNewGame(myProvider);
......
import 'dart:convert'; import 'dart:convert';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:sudoku/utils/tools.dart';
class RandomPickGrid { class RandomPickGrid {
RandomPickGrid(); RandomPickGrid();
...@@ -19,12 +22,12 @@ class RandomPickGrid { ...@@ -19,12 +22,12 @@ class RandomPickGrid {
final jsonResponse = await json.decode(jsonString); final jsonResponse = await json.decode(jsonString);
grids = jsonResponse['templates'][size][level]; grids = jsonResponse['templates'][size][level];
} catch (e) { } catch (e) {
print("$e"); printlog("$e");
} }
// Check we have enough grids // Check we have enough grids
if (grids.isEmpty) { if (grids.isEmpty) {
print('Not enough grids [$size, $level] in templates.'); printlog('Not enough grids [$size, $level] in templates.');
} }
// Randomize grids list // Randomize grids list
......
import 'package:flutter/foundation.dart';
void printlog(String message) {
if (!kReleaseMode) {
debugPrint(message);
}
}
...@@ -159,10 +159,10 @@ packages: ...@@ -159,10 +159,10 @@ packages:
dependency: "direct main" dependency: "direct main"
description: description:
name: provider name: provider
sha256: "9a96a0a19b594dbc5bf0f1f27d2bc67d5f95957359b461cd9feb44ed6ae75096" sha256: c8a055ee5ce3fd98d6fc872478b03823ffdb448699c6ebdbbc71d59b596fd48c
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "6.1.1" version: "6.1.2"
shared_preferences: shared_preferences:
dependency: "direct main" dependency: "direct main"
description: description:
......
name: sudoku name: sudoku
description: A sudoku game application. description: A sudoku game application.
publish_to: 'none' publish_to: 'none'
version: 0.1.14+63 version: 0.1.15+64
environment: environment:
sdk: '^3.0.0' sdk: '^3.0.0'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment