Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
concordant
Software
c-sudoku
Commits
4e95e3f3
Commit
4e95e3f3
authored
Apr 19, 2021
by
Yannick Li
Browse files
ESLint: automatic fixes
parent
b364d4a0
Changes
3
Hide whitespace changes
Inline
Side-by-side
collaborative/src/components/Game.tsx
View file @
4e95e3f3
...
...
@@ -41,9 +41,9 @@ interface IGameState {
class
Game
extends
React
.
Component
<
{},
IGameState
>
{
constructor
(
props
:
any
)
{
super
(
props
);
le
t
CONFIG
=
require
(
'
../config.json
'
);
le
t
session
=
client
.
Session
.
Companion
.
connect
(
CONFIG
.
dbName
,
CONFIG
.
serviceUrl
,
CONFIG
.
credentials
);
le
t
collection
=
session
.
openCollection
(
"
sudoku
"
,
false
);
cons
t
CONFIG
=
require
(
'
../config.json
'
);
cons
t
session
=
client
.
Session
.
Companion
.
connect
(
CONFIG
.
dbName
,
CONFIG
.
serviceUrl
,
CONFIG
.
credentials
);
cons
t
collection
=
session
.
openCollection
(
"
sudoku
"
,
false
);
this
.
state
=
{
session
:
session
,
collection
:
collection
...
...
collaborative/src/components/Grid.test.tsx
View file @
4e95e3f3
...
...
@@ -90,8 +90,8 @@ describe ("getValue", () => {
const
wrapper
=
shallow
(<
Grid
initial
=
{
initVal
}
/>)
const
grid
=
wrapper
.
instance
()
le
t
envs
=
Array
(
9
)
le
t
newvals
=
Array
(
9
)
cons
t
envs
=
Array
(
9
)
cons
t
newvals
=
Array
(
9
)
for
(
let
i
=
0
;
i
<
9
;
i
++
){
envs
[
i
]
=
new
crdtlib
.
utils
.
SimpleEnvironment
(
new
crdtlib
.
utils
.
ClientUId
(
"
myClientId
"
+
i
));
...
...
@@ -147,9 +147,9 @@ describe("checkLine", () => {
const
wrapper
=
shallow
(<
Grid
initial
=
{
initVal
}
/>)
const
grid
=
wrapper
.
instance
()
le
t
env
=
new
crdtlib
.
utils
.
SimpleEnvironment
(
cons
t
env
=
new
crdtlib
.
utils
.
SimpleEnvironment
(
new
crdtlib
.
utils
.
ClientUId
(
"
myClientId1
"
));
le
t
newval
=
new
crdtlib
.
crdt
.
MVRegister
()
cons
t
newval
=
new
crdtlib
.
crdt
.
MVRegister
()
newval
.
set
(
"
1
"
,
env
.
tick
())
grid
.
state
.
cells
[
45
].
merge
(
newval
)
...
...
@@ -180,9 +180,9 @@ describe("checkColumn", () => {
const
wrapper
=
shallow
(<
Grid
initial
=
{
initVal
}
/>)
const
grid
=
wrapper
.
instance
()
le
t
env
=
new
crdtlib
.
utils
.
SimpleEnvironment
(
cons
t
env
=
new
crdtlib
.
utils
.
SimpleEnvironment
(
new
crdtlib
.
utils
.
ClientUId
(
"
myClientId1
"
));
le
t
newval
=
new
crdtlib
.
crdt
.
MVRegister
()
cons
t
newval
=
new
crdtlib
.
crdt
.
MVRegister
()
newval
.
set
(
"
1
"
,
env
.
tick
())
grid
.
state
.
cells
[
5
].
merge
(
newval
)
...
...
@@ -213,9 +213,9 @@ describe("checkBlock", () => {
const
wrapper
=
shallow
(<
Grid
initial
=
{
initVal
}
/>)
const
grid
=
wrapper
.
instance
()
le
t
env
=
new
crdtlib
.
utils
.
SimpleEnvironment
(
cons
t
env
=
new
crdtlib
.
utils
.
SimpleEnvironment
(
new
crdtlib
.
utils
.
ClientUId
(
"
myClientId
"
));
le
t
newval
=
new
crdtlib
.
crdt
.
MVRegister
()
cons
t
newval
=
new
crdtlib
.
crdt
.
MVRegister
()
newval
.
set
(
"
1
"
,
env
.
tick
())
grid
.
state
.
cells
[
3
].
merge
(
newval
)
...
...
@@ -321,9 +321,9 @@ describe("validateLine", () => {
const
wrapper
=
shallow
(<
Grid
initial
=
{
initVal
}
/>)
const
grid
=
wrapper
.
instance
()
le
t
env
=
new
crdtlib
.
utils
.
SimpleEnvironment
(
cons
t
env
=
new
crdtlib
.
utils
.
SimpleEnvironment
(
new
crdtlib
.
utils
.
ClientUId
(
"
myClientId
"
));
le
t
newval
=
new
crdtlib
.
crdt
.
MVRegister
()
cons
t
newval
=
new
crdtlib
.
crdt
.
MVRegister
()
newval
.
set
(
"
1
"
,
env
.
tick
())
grid
.
state
.
cells
[
1
].
merge
(
newval
)
...
...
@@ -424,9 +424,9 @@ describe("validateColumn", () => {
const
wrapper
=
shallow
(<
Grid
initial
=
{
initVal
}
/>)
const
grid
=
wrapper
.
instance
()
le
t
env
=
new
crdtlib
.
utils
.
SimpleEnvironment
(
cons
t
env
=
new
crdtlib
.
utils
.
SimpleEnvironment
(
new
crdtlib
.
utils
.
ClientUId
(
"
myClientId
"
));
le
t
newval
=
new
crdtlib
.
crdt
.
MVRegister
()
cons
t
newval
=
new
crdtlib
.
crdt
.
MVRegister
()
newval
.
set
(
"
1
"
,
env
.
tick
())
grid
.
state
.
cells
[
1
].
merge
(
newval
)
...
...
@@ -527,9 +527,9 @@ describe("validateBlock", () => {
const
wrapper
=
shallow
(<
Grid
initial
=
{
initVal
}
/>)
const
grid
=
wrapper
.
instance
()
le
t
env
=
new
crdtlib
.
utils
.
SimpleEnvironment
(
cons
t
env
=
new
crdtlib
.
utils
.
SimpleEnvironment
(
new
crdtlib
.
utils
.
ClientUId
(
"
myClientId
"
));
le
t
newval
=
new
crdtlib
.
crdt
.
MVRegister
()
cons
t
newval
=
new
crdtlib
.
crdt
.
MVRegister
()
newval
.
set
(
"
1
"
,
env
.
tick
())
grid
.
state
.
cells
[
1
].
merge
(
newval
)
...
...
@@ -630,9 +630,9 @@ describe("validateSudoku", () => {
const
wrapper
=
shallow
(<
Grid
initial
=
{
initVal
}
/>)
const
grid
=
wrapper
.
instance
()
le
t
env
=
new
crdtlib
.
utils
.
SimpleEnvironment
(
cons
t
env
=
new
crdtlib
.
utils
.
SimpleEnvironment
(
new
crdtlib
.
utils
.
ClientUId
(
"
myClientId
"
));
le
t
newval
=
new
crdtlib
.
crdt
.
MVRegister
()
cons
t
newval
=
new
crdtlib
.
crdt
.
MVRegister
()
newval
.
set
(
"
1
"
,
env
.
tick
())
grid
.
state
.
cells
[
1
].
merge
(
newval
)
...
...
collaborative/src/components/Grid.tsx
View file @
4e95e3f3
...
...
@@ -57,10 +57,10 @@ class Grid extends React.Component<IGridProps, IGridState> {
constructor
(
props
:
any
)
{
super
(
props
);
le
t
cells
=
new
Array
(
81
).
fill
(
null
).
map
(()
=>
({
value
:
""
,
modifiable
:
false
,
error
:
false
}));
cons
t
cells
=
new
Array
(
81
).
fill
(
null
).
map
(()
=>
({
value
:
""
,
modifiable
:
false
,
error
:
false
}));
this
.
modifiedCells
=
new
Array
(
81
).
fill
(
null
);
le
t
gridNum
=
"
1
"
;
le
t
mvmap
=
this
.
props
.
collection
.
open
(
"
grid
"
+
gridNum
,
"
MVMap
"
,
false
,
function
()
{
return
});
cons
t
gridNum
=
"
1
"
;
cons
t
mvmap
=
this
.
props
.
collection
.
open
(
"
grid
"
+
gridNum
,
"
MVMap
"
,
false
,
function
()
{
return
});
this
.
state
=
{
gridNum
:
gridNum
,
mvmap
:
mvmap
,
...
...
@@ -94,7 +94,7 @@ class Grid extends React.Component<IGridProps, IGridState> {
* Update cells values from C-Client.
*/
updateGrid
()
{
le
t
cells
=
this
.
state
.
cells
;
cons
t
cells
=
this
.
state
.
cells
;
if
(
!
this
.
state
.
isConnected
)
{
console
.
error
(
"
updateGrid() called while not connected.
"
)
return
cells
;
...
...
@@ -105,9 +105,9 @@ class Grid extends React.Component<IGridProps, IGridState> {
}
}
this
.
props
.
session
.
transaction
(
client
.
utils
.
ConsistencyLevel
.
None
,
()
=>
{
le
t
itString
=
this
.
state
.
mvmap
.
iteratorString
()
cons
t
itString
=
this
.
state
.
mvmap
.
iteratorString
()
while
(
itString
.
hasNext
())
{
le
t
val
=
itString
.
next
()
cons
t
val
=
itString
.
next
()
cells
[
val
.
first
].
value
=
hashSetToString
(
val
.
second
)
}
})
...
...
@@ -143,7 +143,7 @@ class Grid extends React.Component<IGridProps, IGridState> {
*/
initFrom
(
values
:
any
)
{
assert
.
ok
(
values
.
length
===
81
);
le
t
cells
=
this
.
state
.
cells
;
cons
t
cells
=
this
.
state
.
cells
;
for
(
let
index
=
0
;
index
<
81
;
index
++
)
{
cells
[
index
].
value
=
values
[
index
]
===
"
.
"
?
""
:
values
[
index
];
cells
[
index
].
modifiable
=
values
[
index
]
===
"
.
"
?
true
:
false
;
...
...
@@ -155,7 +155,7 @@ class Grid extends React.Component<IGridProps, IGridState> {
* Reset the value of all modifiable cells.
*/
reset
()
{
le
t
cells
=
this
.
state
.
cells
;
cons
t
cells
=
this
.
state
.
cells
;
for
(
let
index
=
0
;
index
<
81
;
index
++
)
{
if
(
cells
[
index
].
modifiable
)
{
cells
[
index
].
value
=
""
;
...
...
@@ -183,7 +183,7 @@ class Grid extends React.Component<IGridProps, IGridState> {
console
.
error
(
"
Trying to change an non modifiable cell. Should not happend
"
);
}
le
t
cells
=
this
.
state
.
cells
;
cons
t
cells
=
this
.
state
.
cells
;
cells
[
index
].
value
=
value
;
this
.
updateState
(
cells
);
...
...
@@ -204,7 +204,7 @@ class Grid extends React.Component<IGridProps, IGridState> {
if
(
Number
(
gridNum
)
<
1
||
Number
(
gridNum
)
>
100
||
gridNum
===
this
.
state
.
gridNum
)
{
return
;
}
le
t
mvmap
=
this
.
props
.
collection
.
open
(
"
grid
"
+
gridNum
,
"
MVMap
"
,
false
,
function
()
{
return
});
cons
t
mvmap
=
this
.
props
.
collection
.
open
(
"
grid
"
+
gridNum
,
"
MVMap
"
,
false
,
function
()
{
return
});
this
.
setState
({
gridNum
:
gridNum
,
mvmap
:
mvmap
});
this
.
initFrom
(
generateStaticGrid
(
gridNum
));
}
...
...
@@ -231,7 +231,7 @@ class Grid extends React.Component<IGridProps, IGridState> {
*/
renderBlock
(
blockNum
:
number
)
{
assert
.
ok
(
blockNum
>=
0
&&
blockNum
<
9
)
le
t
index
=
blockIndex
(
blockNum
);
cons
t
index
=
blockIndex
(
blockNum
);
return
(
<
td
>
{
this
.
renderCell
(
index
[
0
])
}{
this
.
renderCell
(
index
[
1
])
}{
this
.
renderCell
(
index
[
2
])
}
<
br
/>
...
...
@@ -275,10 +275,10 @@ class Grid extends React.Component<IGridProps, IGridState> {
*/
checkLine
(
line
:
number
)
{
assert
.
ok
(
line
>=
0
&&
line
<
9
)
le
t
cpt
=
Array
(
9
).
fill
(
0
)
cons
t
cpt
=
Array
(
9
).
fill
(
0
)
for
(
let
column
=
0
;
column
<
9
;
column
++
)
{
le
t
index
=
line
*
9
+
column
le
t
val
=
this
.
state
.
cells
[
index
].
value
cons
t
index
=
line
*
9
+
column
cons
t
val
=
this
.
state
.
cells
[
index
].
value
if
(
val
.
length
===
0
||
val
.
length
>
1
)
{
continue
}
...
...
@@ -293,10 +293,10 @@ class Grid extends React.Component<IGridProps, IGridState> {
*/
checkColumn
(
column
:
number
)
{
assert
.
ok
(
column
>=
0
&&
column
<
9
)
le
t
cpt
=
Array
(
9
).
fill
(
0
)
cons
t
cpt
=
Array
(
9
).
fill
(
0
)
for
(
let
line
=
0
;
line
<
9
;
line
++
)
{
le
t
index
=
line
*
9
+
column
le
t
val
=
this
.
state
.
cells
[
index
].
value
cons
t
index
=
line
*
9
+
column
cons
t
val
=
this
.
state
.
cells
[
index
].
value
if
(
val
.
length
===
0
||
val
.
length
>
1
)
{
continue
}
...
...
@@ -311,10 +311,10 @@ class Grid extends React.Component<IGridProps, IGridState> {
*/
checkBlock
(
block
:
number
)
{
assert
.
ok
(
block
>=
0
&&
block
<
9
)
le
t
cpt
=
Array
(
9
).
fill
(
0
)
le
t
indexList
=
blockIndex
(
block
)
for
(
le
t
index
of
indexList
)
{
le
t
val
=
this
.
state
.
cells
[
index
].
value
cons
t
cpt
=
Array
(
9
).
fill
(
0
)
cons
t
indexList
=
blockIndex
(
block
)
for
(
cons
t
index
of
indexList
)
{
cons
t
val
=
this
.
state
.
cells
[
index
].
value
if
(
val
.
length
===
0
||
val
.
length
>
1
)
{
continue
}
...
...
@@ -327,7 +327,7 @@ class Grid extends React.Component<IGridProps, IGridState> {
* This function check if all lines respect Sudoku lines rules.
*/
checkLines
()
{
le
t
indexList
=
[]
cons
t
indexList
=
[]
for
(
let
line
=
0
;
line
<
9
;
line
++
)
{
if
(
this
.
checkLine
(
line
)
===
false
)
{
for
(
let
column
=
0
;
column
<
9
;
column
++
)
{
...
...
@@ -342,7 +342,7 @@ class Grid extends React.Component<IGridProps, IGridState> {
* This function check if all columns respect Sudoku columns rules.
*/
checkColumns
()
{
le
t
indexList
=
[]
cons
t
indexList
=
[]
for
(
let
column
=
0
;
column
<
9
;
column
++
)
{
if
(
this
.
checkColumn
(
column
)
===
false
)
{
for
(
let
line
=
0
;
line
<
9
;
line
++
)
{
...
...
@@ -370,9 +370,9 @@ class Grid extends React.Component<IGridProps, IGridState> {
* This function check if cells contains multiple values.
*/
checkCells
()
{
le
t
indexList
=
[]
cons
t
indexList
=
[]
for
(
let
cell
=
0
;
cell
<
81
;
cell
++
)
{
le
t
val
=
this
.
state
.
cells
[
cell
].
value
cons
t
val
=
this
.
state
.
cells
[
cell
].
value
if
(
val
.
length
>
1
)
{
indexList
.
push
(
cell
)
}
...
...
@@ -390,7 +390,7 @@ class Grid extends React.Component<IGridProps, IGridState> {
errorIndexList
=
errorIndexList
.
concat
(
this
.
checkBlocks
());
errorIndexList
=
errorIndexList
.
concat
(
this
.
checkCells
());
le
t
errorIndexSet
=
new
Set
(
errorIndexList
);
cons
t
errorIndexSet
=
new
Set
(
errorIndexList
);
for
(
let
index
=
0
;
index
<
81
;
index
++
)
{
if
(
errorIndexSet
.
has
(
index
))
{
...
...
@@ -429,9 +429,9 @@ function generateStaticGrid(gridNum: string) {
*/
function
blockIndex
(
block
:
number
)
{
assert
.
ok
(
block
>=
0
&&
block
<
9
)
le
t
line
=
Math
.
floor
(
block
/
3
)
*
3
le
t
column
=
(
block
%
3
)
*
3
le
t
index
=
[
line
*
9
+
column
,
line
*
9
+
column
+
1
,
line
*
9
+
column
+
2
,
cons
t
line
=
Math
.
floor
(
block
/
3
)
*
3
cons
t
column
=
(
block
%
3
)
*
3
cons
t
index
=
[
line
*
9
+
column
,
line
*
9
+
column
+
1
,
line
*
9
+
column
+
2
,
(
line
+
1
)
*
9
+
column
,
(
line
+
1
)
*
9
+
column
+
1
,
(
line
+
1
)
*
9
+
column
+
2
,
(
line
+
2
)
*
9
+
column
,
(
line
+
2
)
*
9
+
column
+
1
,
(
line
+
2
)
*
9
+
column
+
2
]
return
index
...
...
@@ -442,10 +442,10 @@ function blockIndex(block: number) {
* @param set HashSet to be concatenated.
*/
function
hashSetToString
(
set
:
any
)
{
le
t
res
=
new
Set
();
le
t
it
=
set
.
iterator
();
cons
t
res
=
new
Set
();
cons
t
it
=
set
.
iterator
();
while
(
it
.
hasNext
())
{
le
t
val
=
it
.
next
();
cons
t
val
=
it
.
next
();
if
(
val
!==
""
)
{
res
.
add
(
val
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment