Skip to content

Commit

Permalink
Add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Spencer committed Jul 16, 2020
1 parent 4694994 commit 0bf8546
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
21 changes: 9 additions & 12 deletions lib/src/game/board/SudokuGameboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'SudokuChunk.dart';
class SudokuGameboard {
final _chunkMap = <Pair, SudokuChunk>{};

SudokuGameboard.generator(var numbersToRemove) {
SudokuGameboard(var numbersToRemove) {
var generator = SudokuGenerator(numbersToRemove);
var unshuffledMap = <Pair, SudokuChunk>{};

Expand All @@ -30,12 +30,10 @@ class SudokuGameboard {
var pairsOfChunks = columnPairList(gameboardCol);
var pairsOfSquares = columnPairList(chunkCol);

final chunkList = pairsOfChunks.map((pair) =>
sudokuChunks[pair]).toList();
final chunkList = pairsOfChunks.map((pair) => sudokuChunks[pair]).toList();

for(var chunk in chunkList) {
colValues.addAll(
pairsOfSquares.map((pair) =>
colValues.addAll(pairsOfSquares.map((pair) =>
chunk.sudokuSquares[pair].value));
}
return colValues;
Expand All @@ -51,16 +49,15 @@ class SudokuGameboard {
var pairsOfChunks = rowPairList(gameboardRow);
var pairsOfSquares = rowPairList(chunkRow);

final chunkList = pairsOfChunks.map((pair) =>
sudokuChunks[pair]).toList();
final chunkList = pairsOfChunks.map((pair) => sudokuChunks[pair]).toList();

for(var chunk in chunkList) {
rowValues.addAll(
pairsOfSquares.map((pair) =>
rowValues.addAll(pairsOfSquares.map((pair) =>
chunk.sudokuSquares[pair].value));
}
return rowValues;
}

/// Given a column index, 1 - 9, create a List of Pairs that compose the given column.
List<Pair> columnPairList(int index) {
var pairs = <Pair>[];
Expand Down Expand Up @@ -89,8 +86,8 @@ class SudokuGameboard {
return chunkData;
}

///Given a particular row/column index, 1 - 9, return the equivalent index
///within the specific chunk.
/// Given a particular row/column index, 1 - 9, return the equivalent index of
/// where it's contained within the chunk.
int getChunkIndex(int index) {
var result = (index % 3) - 1;
if(result == -1) {
Expand All @@ -99,7 +96,7 @@ class SudokuGameboard {
return result;
}

///Given a particular row/column index, 1 - 9, return the row/column index
///Given a particular row/column index, 1 - 9, return the equivalent index of
///where it's contained within the game board.
int getEquivalentBoardIndex(int index) {
var result = ((index / 3) - 1).ceil();
Expand Down
7 changes: 5 additions & 2 deletions lib/src/game/logic/GameManager.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import 'package:collection/collection.dart';

import 'package:sudoku/src/game/board/Pair.dart';
import 'package:sudoku/src/game/board/SudokuGameboard.dart';

///The GameManager class handles the state of the Sudoku game.
class GameManager {
/// Gets the game board.
SudokuGameboard get board => _board;
final _board = SudokuGameboard.generator(1);
final _board = SudokuGameboard(59);

/// Given a selection of 9 Integers that represents a Sudoku row, column, or
/// chunk, determine whether or not it's valid. The array must contain the
/// numbers 1 through 9 with no duplicates.
bool validSelection(List<int> selection) {
if (selection.contains(null)) {
return false;
Expand All @@ -18,6 +20,7 @@ class GameManager {
return ListEquality().equals(selection, expectedValue);
}

/// Check whether or not the user has completed the Sudoku puzzle.
bool checkForCompletion() {
for(var a = 0; a < board.sudokuChunks.values.length; a++) {
if(!validSelection(board.row(a).toList())
Expand Down
2 changes: 0 additions & 2 deletions lib/src/game/logic/SudokuGenerator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ class SudokuGenerator {
_numbers[randRow][randCol] = null;
numbersToRemove--;
}

print('numbers: $_numbers');
}

/// The rotate method takes a row of Sudoku numbers and shifts them to be used
Expand Down
1 change: 1 addition & 0 deletions lib/src/routes/route_paths.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:angular_router/angular_router.dart';

/// Initializes all route paths in the application.
class RoutePaths {
static final sudoku = RoutePath(path: 'sudoku');
}
3 changes: 2 additions & 1 deletion lib/src/routes/routes.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import 'package:angular_router/angular_router.dart';

import 'route_paths.dart';
import 'package:sudoku/src/components/sudoku_board_component.template.dart' as sudoku_board_template;
import 'route_paths.dart';

class Routes {
static final sudoku = RouteDefinition(
routePath: RoutePaths.sudoku,
Expand Down

0 comments on commit 0bf8546

Please sign in to comment.