From 810e34155acab9bf1525dcc674abf1833e2d9ad6 Mon Sep 17 00:00:00 2001 From: Guyslain <guyslain.naves@lis-lab.fr> Date: Mon, 23 Oct 2023 16:02:20 +0200 Subject: [PATCH] section 6 GameOfLifeState fini --- .../java/model/automata/GameOfLifeState.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/java/model/automata/GameOfLifeState.java b/src/main/java/model/automata/GameOfLifeState.java index 12ee370..c9c7687 100644 --- a/src/main/java/model/automata/GameOfLifeState.java +++ b/src/main/java/model/automata/GameOfLifeState.java @@ -14,20 +14,26 @@ public enum GameOfLifeState implements State<GameOfLifeState> { @Override public Color getColor() { - //TODO: à compléter - return Color.BLACK; + return switch (this) { + case ALIVE -> Color.RED; + case DEAD -> Color.WHITE; + }; } @Override - public GameOfLifeState next() { - //TODO: à compléter - return null; + public GameOfLifeState cycle() { + return switch (this) { + case ALIVE -> DEAD; + case DEAD -> ALIVE; + }; } @Override public GameOfLifeState update(List<GameOfLifeState> neighbours) { - //TODO: à compléter - return null; + int countAlive = State.count(ALIVE, neighbours); + return (countAlive == 3 || (countAlive == 2 && this == ALIVE))? + ALIVE: + DEAD; } } -- GitLab