This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const cell = { | |
| value: 9, | |
| notes: Set([1,2,3]), | |
| prefilled: false | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Game extends Compoent { | |
| ... | |
| getSelectedCell() { | |
| const { board } = this.state; | |
| const selected = board.get('selected'); | |
| return selected && board.get('puzzle').getIn([selected.x, selected.y]); | |
| } | |
| selectCell = (x, y) => { | |
| let { board } = this.state |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| getSelectedCell() { | |
| const { board } = this.state | |
| const selected = board.get('selected') | |
| return selected && board.get('puzzle').getIn([selected.x,selected.y]) | |
| } | |
| renderCell(cell, x, y) { | |
| const { board } = this.state | |
| const selected = this.getSelectedCell() | |
| const sameValue = selected && selected.get('value') && value === selected.get('value') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const puzzle = [ | |
| [cell, cell, cell, cell, cell, cell, cell, cell, cell], | |
| [cell, cell, cell, cell, cell, cell, cell, cell, cell], | |
| [cell, cell, cell, cell, cell, cell, cell, cell, cell], | |
| [cell, cell, cell, cell, cell, cell, cell, cell, cell], | |
| ... | |
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { List, fromJS } from 'immutable'; | |
| /** | |
| * make size 9 array of 0s | |
| * @returns {Array} | |
| */ | |
| function makeCountObject() { | |
| const countObj = []; | |
| for (let i = 0; i < 10; i += 1) countObj.push(0); | |
| return countObj; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export function isPeer(a, b) { | |
| if (!a || !b) return false; | |
| const squareA = ((Math.floor(a.x / 3)) * 3) + Math.floor(a.y / 3); | |
| const squareB = ((Math.floor(b.x / 3)) * 3) + Math.floor(b.y / 3); | |
| return a.x === b.x || a.y === b.y || squareA === squareB; | |
| } | |
| class Game extends Compoent { | |
| ... | |
| isConflict(i, j) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const NumberControl = ({ number, onClick, completionPercentage }) => ( | |
| <div | |
| key={number} | |
| className="number" | |
| onClick={onClick} | |
| > | |
| <div>{number}</div> | |
| <CirclularProgress percent={completionPercentage} /> | |
| <style jsx>{NumberControlStyle}</style> | |
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Set } from 'immutable'; | |
| /** | |
| * give the coordinate update the current board with a number choice | |
| * @param x | |
| * @param y | |
| * @param number | |
| * @param fill whether to set or unset | |
| * @param board the immutable board given to change | |
| */ | |
| function updateBoardWithNumber({ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function getNumberOfGroupsAssignedForNumber(number, groups) { | |
| return groups.reduce((accumulator, row) => | |
| accumulator + (row.get(number) > 0 ? 1 : 0), 0); | |
| } | |
| class Game extends Compoent { | |
| ... | |
| // get the min between its completion in rows, columns and squares. | |
| getNumberValueCount(number) { | |
| const rows = this.state.board.getIn(['choices', 'rows']); | |
| const columns = this.state.board.getIn(['choices', 'columns']); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Game extends Compoent { | |
| ... | |
| renderNumberControl() { | |
| const selectedCell = this.getSelectedCell(); | |
| const prefilled = selectedCell && selectedCell.get('prefilled'); | |
| return ( | |
| <div className="control"> | |
| {range(9).map((i) => { | |
| const number = i + 1; | |
| // handles binding single click and double click callbacks |