Commit 933c4b58 authored by Yannick Li's avatar Yannick Li
Browse files

Rename setMVMap to initForm and remove firstCellOfBlock

parent 86275ced
...@@ -132,7 +132,7 @@ class Grid extends React.Component<IGridProps, IGridState> { ...@@ -132,7 +132,7 @@ class Grid extends React.Component<IGridProps, IGridState> {
* Set the MVMap with the given values. * Set the MVMap with the given values.
* @param values to be set in the MVMap. * @param values to be set in the MVMap.
*/ */
setMVMap(values:any) { initForm(values:any) {
let cells = this.state.cells; let cells = this.state.cells;
for (let i = 0; i < 81; i++) { for (let i = 0; i < 81; i++) {
cells[i][0] = values[i]; cells[i][0] = values[i];
...@@ -210,7 +210,7 @@ class Grid extends React.Component<IGridProps, IGridState> { ...@@ -210,7 +210,7 @@ class Grid extends React.Component<IGridProps, IGridState> {
render() { render() {
return ( return (
<div className="sudoku"> <div className="sudoku">
<div><button onClick={this.setMVMap.bind(this, generateStaticGrid())}>Reset</button></div><br /> <div><button onClick={this.initForm.bind(this, generateStaticGrid())}>Reset</button></div><br />
<div><button onClick={() => this.switchConnection()}>{this.state.isConnected ? "Disconnect" : "Connect"}</button></div><br /> <div><button onClick={() => this.switchConnection()}>{this.state.isConnected ? "Disconnect" : "Connect"}</button></div><br />
<table className="grid"> <table className="grid">
<tbody> <tbody>
...@@ -411,26 +411,14 @@ function checkArray(array:any) { ...@@ -411,26 +411,14 @@ function checkArray(array:any) {
return true return true
} }
/**
* Return the position of the first cell of a block.
* @param block The block number of which we want the position.
*/
function firstCellOfBlock(block:number) {
assert.ok(block >= 0 && block < 9)
let line = Math.floor(block / 3) * 3
let column = (block % 3) * 3
return [line,column]
}
/** /**
* Return an array containing all cell index of a block. * Return an array containing all cell index of a block.
* @param block The block number of which we want the cells index. * @param block The block number of which we want the cells index.
*/ */
function blockIndex(block: number) { function blockIndex(block: number) {
assert.ok(block >= 0 && block < 9) assert.ok(block >= 0 && block < 9)
let blocklc = firstCellOfBlock(block) let line = Math.floor(block / 3) * 3
let line = blocklc[0] let col = (block % 3) * 3
let col = blocklc[1]
let index = [ line * 9 + col, line * 9 + col + 1, line * 9 + col + 2, let index = [ line * 9 + col, line * 9 + col + 1, line * 9 + col + 2,
(line + 1) * 9 + col, (line + 1) * 9 + col + 1, (line + 1) * 9 + col + 2, (line + 1) * 9 + col, (line + 1) * 9 + col + 1, (line + 1) * 9 + col + 2,
(line + 2) * 9 + col, (line + 2) * 9 + col + 1, (line + 2) * 9 + col + 2] (line + 2) * 9 + col, (line + 2) * 9 + col + 1, (line + 2) * 9 + col + 2]
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment