Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
twitch
live-coding-fr
Commits
157084ce
Commit
157084ce
authored
Apr 27, 2021
by
Colin DAMON
Browse files
Fix large grid displays
parent
ee451b73
Changes
3
Hide whitespace changes
Inline
Side-by-side
game-of-life/src/main/java/fr/ippon/life/Grid.java
View file @
157084ce
...
...
@@ -8,10 +8,12 @@ import java.util.stream.Stream;
public
class
Grid
{
private
final
Set
<
Cell
>
aliveCells
;
private
final
Set
<
Cell
>
deadCells
;
private
final
Box
border
;
Grid
(
Set
<
Cell
>
aliveCells
)
{
this
.
aliveCells
=
aliveCells
;
this
.
deadCells
=
buildDeadCells
(
aliveCells
);
border
=
new
Box
(
aliveCells
);
}
...
...
@@ -25,6 +27,10 @@ public class Grid {
.
collect
(
Collectors
.
toUnmodifiableSet
());
}
public
boolean
isAlive
(
Cell
cell
)
{
return
aliveCells
.
contains
(
cell
);
}
public
Collection
<
Cell
>
deadCells
()
{
return
deadCells
;
}
...
...
game-of-life/src/main/java/fr/ippon/life/StringRenderer.java
View file @
157084ce
...
...
@@ -33,16 +33,12 @@ public class StringRenderer implements Renderer<String> {
private
IntFunction
<
String
>
cellRepresentation
(
Integer
row
)
{
return
column
->
{
if
(
alive
Cell
(
row
,
column
))
{
if
(
grid
.
isAlive
(
new
Cell
(
row
,
column
))
)
{
return
"o"
;
}
return
"x"
;
};
}
private
boolean
aliveCell
(
Integer
row
,
int
column
)
{
return
!
grid
.
deadCells
().
contains
(
new
Cell
(
row
,
column
));
}
}
}
game-of-life/src/test/java/fr/ippon/life/StringRendererUnitTest.java
View file @
157084ce
...
...
@@ -22,6 +22,11 @@ class StringRendererUnitTest {
assertThat
(
renderer
.
run
(
grid
().
alive
(
1
,
1
).
alive
(
1
,
3
).
build
())).
isEqualTo
(
join
(
"xxxxx"
,
"xoxox"
,
"xxxxx"
));
}
@Test
void
shouldDisplayGridWithTwoDistantAliveCell
()
{
assertThat
(
renderer
.
run
(
grid
().
alive
(
1
,
1
).
alive
(
1
,
7
).
build
())).
isEqualTo
(
join
(
"xxxxxxxxx"
,
"xoxxxxxox"
,
"xxxxxxxxx"
));
}
private
static
String
join
(
String
...
parts
)
{
return
Arrays
.
stream
(
parts
).
collect
(
Collectors
.
joining
(
System
.
lineSeparator
(),
""
,
System
.
lineSeparator
()));
}
...
...
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