|
|
@@ -1,179 +1,132 @@
|
|
1
|
1
|
import React from 'react';
|
|
2
|
2
|
import ReactDOM from 'react-dom';
|
|
3
|
3
|
import './index.css';
|
|
4
|
|
-import {List, fromJS} from 'immutable';
|
|
5
|
4
|
|
|
6
|
|
-function makeCountObject() {
|
|
7
|
|
- const countObj = [];
|
|
8
|
|
- for (let i = 0; i < 10; i++) countObj.push(0);
|
|
9
|
|
- return countObj;
|
|
10
|
|
-}
|
|
11
|
|
-
|
|
12
|
|
-function makeBoard({puzzle}) {
|
|
13
|
|
- const rows = Array.from(Array(9).keys()).map(() => makeCountObject());
|
|
14
|
|
- const columns = Array.from(Array(9).keys()).map(() => makeCountObject());
|
|
15
|
|
- const squares = Array.from(Array(9).keys()).map(() => makeCountObject());
|
|
16
|
|
- const result = puzzle.map((row, i) => (
|
|
17
|
|
- row.map((cell, j) => {
|
|
18
|
|
- if (cell) {
|
|
19
|
|
- rows[i][cell] += 1;
|
|
20
|
|
- comlumns[j][cell] += 1;
|
|
21
|
|
- squares[((Math.floor( i / 3 )) * 3) + Math.floor( j / 3 )][cell] += 1;
|
|
22
|
|
- }
|
|
23
|
|
- return {
|
|
24
|
|
- value: puzzle[i][j] > 0 ? puzzle[i][j] : null,
|
|
25
|
|
- prefelled: !!puzzle[i][j],
|
|
26
|
|
- };
|
|
27
|
|
- })
|
|
28
|
|
- ));
|
|
29
|
|
- return fromJS({puzzle: result, selected: false, choices: { rows, columns, squares } });
|
|
30
|
|
-}
|
|
|
5
|
+class Cell extends React.Component {
|
|
31
|
6
|
|
|
32
|
|
-class Game extends Component {
|
|
33
|
7
|
constructor(props) {
|
|
34
|
8
|
super(props);
|
|
35
|
|
- this.generateGame();
|
|
|
9
|
+ }
|
|
|
10
|
+
|
|
|
11
|
+ render() {
|
|
|
12
|
+ return (
|
|
|
13
|
+ <td>
|
|
|
14
|
+ <input type = "text"
|
|
|
15
|
+ value = {this.props.value}
|
|
|
16
|
+ readOnly = {this.props.readonly}
|
|
|
17
|
+ className="sudoku-cell" />
|
|
|
18
|
+ </td>
|
|
|
19
|
+ )
|
|
36
|
20
|
}
|
|
37
|
21
|
}
|
|
38
|
22
|
|
|
39
|
|
-// class Cell extends React.Component {
|
|
40
|
|
-// render() {
|
|
41
|
|
-// return (
|
|
42
|
|
-// <td>
|
|
43
|
|
-// <input type="text"
|
|
44
|
|
-// value = {this.props.value}
|
|
45
|
|
-// onChange={this.handleChange}
|
|
46
|
|
-// className="sudoku-cell" />
|
|
47
|
|
-// </td>
|
|
48
|
|
-// );
|
|
49
|
|
-// }
|
|
50
|
|
-// }
|
|
51
|
|
-//
|
|
52
|
|
-// function makeBoard({puzzle}) {
|
|
53
|
|
-//
|
|
54
|
|
-//
|
|
55
|
|
-// }
|
|
56
|
|
-//
|
|
57
|
|
-//
|
|
58
|
|
-//
|
|
59
|
|
-//
|
|
60
|
|
-// class Puzzle extends React.Component {
|
|
61
|
|
-//
|
|
62
|
|
-// // makeNineByNine () {
|
|
63
|
|
-// // var table = []
|
|
64
|
|
-// // for (let i = 0; i < 9; i++) {
|
|
65
|
|
-// // let children = []
|
|
66
|
|
-// // for (let j = 0; j < 9; j++) {
|
|
67
|
|
-// // children.push(<td>{<Cell />}</td>)
|
|
68
|
|
-// // }
|
|
69
|
|
-// // table.push(<tr>{columns}<tr>);
|
|
70
|
|
-// // }
|
|
71
|
|
-// // return (table)
|
|
72
|
|
-// // }
|
|
73
|
|
-//
|
|
74
|
|
-//
|
|
75
|
|
-//
|
|
76
|
|
-//
|
|
77
|
|
-//
|
|
78
|
|
-// render() {
|
|
79
|
|
-// return (
|
|
80
|
|
-// <Cell />
|
|
81
|
|
-// // <table>
|
|
82
|
|
-// //
|
|
83
|
|
-// // </table>
|
|
84
|
|
-// )
|
|
85
|
|
-// }
|
|
86
|
|
-// }
|
|
87
|
|
-//
|
|
88
|
|
-// ReactDOM.render(
|
|
89
|
|
-// //<Cell />,
|
|
90
|
|
-// <Puzzle />,
|
|
91
|
|
-// document.getElementById('root')
|
|
92
|
|
-// )
|
|
93
|
|
-//
|
|
94
|
|
-//
|
|
95
|
|
-//
|
|
|
23
|
+class Puzzle extends React.Component {
|
|
|
24
|
+ render() {
|
|
|
25
|
+ return (
|
|
|
26
|
+ <table className = "sudoku-table">
|
|
|
27
|
+ <tr>
|
|
|
28
|
+ <Cell />
|
|
|
29
|
+ <Cell value={1} readonly={'readonly'}/>
|
|
|
30
|
+ <Cell value={6} readonly={'readonly'}/>
|
|
|
31
|
+ <Cell />
|
|
|
32
|
+ <Cell />
|
|
|
33
|
+ <Cell />
|
|
|
34
|
+ <Cell value={2} readonly={'readonly'}/>
|
|
|
35
|
+ <Cell value={4} readonly={'readonly'}/>
|
|
|
36
|
+ <Cell />
|
|
|
37
|
+ </tr>
|
|
|
38
|
+ <tr>
|
|
|
39
|
+ <Cell value={3} readonly={'readonly'}/>
|
|
|
40
|
+ <Cell value={2} readonly={'readonly'}/>
|
|
|
41
|
+ <Cell />
|
|
|
42
|
+ <Cell />
|
|
|
43
|
+ <Cell />
|
|
|
44
|
+ <Cell value={9} readonly={'readonly'}/>
|
|
|
45
|
+ <Cell />
|
|
|
46
|
+ <Cell />
|
|
|
47
|
+ <Cell />
|
|
|
48
|
+ </tr>
|
|
|
49
|
+ <tr>
|
|
|
50
|
+ <Cell />
|
|
|
51
|
+ <Cell value={4} readonly={'readonly'}/>
|
|
|
52
|
+ <Cell />
|
|
|
53
|
+ <Cell value={1} readonly={'readonly'}/>
|
|
|
54
|
+ <Cell />
|
|
|
55
|
+ <Cell value={3} readonly={'readonly'}/>
|
|
|
56
|
+ <Cell />
|
|
|
57
|
+ <Cell />
|
|
|
58
|
+ <Cell />
|
|
|
59
|
+ </tr>
|
|
|
60
|
+ <tr>
|
|
|
61
|
+ <Cell />
|
|
|
62
|
+ <Cell />
|
|
|
63
|
+ <Cell value={5} readonly={'readonly'}/>
|
|
|
64
|
+ <Cell />
|
|
|
65
|
+ <Cell />
|
|
|
66
|
+ <Cell />
|
|
|
67
|
+ <Cell />
|
|
|
68
|
+ <Cell value={6} readonly={'readonly'}/>
|
|
|
69
|
+ <Cell value={9} readonly={'readonly'}/>
|
|
|
70
|
+ </tr>
|
|
|
71
|
+ <tr>
|
|
|
72
|
+ <Cell />
|
|
|
73
|
+ <Cell />
|
|
|
74
|
+ <Cell value={9} readonly={'readonly'}/>
|
|
|
75
|
+ <Cell />
|
|
|
76
|
+ <Cell value={5} readonly={'readonly'}/>
|
|
|
77
|
+ <Cell />
|
|
|
78
|
+ <Cell value={3} readonly={'readonly'}/>
|
|
|
79
|
+ <Cell />
|
|
|
80
|
+ <Cell />
|
|
|
81
|
+ </tr>
|
|
|
82
|
+ <tr>
|
|
|
83
|
+ <Cell value={6} readonly={'readonly'}/>
|
|
|
84
|
+ <Cell value={3} readonly={'readonly'}/>
|
|
|
85
|
+ <Cell />
|
|
|
86
|
+ <Cell />
|
|
|
87
|
+ <Cell />
|
|
|
88
|
+ <Cell />
|
|
|
89
|
+ <Cell value={8} readonly={'readonly'}/>
|
|
|
90
|
+ <Cell />
|
|
|
91
|
+ <Cell />
|
|
|
92
|
+ </tr>
|
|
|
93
|
+ <tr>
|
|
|
94
|
+ <Cell />
|
|
|
95
|
+ <Cell />
|
|
|
96
|
+ <Cell />
|
|
|
97
|
+ <Cell value={3} readonly={'readonly'}/>
|
|
|
98
|
+ <Cell />
|
|
|
99
|
+ <Cell value={6} readonly={'readonly'}/>
|
|
|
100
|
+ <Cell />
|
|
|
101
|
+ <Cell value={1} readonly={'readonly'}/>
|
|
|
102
|
+ <Cell />
|
|
|
103
|
+ </tr>
|
|
|
104
|
+ <tr>
|
|
|
105
|
+ <Cell />
|
|
|
106
|
+ <Cell />
|
|
|
107
|
+ <Cell />
|
|
|
108
|
+ <Cell value={4} readonly={'readonly'}/>
|
|
|
109
|
+ <Cell />
|
|
|
110
|
+ <Cell />
|
|
|
111
|
+ <Cell />
|
|
|
112
|
+ <Cell value={7} readonly={'readonly'}/>
|
|
|
113
|
+ <Cell value={2} readonly={'readonly'}/>
|
|
|
114
|
+ </tr>
|
|
|
115
|
+ <tr>
|
|
|
116
|
+ <Cell />
|
|
|
117
|
+ <Cell />
|
|
|
118
|
+ <Cell value={4} readonly={'readonly'}/>
|
|
|
119
|
+ <Cell value={9} readonly={'readonly'}/>
|
|
|
120
|
+ <Cell />
|
|
|
121
|
+ <Cell />
|
|
|
122
|
+ <Cell value={6} readonly={'readonly'}/>
|
|
|
123
|
+ <Cell value={8} readonly={'readonly'}/>
|
|
|
124
|
+ <Cell />
|
|
|
125
|
+ </tr>
|
|
|
126
|
+ </table>
|
|
|
127
|
+ )
|
|
|
128
|
+ }
|
|
96
|
129
|
|
|
|
130
|
+}
|
|
97
|
131
|
|
|
98
|
|
-// class Puzzle extends React.Component {
|
|
99
|
|
-// constructor(props) {
|
|
100
|
|
-// super(props);
|
|
101
|
|
-// this.state = {
|
|
102
|
|
-// squares: Array(9).fill(null),
|
|
103
|
|
-// };
|
|
104
|
|
-// }
|
|
105
|
|
-// renderSquare(i) {
|
|
106
|
|
-// return <Cell value= {i} />;
|
|
107
|
|
-// }
|
|
108
|
|
-//
|
|
109
|
|
-// createCellMatrix() {
|
|
110
|
|
-// var generated = this.state.board;
|
|
111
|
|
-// var board = {};
|
|
112
|
|
-//
|
|
113
|
|
-// for (var i = 65; i <= 73; i++) {
|
|
114
|
|
-// var quadrant = String.fromCharCode(i);
|
|
115
|
|
-//
|
|
116
|
|
-// for (var j = 1; j <= 9; j++) {
|
|
117
|
|
-// var cell = quadrant + '' + j;
|
|
118
|
|
-//
|
|
119
|
|
-// if (generated[cell] !== undefined) {
|
|
120
|
|
-// board[cell] = {};
|
|
121
|
|
-// board[cell] = generated[cell];
|
|
122
|
|
-// }
|
|
123
|
|
-// else {
|
|
124
|
|
-// board[cell] = '';
|
|
125
|
|
-// }
|
|
126
|
|
-// }
|
|
127
|
|
-// }
|
|
128
|
|
-//
|
|
129
|
|
-// this.setState({
|
|
130
|
|
-// cells: board
|
|
131
|
|
-// });
|
|
132
|
|
-//
|
|
133
|
|
-// return board;
|
|
134
|
|
-// }
|
|
135
|
|
-// getCells2D() {
|
|
136
|
|
-// var cells = values(this.state.cells);
|
|
137
|
|
-// var cells2D = [];
|
|
138
|
|
-// var i, j, chunk = 9;
|
|
139
|
|
-//
|
|
140
|
|
-// for (i = 0, j = cells.length; i < j; i += chunk) {
|
|
141
|
|
-// cells2D.push(cells.slice(i, i + chunk));
|
|
142
|
|
-// }
|
|
143
|
|
-//
|
|
144
|
|
-// return cells2D;
|
|
145
|
|
-// }
|
|
146
|
|
-// render() {
|
|
147
|
|
-// return (
|
|
148
|
|
-// <div>
|
|
149
|
|
-// {this.getCells2D()}
|
|
150
|
|
-// </div>
|
|
151
|
|
-// );
|
|
152
|
|
-// }
|
|
153
|
|
-//
|
|
154
|
|
-// }
|
|
155
|
|
-//
|
|
156
|
|
-// class Cell extends React.Component {
|
|
157
|
|
-// constructor(props) {
|
|
158
|
|
-// super(props);
|
|
159
|
|
-// this.state = {
|
|
160
|
|
-// value: props,
|
|
161
|
|
-// };
|
|
162
|
|
-// }
|
|
163
|
|
-//
|
|
164
|
|
-// render() {
|
|
165
|
|
-// return (
|
|
166
|
|
-// <td>
|
|
167
|
|
-// <input type="text"
|
|
168
|
|
-// value = {this.props.value}
|
|
169
|
|
-// onChange={this.handleChange}
|
|
170
|
|
-// className="sudoku-square" />
|
|
171
|
|
-// </td>
|
|
172
|
|
-// );
|
|
173
|
|
-// };
|
|
174
|
|
-// }
|
|
175
|
|
-//
|
|
176
|
|
-// ReactDOM.render(
|
|
177
|
|
-// <Puzzle />,
|
|
178
|
|
-// document.getElementById('root')
|
|
179
|
|
-// );
|
|
|
132
|
+ReactDOM.render(<Puzzle />, document.getElementById("root"));
|