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

Avoid print calls in production code

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