From a1d259bdead0420ccba640c3e2b9e1268580cb2a Mon Sep 17 00:00:00 2001 From: "charlotte.ackva" <charlotte.ackva@stud.uni-goettingen.de> Date: Fri, 15 Jun 2018 14:23:49 +0200 Subject: [PATCH 01/15] Test --- src/flowerwarspp/boardmechanics/test.java | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/flowerwarspp/boardmechanics/test.java diff --git a/src/flowerwarspp/boardmechanics/test.java b/src/flowerwarspp/boardmechanics/test.java new file mode 100644 index 0000000..4cf5aa5 --- /dev/null +++ b/src/flowerwarspp/boardmechanics/test.java @@ -0,0 +1 @@ +hallo -- GitLab From 8d1992421debdfec10ea14514e6da62e31045e93 Mon Sep 17 00:00:00 2001 From: Martin Heide <martin.heide@stud.uni-goettingen.de> Date: Fri, 15 Jun 2018 17:18:30 +0200 Subject: [PATCH 02/15] Added Classes: ColoredFlower, FlowerSet, Compound, FlowerType --- .../boardmechanics/ColoredFlower.java | 71 +++++++++++++++++++ src/flowerwarspp/boardmechanics/Compound.java | 31 ++++++++ .../boardmechanics/FlowerSet.java | 57 +++++++++++++++ .../boardmechanics/FlowerType.java | 15 ++++ src/flowerwarspp/boardmechanics/test.java | 1 - 5 files changed, 174 insertions(+), 1 deletion(-) create mode 100644 src/flowerwarspp/boardmechanics/ColoredFlower.java create mode 100644 src/flowerwarspp/boardmechanics/Compound.java create mode 100644 src/flowerwarspp/boardmechanics/FlowerSet.java create mode 100644 src/flowerwarspp/boardmechanics/FlowerType.java delete mode 100644 src/flowerwarspp/boardmechanics/test.java diff --git a/src/flowerwarspp/boardmechanics/ColoredFlower.java b/src/flowerwarspp/boardmechanics/ColoredFlower.java new file mode 100644 index 0000000..f3d3eb8 --- /dev/null +++ b/src/flowerwarspp/boardmechanics/ColoredFlower.java @@ -0,0 +1,71 @@ +package flowerwarspp.boardmechanics; + +import flowerwarspp.preset.*; +import java.util.*; + +/** +* Extends the flower class. Adds extra functionality: <br> +* -Status Variable (if Flower is Red, Blue, uncolored, fallow) +* -vector of EdgeNeighbors +* -vector of NodeNeighbors +* -information about the parentFlowerSet +* +* @author Charlotte Ackva, Felix Spuehler, Martin Heide +**/ + +public class ColoredFlower extends Flower { + /** Holds the edge neighbored flowers */ + private Vector<ColoredFlower> edgeNeighbors; + /** Holds the node neighbored flowers */ + private Vector<ColoredFlower> nodeNeighbors; + /** Holds an information {@see FlowerType} about the status of the ColoredFlower */ + private FlowerType flowerType; + /** Holds the information about the parent flower set where the flower is contained in */ + private FlowerSet parentFlowerSet; + + /** Constructs a ColoredFlower **/ + public ColoredFlower (final Position first, final Position second, final Position third) { + super(first,second,third); + flowerType = FlowerType.UNCOLORED; + } + /** returns the nodeNeighbors of the Flower + * @return vector of Nodeneighbored Flowers + **/ + public Collection<ColoredFlower> getNodeNeighbors() { + return nodeNeighbors; + } + /** returns the edgeNeighbors of the Flower + * @return vector of Edgeneighbored Flowers + **/ + public Collection<ColoredFlower> getEdgeNeighbors() { + return edgeNeighbors; + } + /** sets the nodeNeighbors of the Flower + * @param vector of Nodeneighbored Flowers + **/ + public void setNodeNeighbors(Vector<ColoredFlower> vectorNodes) { + } + /** sets the edgeNeighbors of the Flower + * @param vector of edgeneighbored Flowers + **/ + public void setEdgeNeighbors(Vector<ColoredFlower> vectorEdges) { + } + /** sets the type of the Flower + * @param type FlowerType - the new type of the Flower + **/ + public void setFlowerType(FlowerType type) { + flowerType = type; + } + /** sets the parent Flower Set of the flower + * @param parent FlowerSet + **/ + public void setParentFlowerSet(FlowerSet parent) { + parentFlowerSet = parent; + } + /** returns the parent Flower Set of the flower + * @return parent FlowerSet + **/ + public FlowerSet getParentFlowerSet() { + return parentFlowerSet; + } +} diff --git a/src/flowerwarspp/boardmechanics/Compound.java b/src/flowerwarspp/boardmechanics/Compound.java new file mode 100644 index 0000000..9a8fc7d --- /dev/null +++ b/src/flowerwarspp/boardmechanics/Compound.java @@ -0,0 +1,31 @@ +package flowerwarspp.boardmechanics; + +import java.util.*; + +/** +* Contains FlowerSets which are connected over Ditches. Ditches are not included. +* @author Charlotte Ackva, Felix Spuehler, Martin Heide +**/ +public class Compound { + /** Contains the FlowerSets where all Flowers are safed in.*/ + private Collection<FlowerSet> flowerSets; + + /** + * Constructs a Component based on an initial ColoredFlower. + * @param firstFlower ColoredFlower the inital ColoredFlower + **/ + public Compound(ColoredFlower firstFlower) { + flowerSets = new Vector<FlowerSet>(1); + flowerSets.add(new FlowerSet(firstFlower)); + } + + /** + * Adds a Flower + * @author Charlotte Ackva, Felix Spuehler, Martin Heide + **/ + public void addFlower(ColoredFlower furtherFlower) { + FlowerSet dummy = new FlowerSet(furtherFlower); + dummy.setParentCompound(this); + flowerSets.add(dummy); + } +} diff --git a/src/flowerwarspp/boardmechanics/FlowerSet.java b/src/flowerwarspp/boardmechanics/FlowerSet.java new file mode 100644 index 0000000..d63fb51 --- /dev/null +++ b/src/flowerwarspp/boardmechanics/FlowerSet.java @@ -0,0 +1,57 @@ +package flowerwarspp.boardmechanics; + +import java.util.*; +/** +* Contains edge connected ColoredFlowers +* @author Charlotte Ackva, Felix Spuehler, Martin Heide +**/ +public class FlowerSet { + // auesser ColoredFlowers Referenzen + + /** Contains the flowers in the FlowerSet */ + private Collection<ColoredFlower> flowers; + + /** Holds the information about the parent Compound where the set is contained in */ + private Compound parentCompound; + + /** + * Constructs the set of Flowers + * @param firstFlower of type ColoredFlower which is the first entry in the set. + **/ + public FlowerSet(ColoredFlower firstFlower ) { + flowers = new Vector<ColoredFlower>(1); + add(firstFlower); + } + + /** + * Adds a further Flower to the set of Flowers + * @param furtherFlower of type ColoredFlower to be added + **/ + public void add(ColoredFlower furtherFlower) { + if(flowers.size() == 4) { + throw new IllegalArgumentException(); + } + furtherFlower.setParentFlowerSet(this); + flowers.add(furtherFlower); + // referenzen nach aussen anpassen + } + + /** + * Sets the parent Compound where the set is contained in. + * @param parent Compound + **/ + public void setParentCompound(Compound parent) { + parentCompound = parent; + } + + /** + * Return the parent Compound where the set is contained in. + * @return parent Compound + **/ + public Compound getParentCompound() { + return parentCompound; + } + + // merge + // split +} diff --git a/src/flowerwarspp/boardmechanics/FlowerType.java b/src/flowerwarspp/boardmechanics/FlowerType.java new file mode 100644 index 0000000..466a0fa --- /dev/null +++ b/src/flowerwarspp/boardmechanics/FlowerType.java @@ -0,0 +1,15 @@ +package flowerwarspp.boardmechanics; + +/** +* Defines possible Status Types for ColoredFlower +* +* implements Serializable missing?! +* @author Charlotte Ackva, Felix Spuehler, Martin Heide +**/ + +enum FlowerType { + RED, + BLUE, + FALLOW, + UNCOLORED +} diff --git a/src/flowerwarspp/boardmechanics/test.java b/src/flowerwarspp/boardmechanics/test.java deleted file mode 100644 index 4cf5aa5..0000000 --- a/src/flowerwarspp/boardmechanics/test.java +++ /dev/null @@ -1 +0,0 @@ -hallo -- GitLab From 9ba16132dc658304d6e57186b3c911fe1c0bfd93 Mon Sep 17 00:00:00 2001 From: "charlotte.ackva" <charlotte.ackva@stud.uni-goettingen.de> Date: Fri, 15 Jun 2018 14:23:49 +0200 Subject: [PATCH 03/15] Test --- src/flowerwarspp/boardmechanics/test.java | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/flowerwarspp/boardmechanics/test.java diff --git a/src/flowerwarspp/boardmechanics/test.java b/src/flowerwarspp/boardmechanics/test.java new file mode 100644 index 0000000..4cf5aa5 --- /dev/null +++ b/src/flowerwarspp/boardmechanics/test.java @@ -0,0 +1 @@ +hallo -- GitLab From 19f5848b32d95e3f093f57cfd4f38614dcb4dcb3 Mon Sep 17 00:00:00 2001 From: Martin Heide <martin.heide@stud.uni-goettingen.de> Date: Fri, 15 Jun 2018 17:18:30 +0200 Subject: [PATCH 04/15] Added Classes: ColoredFlower, FlowerSet, Compound, FlowerType --- .../boardmechanics/ColoredFlower.java | 71 +++++++++++++++++++ src/flowerwarspp/boardmechanics/Compound.java | 31 ++++++++ .../boardmechanics/FlowerSet.java | 57 +++++++++++++++ .../boardmechanics/FlowerType.java | 15 ++++ src/flowerwarspp/boardmechanics/test.java | 1 - 5 files changed, 174 insertions(+), 1 deletion(-) create mode 100644 src/flowerwarspp/boardmechanics/ColoredFlower.java create mode 100644 src/flowerwarspp/boardmechanics/Compound.java create mode 100644 src/flowerwarspp/boardmechanics/FlowerSet.java create mode 100644 src/flowerwarspp/boardmechanics/FlowerType.java delete mode 100644 src/flowerwarspp/boardmechanics/test.java diff --git a/src/flowerwarspp/boardmechanics/ColoredFlower.java b/src/flowerwarspp/boardmechanics/ColoredFlower.java new file mode 100644 index 0000000..f3d3eb8 --- /dev/null +++ b/src/flowerwarspp/boardmechanics/ColoredFlower.java @@ -0,0 +1,71 @@ +package flowerwarspp.boardmechanics; + +import flowerwarspp.preset.*; +import java.util.*; + +/** +* Extends the flower class. Adds extra functionality: <br> +* -Status Variable (if Flower is Red, Blue, uncolored, fallow) +* -vector of EdgeNeighbors +* -vector of NodeNeighbors +* -information about the parentFlowerSet +* +* @author Charlotte Ackva, Felix Spuehler, Martin Heide +**/ + +public class ColoredFlower extends Flower { + /** Holds the edge neighbored flowers */ + private Vector<ColoredFlower> edgeNeighbors; + /** Holds the node neighbored flowers */ + private Vector<ColoredFlower> nodeNeighbors; + /** Holds an information {@see FlowerType} about the status of the ColoredFlower */ + private FlowerType flowerType; + /** Holds the information about the parent flower set where the flower is contained in */ + private FlowerSet parentFlowerSet; + + /** Constructs a ColoredFlower **/ + public ColoredFlower (final Position first, final Position second, final Position third) { + super(first,second,third); + flowerType = FlowerType.UNCOLORED; + } + /** returns the nodeNeighbors of the Flower + * @return vector of Nodeneighbored Flowers + **/ + public Collection<ColoredFlower> getNodeNeighbors() { + return nodeNeighbors; + } + /** returns the edgeNeighbors of the Flower + * @return vector of Edgeneighbored Flowers + **/ + public Collection<ColoredFlower> getEdgeNeighbors() { + return edgeNeighbors; + } + /** sets the nodeNeighbors of the Flower + * @param vector of Nodeneighbored Flowers + **/ + public void setNodeNeighbors(Vector<ColoredFlower> vectorNodes) { + } + /** sets the edgeNeighbors of the Flower + * @param vector of edgeneighbored Flowers + **/ + public void setEdgeNeighbors(Vector<ColoredFlower> vectorEdges) { + } + /** sets the type of the Flower + * @param type FlowerType - the new type of the Flower + **/ + public void setFlowerType(FlowerType type) { + flowerType = type; + } + /** sets the parent Flower Set of the flower + * @param parent FlowerSet + **/ + public void setParentFlowerSet(FlowerSet parent) { + parentFlowerSet = parent; + } + /** returns the parent Flower Set of the flower + * @return parent FlowerSet + **/ + public FlowerSet getParentFlowerSet() { + return parentFlowerSet; + } +} diff --git a/src/flowerwarspp/boardmechanics/Compound.java b/src/flowerwarspp/boardmechanics/Compound.java new file mode 100644 index 0000000..9a8fc7d --- /dev/null +++ b/src/flowerwarspp/boardmechanics/Compound.java @@ -0,0 +1,31 @@ +package flowerwarspp.boardmechanics; + +import java.util.*; + +/** +* Contains FlowerSets which are connected over Ditches. Ditches are not included. +* @author Charlotte Ackva, Felix Spuehler, Martin Heide +**/ +public class Compound { + /** Contains the FlowerSets where all Flowers are safed in.*/ + private Collection<FlowerSet> flowerSets; + + /** + * Constructs a Component based on an initial ColoredFlower. + * @param firstFlower ColoredFlower the inital ColoredFlower + **/ + public Compound(ColoredFlower firstFlower) { + flowerSets = new Vector<FlowerSet>(1); + flowerSets.add(new FlowerSet(firstFlower)); + } + + /** + * Adds a Flower + * @author Charlotte Ackva, Felix Spuehler, Martin Heide + **/ + public void addFlower(ColoredFlower furtherFlower) { + FlowerSet dummy = new FlowerSet(furtherFlower); + dummy.setParentCompound(this); + flowerSets.add(dummy); + } +} diff --git a/src/flowerwarspp/boardmechanics/FlowerSet.java b/src/flowerwarspp/boardmechanics/FlowerSet.java new file mode 100644 index 0000000..d63fb51 --- /dev/null +++ b/src/flowerwarspp/boardmechanics/FlowerSet.java @@ -0,0 +1,57 @@ +package flowerwarspp.boardmechanics; + +import java.util.*; +/** +* Contains edge connected ColoredFlowers +* @author Charlotte Ackva, Felix Spuehler, Martin Heide +**/ +public class FlowerSet { + // auesser ColoredFlowers Referenzen + + /** Contains the flowers in the FlowerSet */ + private Collection<ColoredFlower> flowers; + + /** Holds the information about the parent Compound where the set is contained in */ + private Compound parentCompound; + + /** + * Constructs the set of Flowers + * @param firstFlower of type ColoredFlower which is the first entry in the set. + **/ + public FlowerSet(ColoredFlower firstFlower ) { + flowers = new Vector<ColoredFlower>(1); + add(firstFlower); + } + + /** + * Adds a further Flower to the set of Flowers + * @param furtherFlower of type ColoredFlower to be added + **/ + public void add(ColoredFlower furtherFlower) { + if(flowers.size() == 4) { + throw new IllegalArgumentException(); + } + furtherFlower.setParentFlowerSet(this); + flowers.add(furtherFlower); + // referenzen nach aussen anpassen + } + + /** + * Sets the parent Compound where the set is contained in. + * @param parent Compound + **/ + public void setParentCompound(Compound parent) { + parentCompound = parent; + } + + /** + * Return the parent Compound where the set is contained in. + * @return parent Compound + **/ + public Compound getParentCompound() { + return parentCompound; + } + + // merge + // split +} diff --git a/src/flowerwarspp/boardmechanics/FlowerType.java b/src/flowerwarspp/boardmechanics/FlowerType.java new file mode 100644 index 0000000..466a0fa --- /dev/null +++ b/src/flowerwarspp/boardmechanics/FlowerType.java @@ -0,0 +1,15 @@ +package flowerwarspp.boardmechanics; + +/** +* Defines possible Status Types for ColoredFlower +* +* implements Serializable missing?! +* @author Charlotte Ackva, Felix Spuehler, Martin Heide +**/ + +enum FlowerType { + RED, + BLUE, + FALLOW, + UNCOLORED +} diff --git a/src/flowerwarspp/boardmechanics/test.java b/src/flowerwarspp/boardmechanics/test.java deleted file mode 100644 index 4cf5aa5..0000000 --- a/src/flowerwarspp/boardmechanics/test.java +++ /dev/null @@ -1 +0,0 @@ -hallo -- GitLab From 26ed51b76989b7b8935736a23cd012ef11361004 Mon Sep 17 00:00:00 2001 From: Martin Heide <martin.heide@stud.uni-goettingen.de> Date: Fri, 15 Jun 2018 17:43:10 +0200 Subject: [PATCH 05/15] Added: FGWBoard, FGWBoardViewer --- src/flowerwarspp/boardmechanics/FGWBoard.java | 29 ++++++++++++++ .../boardmechanics/FGWBoardViewer.java | 39 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 src/flowerwarspp/boardmechanics/FGWBoard.java create mode 100644 src/flowerwarspp/boardmechanics/FGWBoardViewer.java diff --git a/src/flowerwarspp/boardmechanics/FGWBoard.java b/src/flowerwarspp/boardmechanics/FGWBoard.java new file mode 100644 index 0000000..a6ecada --- /dev/null +++ b/src/flowerwarspp/boardmechanics/FGWBoard.java @@ -0,0 +1,29 @@ +package flowerwarspp.boardmechanics; + +import java.util.*; +import flowerwarspp.preset.*; + +public class FGWBoard implements Board { + private final int boardSize; + + private Collection<ColoredFlower> uncoloredFlowers; + private Collection<Compound> redFlowers; + private Collection<Compound> blueFlowers; + private Collection<ColoredFlower> fallowFlowers; + + + + public FGWBoard(int boardSize) { + this.boardSize = boardSize; + } + + public FGWBoardViewer viewer() { + return new FGWBoardViewer(); + } + + + public void make(final Move move) throws IllegalStateException { + while(true) + System.out.println("I like to move it, move it, move"); + } +} diff --git a/src/flowerwarspp/boardmechanics/FGWBoardViewer.java b/src/flowerwarspp/boardmechanics/FGWBoardViewer.java new file mode 100644 index 0000000..c024699 --- /dev/null +++ b/src/flowerwarspp/boardmechanics/FGWBoardViewer.java @@ -0,0 +1,39 @@ +package flowerwarspp.boardmechanics; + +import java.util.*; +import flowerwarspp.preset.*; + +public class FGWBoardViewer implements Viewer { + + public PlayerColor getTurn() { + return PlayerColor.Red; + } + + public int getSize() { + return 0; + } + + public Status getStatus() { + return Status.Illegal; + } + + public Collection<Flower> getFlowers(final PlayerColor color) { + return new Vector<Flower>(); + } + + public Collection<Ditch> getDitches(final PlayerColor color) { + return new Vector<Ditch>(); + } + + public Collection<Move> getPossibleMoves() { + return new Vector<Move>(); + } + + public int getPoints(final PlayerColor color) { + return -1; + } + + + + +} -- GitLab From 94f62ed329a9291dad6e46fbd308fb9a36d7405d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sp=C3=BChler?= <felix.spuehler@stud.uni-goettingen.de> Date: Sat, 16 Jun 2018 13:08:02 +0200 Subject: [PATCH 06/15] doc ueberarbeitet --- src/flowerwarspp/boardmechanics/ColoredFlower.java | 6 +++--- src/flowerwarspp/boardmechanics/Compound.java | 1 - src/flowerwarspp/boardmechanics/FGWBoardViewer.java | 4 ++++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/flowerwarspp/boardmechanics/ColoredFlower.java b/src/flowerwarspp/boardmechanics/ColoredFlower.java index f3d3eb8..776737d 100644 --- a/src/flowerwarspp/boardmechanics/ColoredFlower.java +++ b/src/flowerwarspp/boardmechanics/ColoredFlower.java @@ -18,7 +18,7 @@ public class ColoredFlower extends Flower { private Vector<ColoredFlower> edgeNeighbors; /** Holds the node neighbored flowers */ private Vector<ColoredFlower> nodeNeighbors; - /** Holds an information {@see FlowerType} about the status of the ColoredFlower */ + /** Holds an information about the status of the ColoredFlower */ private FlowerType flowerType; /** Holds the information about the parent flower set where the flower is contained in */ private FlowerSet parentFlowerSet; @@ -41,12 +41,12 @@ public class ColoredFlower extends Flower { return edgeNeighbors; } /** sets the nodeNeighbors of the Flower - * @param vector of Nodeneighbored Flowers + * @param vectorNodes of Nodeneighbored Flowers **/ public void setNodeNeighbors(Vector<ColoredFlower> vectorNodes) { } /** sets the edgeNeighbors of the Flower - * @param vector of edgeneighbored Flowers + * @param vectorEdges of edgeneighbored Flowers **/ public void setEdgeNeighbors(Vector<ColoredFlower> vectorEdges) { } diff --git a/src/flowerwarspp/boardmechanics/Compound.java b/src/flowerwarspp/boardmechanics/Compound.java index 9a8fc7d..8c8bd40 100644 --- a/src/flowerwarspp/boardmechanics/Compound.java +++ b/src/flowerwarspp/boardmechanics/Compound.java @@ -21,7 +21,6 @@ public class Compound { /** * Adds a Flower - * @author Charlotte Ackva, Felix Spuehler, Martin Heide **/ public void addFlower(ColoredFlower furtherFlower) { FlowerSet dummy = new FlowerSet(furtherFlower); diff --git a/src/flowerwarspp/boardmechanics/FGWBoardViewer.java b/src/flowerwarspp/boardmechanics/FGWBoardViewer.java index c024699..faf65c4 100644 --- a/src/flowerwarspp/boardmechanics/FGWBoardViewer.java +++ b/src/flowerwarspp/boardmechanics/FGWBoardViewer.java @@ -3,6 +3,10 @@ package flowerwarspp.boardmechanics; import java.util.*; import flowerwarspp.preset.*; +/** +* Viewer for the FGWBoard +* @author Charlotte Ackva, Felix Spuehler, Martin Heide +**/ public class FGWBoardViewer implements Viewer { public PlayerColor getTurn() { -- GitLab From c5290642211f90273b314205afb5737e316ec16f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sp=C3=BChler?= <felix.spuehler@stud.uni-goettingen.de> Date: Sat, 16 Jun 2018 13:09:07 +0200 Subject: [PATCH 07/15] init ColoredDitch DitchType, ueberarbeitengit status! --- src/flowerwarspp/boardmechanics/ColoredDitch.java | 12 ++++++++++++ src/flowerwarspp/boardmechanics/DitchType.java | 15 +++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 src/flowerwarspp/boardmechanics/ColoredDitch.java create mode 100644 src/flowerwarspp/boardmechanics/DitchType.java diff --git a/src/flowerwarspp/boardmechanics/ColoredDitch.java b/src/flowerwarspp/boardmechanics/ColoredDitch.java new file mode 100644 index 0000000..35d794c --- /dev/null +++ b/src/flowerwarspp/boardmechanics/ColoredDitch.java @@ -0,0 +1,12 @@ +package flowerwarspp.boardmechanics; + +import flowerwarspp.preset.*; + +public class ColoredDitch extends Ditch { + private DitchType ditchType; + + public ColoredDitch(final Position first, final Position second) { + super(first, second); + ditchType = DitchType.UNCOLORED; + } +} \ No newline at end of file diff --git a/src/flowerwarspp/boardmechanics/DitchType.java b/src/flowerwarspp/boardmechanics/DitchType.java new file mode 100644 index 0000000..90bb2b5 --- /dev/null +++ b/src/flowerwarspp/boardmechanics/DitchType.java @@ -0,0 +1,15 @@ +package flowerwarspp.boardmechanics; + +/** +* Defines possible Status Types for ColoredFlower <br> +* +* implements Serializable missing?! +* @author Charlotte Ackva, Felix Spuehler, Martin Heide +**/ + +enum DitchType { + RED, + BLUE, + FALLOW, + UNCOLORED +} -- GitLab From 4e85cb429f43f932ffa54af3e5eb0f06c942344c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sp=C3=BChler?= <felix.spuehler@stud.uni-goettingen.de> Date: Sat, 16 Jun 2018 13:41:02 +0200 Subject: [PATCH 08/15] FGWBoard init Position Flowers Ditches --- src/flowerwarspp/boardmechanics/FGWBoard.java | 185 +++++++++++++++++- 1 file changed, 184 insertions(+), 1 deletion(-) diff --git a/src/flowerwarspp/boardmechanics/FGWBoard.java b/src/flowerwarspp/boardmechanics/FGWBoard.java index a6ecada..706fdc4 100644 --- a/src/flowerwarspp/boardmechanics/FGWBoard.java +++ b/src/flowerwarspp/boardmechanics/FGWBoard.java @@ -1,20 +1,37 @@ package flowerwarspp.boardmechanics; +import java.awt.Color; import java.util.*; import flowerwarspp.preset.*; + +/** + * Board for the board and game mechanics + * @author Charlotte Ackva, Felix Spuehler, Martin Heide +**/ public class FGWBoard implements Board { + public static final int MAX_VALUE = 31; private final int boardSize; - private Collection<ColoredFlower> uncoloredFlowers; + private HashMap<Integer, Position> allPositions; + + private HashMap<Integer, ColoredFlower> uncoloredFlowers; private Collection<Compound> redFlowers; private Collection<Compound> blueFlowers; private Collection<ColoredFlower> fallowFlowers; + private HashMap<Integer, ColoredDitch> uncoloredDitches; + private Collection<Ditch> redDitches; + private Collection<Ditch> blueDitches; + private Collection<Ditch> fallowDitches; + public FGWBoard(int boardSize) { this.boardSize = boardSize; + initializePositions(); + initizializeFlowers(); + initalizeDitches(); } public FGWBoardViewer viewer() { @@ -26,4 +43,170 @@ public class FGWBoard implements Board { while(true) System.out.println("I like to move it, move it, move"); } + + /** + * initialize all ColoredFlowers into the Hashmap {@link FGWBoard#allPositions} + */ + public void initializePositions() { + allPositions = new HashMap<Integer, Position>(); + for( int c = 1; c <= boardSize + 1; c++) { + for( int r = 1; c + r <= boardSize + 2; r++) { + Position dummyPosition = new Position(c, r); + allPositions.put(dummyPosition.hashCode(), dummyPosition); + } + } + + /* Ueberpreufung, ob alle Positions (richtig) erstellt wurden + System.out.println(allPositions.size()); + Set set = allPositions.entrySet(); + Iterator iterator = set.iterator(); + while(iterator.hasNext()) { + Map.Entry mentry = (Map.Entry)iterator.next(); + System.out.print("key is: "+ mentry.getKey() + " & Value is: "); + System.out.println(mentry.getValue()); + } + */ + } + + /** + * Calculates Hashcode of Position + * @param column column number + * @param row row number + * @return Hashcode + */ + public int calculatePositionHashCode(int column, int row) { + if( column < 1 || column > MAX_VALUE || row < 1 || row > MAX_VALUE ) { + throw new IllegalArgumentException(); + } + return column * MAX_VALUE + row; + } + + /** + * initialize all ColoredFlowers into the Hashmap {@link FGWBoard#uncoloredFlowers} + */ + public void initizializeFlowers() { + if( allPositions == null ) { + throw new UnsupportedOperationException(); + } + uncoloredFlowers = new HashMap<Integer, ColoredFlower>(); + + Position first; + Position second; + Position third; + ColoredFlower dummyColoredFlower; + + for( int c = 1; c <= boardSize; c++ ) { + for( int r = 1; c + r <= boardSize + 1; r++) { + first = allPositions.get( calculatePositionHashCode(c,r) ); + second = allPositions.get( calculatePositionHashCode(c+1,r) ); + third = allPositions.get( calculatePositionHashCode(c,r+1) ); + dummyColoredFlower = new ColoredFlower(first, second, third); + uncoloredFlowers.put( dummyColoredFlower.hashCode(), dummyColoredFlower); + + if( c > 1) { + first = allPositions.get( calculatePositionHashCode(c,r) ); + second = allPositions.get( calculatePositionHashCode(c,r+1) ); + third = allPositions.get( calculatePositionHashCode(c-1,r+1) ); + dummyColoredFlower = new ColoredFlower(first, second, third); + uncoloredFlowers.put( dummyColoredFlower.hashCode(), dummyColoredFlower); + } + } + } + + /*Ueberpreufung, ob alle Positions (richtig) erstellt wurden + System.out.println(uncoloredFlowers.size()); + Set set = uncoloredFlowers.entrySet(); + Iterator iterator = set.iterator(); + while(iterator.hasNext()) { + Map.Entry mentry = (Map.Entry)iterator.next(); + System.out.print("key is: "+ mentry.getKey() + " & Value is: "); + System.out.println(mentry.getValue()); + } + */ + } + + /** + * Calculates Hashcode of a Flower + * @param first one Position + * @param second another Position + * @param third last Position + * @return Hashcode + */ + public int calculateFlowerHashCode( Position first, Position second, Position third) { + // Keine Pruefung, ob Blume ueberhaupt im Feld... + Flower dummyFlower = new Flower(first, second, third); + return dummyFlower.hashCode(); + + } + + /** + * initialize all ColoredFlowers into the Hashmap {@link FGWBoard#uncoloredDitches} + */ + public void initalizeDitches() { + if( allPositions == null ) { + throw new UnsupportedOperationException(); + } + + uncoloredDitches = new HashMap<Integer, ColoredDitch>(); + + + Position first; + Position second; + ColoredDitch dummyColoredDitch; + for( int c = 1; c <= boardSize+1; c++ ) { + for( int r = 1; c + r <= boardSize + 2; r++) { + if( c + r < boardSize + 2) { + first = allPositions.get( calculatePositionHashCode(c,r) ); + second = allPositions.get( calculatePositionHashCode(c+1,r) ); + dummyColoredDitch = new ColoredDitch(first, second); + uncoloredDitches.put(dummyColoredDitch.hashCode(), dummyColoredDitch); + } + if( c + r < boardSize + 2) { + first = allPositions.get( calculatePositionHashCode(c,r) ); + second = allPositions.get( calculatePositionHashCode(c+1,r) ); + dummyColoredDitch = new ColoredDitch(first, second); + uncoloredDitches.put(dummyColoredDitch.hashCode(), dummyColoredDitch); + + first = allPositions.get( calculatePositionHashCode(c,r) ); + second = allPositions.get( calculatePositionHashCode(c,r+1) ); + dummyColoredDitch = new ColoredDitch(first, second); + uncoloredDitches.put(dummyColoredDitch.hashCode(), dummyColoredDitch); + } + if( r > 1) { + first = allPositions.get( calculatePositionHashCode(c,r) ); + second = allPositions.get( calculatePositionHashCode(c+1,r-1) ); + dummyColoredDitch = new ColoredDitch(first, second); + uncoloredDitches.put(dummyColoredDitch.hashCode(), dummyColoredDitch); + } + } + } + + /*Ueberpreufung, ob alle Positions (richtig) erstellt wurden + System.out.println(uncoloredDitches.size()); + Set set = uncoloredDitches.entrySet(); + Iterator iterator = set.iterator(); + while(iterator.hasNext()) { + Map.Entry mentry = (Map.Entry)iterator.next(); + System.out.print("key is: "+ mentry.getKey() + " & Value is: "); + System.out.println(mentry.getValue()); + } + */ + } + + public int calculateDitchHashCode(Position first, Position second) { + // Keine Pruefung, ob Graben ueberhaupt im Feld... + Ditch dummyDitch = new Ditch(first, second); + return dummyDitch.hashCode(); + } + + /** + * Main Methode, um einzelne Funktionen beim Implementieren zu testen <br> + * spaeter loeschen!!! <br> + * Aufruf mit {@code java -cp build flowerwarspp.boardmechanics.FGWBoard} + */ + public static void main(String[] args) { + FGWBoard MainBoard = new FGWBoard(6); + //int d = MainBoard.calculateDitchHashCode(new Position(3,3), new Position(3,4)); + //System.out.println(d); + } } -- GitLab From e5bedab38016c7e1bae6f238d22051e3e0ca88f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sp=C3=BChler?= <felix.spuehler@stud.uni-goettingen.de> Date: Sat, 16 Jun 2018 13:48:56 +0200 Subject: [PATCH 09/15] doc ueberarbeitet --- src/flowerwarspp/boardmechanics/ColoredDitch.java | 7 +++++++ src/flowerwarspp/boardmechanics/DitchType.java | 2 +- src/flowerwarspp/boardmechanics/FGWBoard.java | 6 ++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/flowerwarspp/boardmechanics/ColoredDitch.java b/src/flowerwarspp/boardmechanics/ColoredDitch.java index 35d794c..840639c 100644 --- a/src/flowerwarspp/boardmechanics/ColoredDitch.java +++ b/src/flowerwarspp/boardmechanics/ColoredDitch.java @@ -2,6 +2,13 @@ package flowerwarspp.boardmechanics; import flowerwarspp.preset.*; + +/** +* Extends the ditch class. Adds extra functionality: <br> +* -Status Variable (if Flower is Red, Blue, uncolored, fallow) <br> <br> +* erweitern!!! +* @author Charlotte Ackva, Felix Spuehler, Martin Heide +**/ public class ColoredDitch extends Ditch { private DitchType ditchType; diff --git a/src/flowerwarspp/boardmechanics/DitchType.java b/src/flowerwarspp/boardmechanics/DitchType.java index 90bb2b5..9883c0d 100644 --- a/src/flowerwarspp/boardmechanics/DitchType.java +++ b/src/flowerwarspp/boardmechanics/DitchType.java @@ -1,7 +1,7 @@ package flowerwarspp.boardmechanics; /** -* Defines possible Status Types for ColoredFlower <br> +* Defines possible Status Types for ColoredDitch <br> * * implements Serializable missing?! * @author Charlotte Ackva, Felix Spuehler, Martin Heide diff --git a/src/flowerwarspp/boardmechanics/FGWBoard.java b/src/flowerwarspp/boardmechanics/FGWBoard.java index 706fdc4..5bc7f09 100644 --- a/src/flowerwarspp/boardmechanics/FGWBoard.java +++ b/src/flowerwarspp/boardmechanics/FGWBoard.java @@ -193,6 +193,12 @@ public class FGWBoard implements Board { */ } + /** + * Calculates Hashcode of a Flower + * @param first one Position + * @param second other Position + * @return Hashcode + */ public int calculateDitchHashCode(Position first, Position second) { // Keine Pruefung, ob Graben ueberhaupt im Feld... Ditch dummyDitch = new Ditch(first, second); -- GitLab From 40f4486dc9f49b9271b8af35f60989ee5d34bab6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sp=C3=BChler?= <felix.spuehler@stud.uni-goettingen.de> Date: Sun, 17 Jun 2018 14:45:03 +0200 Subject: [PATCH 10/15] kleine Fehlerkorrektur --- src/flowerwarspp/boardmechanics/FGWBoard.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/flowerwarspp/boardmechanics/FGWBoard.java b/src/flowerwarspp/boardmechanics/FGWBoard.java index 5bc7f09..511590a 100644 --- a/src/flowerwarspp/boardmechanics/FGWBoard.java +++ b/src/flowerwarspp/boardmechanics/FGWBoard.java @@ -45,7 +45,7 @@ public class FGWBoard implements Board { } /** - * initialize all ColoredFlowers into the Hashmap {@link FGWBoard#allPositions} + * initialize all Positions into the Hashmap {@link FGWBoard#allPositions} */ public void initializePositions() { allPositions = new HashMap<Integer, Position>(); @@ -155,12 +155,6 @@ public class FGWBoard implements Board { ColoredDitch dummyColoredDitch; for( int c = 1; c <= boardSize+1; c++ ) { for( int r = 1; c + r <= boardSize + 2; r++) { - if( c + r < boardSize + 2) { - first = allPositions.get( calculatePositionHashCode(c,r) ); - second = allPositions.get( calculatePositionHashCode(c+1,r) ); - dummyColoredDitch = new ColoredDitch(first, second); - uncoloredDitches.put(dummyColoredDitch.hashCode(), dummyColoredDitch); - } if( c + r < boardSize + 2) { first = allPositions.get( calculatePositionHashCode(c,r) ); second = allPositions.get( calculatePositionHashCode(c+1,r) ); -- GitLab From 8973cfb385c06377ef34e732e188688090cd28fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sp=C3=BChler?= <felix.spuehler@stud.uni-goettingen.de> Date: Sun, 17 Jun 2018 15:32:46 +0200 Subject: [PATCH 11/15] ColoredDitch ColoredFlower erweitert --- .../boardmechanics/ColoredDitch.java | 42 ++++++++++++++++++ .../boardmechanics/ColoredFlower.java | 43 +++++++++++++++---- 2 files changed, 76 insertions(+), 9 deletions(-) diff --git a/src/flowerwarspp/boardmechanics/ColoredDitch.java b/src/flowerwarspp/boardmechanics/ColoredDitch.java index 840639c..9906306 100644 --- a/src/flowerwarspp/boardmechanics/ColoredDitch.java +++ b/src/flowerwarspp/boardmechanics/ColoredDitch.java @@ -1,5 +1,7 @@ package flowerwarspp.boardmechanics; +import java.util.*; + import flowerwarspp.preset.*; @@ -10,10 +12,50 @@ import flowerwarspp.preset.*; * @author Charlotte Ackva, Felix Spuehler, Martin Heide **/ public class ColoredDitch extends Ditch { + /** Holds neighbored flowers */ + private Vector<ColoredFlower> flowerNeighbors; + /** Holds neighbored ditches */ + private Vector<ColoredDitch> ditchNeighbors; + /** Holds an information about the status of the ColoredDitch */ private DitchType ditchType; public ColoredDitch(final Position first, final Position second) { super(first, second); ditchType = DitchType.UNCOLORED; } + + /** returns the flowerNeighbors of the Ditch + * @return vector of Flowers + **/ + public Collection<ColoredFlower> getFlowerNeighbors() { + return flowerNeighbors; + } + + /** returns the edgeNeighbors of the Flower + * @return vector of Ditches + **/ + public Collection<ColoredDitch> getDitchNeighbors() { + return ditchNeighbors; + } + + /** sets the flowerNeighbors of the Ditch + * @param vectorFlowers of Flowers + **/ + public void setNodeNeighbors(Vector<ColoredFlower> vectorFlowers) { + flowerNeighbors = vectorFlowers; + } + + /** sets the ditchNeighbors of the Ditch + * @param vectorDitches of Ditches + **/ + public void setEdgeNeighbors(Vector<ColoredDitch> vectorDitches) { + ditchNeighbors = vectorDitches; + } + + /** sets the type of the Ditch + * @param type DitchType - the new type of the Ditch + **/ + public void setFlowerType(DitchType type) { + ditchType = type; + } } \ No newline at end of file diff --git a/src/flowerwarspp/boardmechanics/ColoredFlower.java b/src/flowerwarspp/boardmechanics/ColoredFlower.java index 776737d..20981c8 100644 --- a/src/flowerwarspp/boardmechanics/ColoredFlower.java +++ b/src/flowerwarspp/boardmechanics/ColoredFlower.java @@ -18,6 +18,8 @@ public class ColoredFlower extends Flower { private Vector<ColoredFlower> edgeNeighbors; /** Holds the node neighbored flowers */ private Vector<ColoredFlower> nodeNeighbors; + /** Holds neighbored ditches */ + private Vector<ColoredDitch> ditchNeighbors; /** Holds an information about the status of the ColoredFlower */ private FlowerType flowerType; /** Holds the information about the parent flower set where the flower is contained in */ @@ -28,43 +30,66 @@ public class ColoredFlower extends Flower { super(first,second,third); flowerType = FlowerType.UNCOLORED; } + /** returns the nodeNeighbors of the Flower * @return vector of Nodeneighbored Flowers - **/ + **/ public Collection<ColoredFlower> getNodeNeighbors() { return nodeNeighbors; } + /** returns the edgeNeighbors of the Flower * @return vector of Edgeneighbored Flowers - **/ + **/ public Collection<ColoredFlower> getEdgeNeighbors() { return edgeNeighbors; } + + /** returns the ditchNeighbors of the Flower + * @return vector of Ditches + **/ + public Collection<ColoredDitch> getDitchNeighbors() { + return ditchNeighbors; + } + /** sets the nodeNeighbors of the Flower - * @param vectorNodes of Nodeneighbored Flowers - **/ + * @param vectorNodes of Flowers + **/ public void setNodeNeighbors(Vector<ColoredFlower> vectorNodes) { + nodeNeighbors = vectorNodes; } + /** sets the edgeNeighbors of the Flower - * @param vectorEdges of edgeneighbored Flowers - **/ + * @param vectorEdges of Flowers + **/ public void setEdgeNeighbors(Vector<ColoredFlower> vectorEdges) { + edgeNeighbors = vectorEdges; } + + /** sets the ditchNeighbors of the Flower + * @param vectorDitches of Ditches + **/ + public void setDitchNeighbors(Vector<ColoredDitch> vectorDitches) { + ditchNeighbors = vectorDitches; + } + /** sets the type of the Flower * @param type FlowerType - the new type of the Flower - **/ + **/ public void setFlowerType(FlowerType type) { flowerType = type; } + /** sets the parent Flower Set of the flower * @param parent FlowerSet - **/ + **/ public void setParentFlowerSet(FlowerSet parent) { parentFlowerSet = parent; } + /** returns the parent Flower Set of the flower * @return parent FlowerSet - **/ + **/ public FlowerSet getParentFlowerSet() { return parentFlowerSet; } -- GitLab From 8db7152ba44a3e95eee8299b939b2052d1541953 Mon Sep 17 00:00:00 2001 From: Felix <felix.strnad@stud.uni-goettingen.de> Date: Sun, 17 Jun 2018 17:11:31 +0200 Subject: [PATCH 12/15] Implement Human Player class --- src/flowerwarspp/player/HumanPlayer.java | 169 ++++++++++++++++++++++ src/flowerwarspp/player/PlayerStatus.java | 12 ++ src/flowerwarspp/preset/Player.java | 7 +- src/flowerwarspp/preset/Viewer.java | 8 +- 4 files changed, 192 insertions(+), 4 deletions(-) create mode 100644 src/flowerwarspp/player/HumanPlayer.java create mode 100644 src/flowerwarspp/player/PlayerStatus.java diff --git a/src/flowerwarspp/player/HumanPlayer.java b/src/flowerwarspp/player/HumanPlayer.java new file mode 100644 index 0000000..b9e8e91 --- /dev/null +++ b/src/flowerwarspp/player/HumanPlayer.java @@ -0,0 +1,169 @@ +package flowerwarspp.player; + + +import flowerwarspp.preset.Ditch; +import flowerwarspp.preset.Flower; +import flowerwarspp.preset.Move; +import flowerwarspp.preset.PlayerColor; +import flowerwarspp.preset.PlayerType; +import flowerwarspp.preset.Status; +import flowerwarspp.preset.Viewer; + +import java.rmi.RemoteException; +import java.util.Collection; + +import flowerwarspp.MyBoard; +/** + * Class for an interactive human player + * @version 1 + * + */ +public class HumanPlayer implements flowerwarspp.preset.Player { + + /** + * type of the player + */ + private final PlayerType type; + + /** + * Status in which this player is + * @see #PlayerStatus + */ + private PlayerStatus status; + + /** + * The color of this player + */ + private PlayerColor color; + + /** + * Each player has a copy of the current board that controls the game. + */ + private MyBoard myBoard; + + /** + * Viewer delievers the move the player can take. + */ + private Viewer viewer=null; + + /** + * Needed next move, given by the Viewer. + * It is an auxiliary variable, thus no getter and setter needed. + */ + private Move nextMove; + + /** + * Defines specialized Player constructor + */ + public HumanPlayer(Viewer viewer) { + this.type = PlayerType.HUMAN; + this.status = PlayerStatus.NOTEXISTING; + this.viewer = viewer; + + } + + //*********************** Get & Set Functions ************************** + /** + * Get the type of this player + * @return PlayerType type + */ + public PlayerType getType(){ + return this.type; + } + + + + //*********************** Function implementation ****************** + + + /** + * Inititializes the Player and tells him/her the size of the board. + * This function is called first by the game. + * @param boardSize int + * @param Color PlayerColor + */ + @Override + public void init(int boardSize, PlayerColor color) { + this.myBoard = new MyBoard(boardSize); + this.color = color; + if(viewer==null) { + this.viewer = new Viewer() ; + } + this.status=PlayerStatus.INITIALIZED; + } + + /** + * Requests a new draw of the player. + * @return + * @throws Exception + * @throws RemoteException + */ + @Override + public Move request() throws Exception{ + if(this.color == PlayerColor.Red){ //check the right order, red starts with request + if(this.status == PlayerStatus.NOTEXISTING){ + throw new Exception("Call init() before using request()"); + } + else if(this.status != PlayerStatus.UPDATE && this.status != PlayerStatus.INITIALIZED){ + throw new Exception("Update() cannot be called before request()"); + } + } + else if(this.status != PlayerStatus.UPDATE){ //Blue starts with update BEFORE request + throw new Exception("call update() before request()"); + } + while(this.status != PlayerStatus.REQUEST){ + this.nextMove = viewer.deliverNextMove(); + if(this.nextMove == null || myBoard.legalMove(this.nextMove, this.color)){ + this.status = PlayerStatus.REQUEST; + } + } + return this.nextMove; + } + + + + /** + * Confirms that own Status status is in agreement with the status on the MainBoard. + * @param status Status + * @throws Exception + * @throws RemoteException + */ + @Override + public void confirm(Status boardStatus) throws Exception, RemoteException { + if(this.status != PlayerStatus.REQUEST){ //check the correct order. Red player starts with request() + throw new Exception("call request() before confirm()"); + } + this.myBoard.place(this.nextMove); // TODO See how this is exact called in main function + if(boardStatus != this.myBoard.getBoardStatus()){ + throw new Exception("Confusion at boardstatus! Board of Player not in the same state as Control Board!"); + } + this.status = PlayerStatus.CONFIRM; + } + + /** + * + * @param opponentMove Move + * @param status Status + * @throws Exception + * @throws RemoteException + */ + @Override + public void update(Move opponentMove, Status boardStatus) throws Exception, RemoteException { + if(this.color == PlayerColor.Blue){ //check the correct order, blue player starts with update() + if(this.status == PlayerStatus.NOTEXISTING){ + throw new Exception("Call init() before using request()"); + } + else if(this.status != PlayerStatus.CONFIRM && this.status != PlayerStatus.INITIALIZED){ + throw new Exception("call confirm() before update()"); + } + } + else if(this.status != PlayerStatus.CONFIRM){ + throw new Exception("call confirm() before update()"); + } + this.myBoard.place(opponentMove); + if(boardStatus != this.myBoard.getBoardStatus()){ + throw new Exception("confusion at boardstatus"); + } + this.status = PlayerStatus.UPDATE; + } +} diff --git a/src/flowerwarspp/player/PlayerStatus.java b/src/flowerwarspp/player/PlayerStatus.java new file mode 100644 index 0000000..8130d06 --- /dev/null +++ b/src/flowerwarspp/player/PlayerStatus.java @@ -0,0 +1,12 @@ +package flowerwarspp.player; +/** +* Enum for the different states that the player objects can have +* @version 1 +*/ +public enum PlayerStatus { + NOTEXISTING, + INITIALIZED, + REQUEST, + CONFIRM, + UPDATE +} \ No newline at end of file diff --git a/src/flowerwarspp/preset/Player.java b/src/flowerwarspp/preset/Player.java index 15ada75..94b1db1 100644 --- a/src/flowerwarspp/preset/Player.java +++ b/src/flowerwarspp/preset/Player.java @@ -1,7 +1,7 @@ package flowerwarspp.preset; import java.rmi.*; - +import flowerwarspp.MyBoard; /** * <h1>Spieler-Schnittstelle</h1> * <p> @@ -68,7 +68,7 @@ public interface Player extends Remote { * @throws RemoteException * falls bei der Netzwerkkommunikation etwas schief gelaufen ist */ - void confirm(Status status) throws Exception, RemoteException; + void confirm(Status boardStatus) throws Exception, RemoteException; /** * Diese Funktion uebermittelt dem Spieler den Zug und Status des Zuges des Gegenspielers. Im Parameter {@code @@ -88,7 +88,7 @@ public interface Player extends Remote { * @throws RemoteException * falls bei der Netzwerkkommunikation etwas schief gelaufen ist */ - void update(Move opponentMove, Status status) throws Exception, RemoteException; + void update(Move opponentMove, Status boardStatus) throws Exception, RemoteException; /** * Initialisiere den Spieler und teile ihm die Groesse des Spielbretts und seine Spielerfarbe mit. Diese Funktion @@ -107,3 +107,4 @@ public interface Player extends Remote { */ void init(int boardSize, PlayerColor color) throws Exception, RemoteException; } + diff --git a/src/flowerwarspp/preset/Viewer.java b/src/flowerwarspp/preset/Viewer.java index fbce475..bccd818 100644 --- a/src/flowerwarspp/preset/Viewer.java +++ b/src/flowerwarspp/preset/Viewer.java @@ -75,6 +75,12 @@ public interface Viewer { // ******************************************************************** // Hier koennen weitere Funktionen ergaenzt werden... // ******************************************************************** - + + /** + * Delivers the next move of an player + * @return Move nextMove + */ + Move deliverNextMove(); + } -- GitLab From f12bc1c9fd916de11e61a28b6122293c84ebcb67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sp=C3=BChler?= <felix.spuehler@stud.uni-goettingen.de> Date: Sun, 17 Jun 2018 17:13:04 +0200 Subject: [PATCH 13/15] BoardViewer Update --- src/flowerwarspp/boardmechanics/FGWBoard.java | 53 ++++++++++++++++++- .../boardmechanics/FGWBoardViewer.java | 28 +++++++--- 2 files changed, 73 insertions(+), 8 deletions(-) diff --git a/src/flowerwarspp/boardmechanics/FGWBoard.java b/src/flowerwarspp/boardmechanics/FGWBoard.java index 511590a..c638abb 100644 --- a/src/flowerwarspp/boardmechanics/FGWBoard.java +++ b/src/flowerwarspp/boardmechanics/FGWBoard.java @@ -12,6 +12,10 @@ import flowerwarspp.preset.*; public class FGWBoard implements Board { public static final int MAX_VALUE = 31; private final int boardSize; + private Status status; + private PlayerColor currentPlayerColor; + private int pointsRed; + private int pointsBlue; private HashMap<Integer, Position> allPositions; @@ -29,13 +33,60 @@ public class FGWBoard implements Board { public FGWBoard(int boardSize) { this.boardSize = boardSize; + status = Status.Ok; + currentPlayerColor = PlayerColor.Red; + pointsRed = 0; + pointsBlue = 0; + initializePositions(); initizializeFlowers(); initalizeDitches(); } public FGWBoardViewer viewer() { - return new FGWBoardViewer(); + return new FGWBoardViewer(this); + } + + public int getBoardSize() { + return boardSize; + } + + public Status getStatus() { + return status; + } + + public PlayerColor getCurrentPlayerColor() { + return currentPlayerColor; + } + + public int getPoints( PlayerColor color ) { + if( color == PlayerColor.Red) { + return pointsRed; + } else { + return pointsBlue; + } + } + + public Collection<Flower> getRedFlowers() { + Vector<Flower> flowers = new Vector<Flower>(); + // hier wirklich eine Collection von Flowers zuerueckgeben nicht von Compound!!! + return flowers; + } + + public Collection<Flower> getBlueFlowers() { + Vector<Flower> flowers = new Vector<Flower>(); + // hier wirklich eine Collection von Flowers zuerueckgeben nicht von Compound!!! + return flowers; + } + + public Collection<Ditch> getRedDitches() { + // ColoredDitches in Ditches umwandeln + return redDitches; + } + + public Collection<Ditch> getBlueDitches() { + // ColoredDitches in Ditches umwandeln + return blueDitches; } diff --git a/src/flowerwarspp/boardmechanics/FGWBoardViewer.java b/src/flowerwarspp/boardmechanics/FGWBoardViewer.java index faf65c4..436310c 100644 --- a/src/flowerwarspp/boardmechanics/FGWBoardViewer.java +++ b/src/flowerwarspp/boardmechanics/FGWBoardViewer.java @@ -8,33 +8,47 @@ import flowerwarspp.preset.*; * @author Charlotte Ackva, Felix Spuehler, Martin Heide **/ public class FGWBoardViewer implements Viewer { + private FGWBoard board; + + public FGWBoardViewer(FGWBoard board){ + super(); + this.board = board; + } public PlayerColor getTurn() { - return PlayerColor.Red; + return board.getCurrentPlayerColor(); } public int getSize() { - return 0; + return board.getBoardSize(); } public Status getStatus() { - return Status.Illegal; + return board.getStatus(); } public Collection<Flower> getFlowers(final PlayerColor color) { - return new Vector<Flower>(); + if( color == PlayerColor.Red) { + return board.getRedFlowers(); + } else { + return board.getBlueFlowers(); + } } public Collection<Ditch> getDitches(final PlayerColor color) { - return new Vector<Ditch>(); + if( color == PlayerColor.Red) { + return board.getRedDitches(); + } else { + return board.getBlueDitches(); + } } public Collection<Move> getPossibleMoves() { - return new Vector<Move>(); + throw new UnsupportedOperationException(); } public int getPoints(final PlayerColor color) { - return -1; + return board.getPoints(color); } -- GitLab From 5536f56b1b1303b9651632f3594ee7cdc695ddaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sp=C3=BChler?= <felix.spuehler@stud.uni-goettingen.de> Date: Sun, 17 Jun 2018 17:21:00 +0200 Subject: [PATCH 14/15] Update BoardViewer Vol2 --- src/flowerwarspp/boardmechanics/FGWBoard.java | 38 ++++++++++--------- .../boardmechanics/FGWBoardViewer.java | 12 +----- 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/src/flowerwarspp/boardmechanics/FGWBoard.java b/src/flowerwarspp/boardmechanics/FGWBoard.java index c638abb..5e55160 100644 --- a/src/flowerwarspp/boardmechanics/FGWBoard.java +++ b/src/flowerwarspp/boardmechanics/FGWBoard.java @@ -25,9 +25,9 @@ public class FGWBoard implements Board { private Collection<ColoredFlower> fallowFlowers; private HashMap<Integer, ColoredDitch> uncoloredDitches; - private Collection<Ditch> redDitches; - private Collection<Ditch> blueDitches; - private Collection<Ditch> fallowDitches; + private Collection<ColoredDitch> redDitches; + private Collection<ColoredDitch> blueDitches; + private Collection<ColoredDitch> fallowDitches; @@ -67,29 +67,31 @@ public class FGWBoard implements Board { } } - public Collection<Flower> getRedFlowers() { - Vector<Flower> flowers = new Vector<Flower>(); - // hier wirklich eine Collection von Flowers zuerueckgeben nicht von Compound!!! - return flowers; - } + public Collection<Flower> getFlowers(PlayerColor color) { + Collection<Compound> coloredFlowers; + if( color == PlayerColor.Red) { + coloredFlowers = redFlowers; + } else { + coloredFlowers = blueFlowers; + } - public Collection<Flower> getBlueFlowers() { - Vector<Flower> flowers = new Vector<Flower>(); // hier wirklich eine Collection von Flowers zuerueckgeben nicht von Compound!!! + Vector<Flower> flowers = new Vector<Flower>(); return flowers; } - public Collection<Ditch> getRedDitches() { - // ColoredDitches in Ditches umwandeln - return redDitches; - } - - public Collection<Ditch> getBlueDitches() { + public Collection<Ditch> getDitches( PlayerColor color ) { + Collection<ColoredDitch> coloredDitches; + if( color == PlayerColor.Red ) { + coloredDitches = redDitches; + } else { + coloredDitches = blueDitches; + } // ColoredDitches in Ditches umwandeln - return blueDitches; + Vector<Ditch> ditches = new Vector<Ditch>(); + return ditches; } - public void make(final Move move) throws IllegalStateException { while(true) System.out.println("I like to move it, move it, move"); diff --git a/src/flowerwarspp/boardmechanics/FGWBoardViewer.java b/src/flowerwarspp/boardmechanics/FGWBoardViewer.java index 436310c..ecbd15f 100644 --- a/src/flowerwarspp/boardmechanics/FGWBoardViewer.java +++ b/src/flowerwarspp/boardmechanics/FGWBoardViewer.java @@ -28,19 +28,11 @@ public class FGWBoardViewer implements Viewer { } public Collection<Flower> getFlowers(final PlayerColor color) { - if( color == PlayerColor.Red) { - return board.getRedFlowers(); - } else { - return board.getBlueFlowers(); - } + return board.getFlowers(color); } public Collection<Ditch> getDitches(final PlayerColor color) { - if( color == PlayerColor.Red) { - return board.getRedDitches(); - } else { - return board.getBlueDitches(); - } + return board.getDitches(color); } public Collection<Move> getPossibleMoves() { -- GitLab From 3a5bed0d5d489ecdae4e0ae38dcda8a8b94d9e81 Mon Sep 17 00:00:00 2001 From: Felix <felix.strnad@stud.uni-goettingen.de> Date: Sun, 17 Jun 2018 21:29:36 +0200 Subject: [PATCH 15/15] Updated Player with FGWBoard --- .classpath | 9 +++++ .gitignore | 1 + .project | 17 +++++++++ .../flowerwarspp/MyBoard.java | 4 +++ src/flowerwarspp/Main.java | 11 ++++-- .../boardmechanics/FGWBoardViewer.java | 4 +++ src/flowerwarspp/player/HumanPlayer.java | 36 +++++++++---------- 7 files changed, 60 insertions(+), 22 deletions(-) create mode 100644 .classpath create mode 100644 .project diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..f2588a1 --- /dev/null +++ b/.classpath @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="src" path="example-implementation"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="lib" path="FlowerWarsPP-Display.jar"/> + <classpathentry kind="lib" path="FlowerWarsPP-Tester.jar"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/.gitignore b/.gitignore index df22391..3b7b328 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ doc/ *.class *.jar +/bin/ diff --git a/.project b/.project new file mode 100644 index 0000000..59447ea --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>floragnomewars</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/example-implementation/flowerwarspp/MyBoard.java b/example-implementation/flowerwarspp/MyBoard.java index 8c3fd99..6c45c0f 100644 --- a/example-implementation/flowerwarspp/MyBoard.java +++ b/example-implementation/flowerwarspp/MyBoard.java @@ -59,4 +59,8 @@ public class MyBoard implements Board { } }; } + + public boolean legalMove(Move nextMove, PlayerColor color) { + return false; + } } diff --git a/src/flowerwarspp/Main.java b/src/flowerwarspp/Main.java index 1930c66..c63a267 100644 --- a/src/flowerwarspp/Main.java +++ b/src/flowerwarspp/Main.java @@ -1,12 +1,15 @@ package flowerwarspp; import flowerwarspp.boarddisplay.BoardDisplay; +import flowerwarspp.boardmechanics.FGWBoard; +import flowerwarspp.boardmechanics.FGWBoardViewer; +import flowerwarspp.player.HumanPlayer; import flowerwarspp.preset.*; public class Main { public static void main(String[] args) { - Board board = new MyBoard(6); - Viewer viewer = board.viewer(); + FGWBoard board = new FGWBoard(6); + FGWBoardViewer viewer = board.viewer(); BoardDisplay boardDisplay = new BoardDisplay(); boardDisplay.setViewer(viewer); @@ -14,5 +17,7 @@ public class Main { board.make(move); boardDisplay.update(move); boardDisplay.showStatus(viewer.getStatus()); - } + + HumanPlayer human = new HumanPlayer(viewer); + } } diff --git a/src/flowerwarspp/boardmechanics/FGWBoardViewer.java b/src/flowerwarspp/boardmechanics/FGWBoardViewer.java index ecbd15f..b3f041e 100644 --- a/src/flowerwarspp/boardmechanics/FGWBoardViewer.java +++ b/src/flowerwarspp/boardmechanics/FGWBoardViewer.java @@ -43,6 +43,10 @@ public class FGWBoardViewer implements Viewer { return board.getPoints(color); } + public Move deliverNextMove() { + return null; + } + diff --git a/src/flowerwarspp/player/HumanPlayer.java b/src/flowerwarspp/player/HumanPlayer.java index b9e8e91..085da0d 100644 --- a/src/flowerwarspp/player/HumanPlayer.java +++ b/src/flowerwarspp/player/HumanPlayer.java @@ -1,20 +1,16 @@ package flowerwarspp.player; - -import flowerwarspp.preset.Ditch; -import flowerwarspp.preset.Flower; import flowerwarspp.preset.Move; import flowerwarspp.preset.PlayerColor; import flowerwarspp.preset.PlayerType; import flowerwarspp.preset.Status; -import flowerwarspp.preset.Viewer; - +import flowerwarspp.boardmechanics.FGWBoard; +import flowerwarspp.boardmechanics.FGWBoardViewer; import java.rmi.RemoteException; -import java.util.Collection; -import flowerwarspp.MyBoard; /** * Class for an interactive human player + * @author Felix Strnad * @version 1 * */ @@ -39,12 +35,12 @@ public class HumanPlayer implements flowerwarspp.preset.Player { /** * Each player has a copy of the current board that controls the game. */ - private MyBoard myBoard; + private FGWBoard myBoard; /** - * Viewer delievers the move the player can take. + * Viewer delivers the move the player can take. */ - private Viewer viewer=null; + private FGWBoardViewer viewer=null; /** * Needed next move, given by the Viewer. @@ -55,7 +51,7 @@ public class HumanPlayer implements flowerwarspp.preset.Player { /** * Defines specialized Player constructor */ - public HumanPlayer(Viewer viewer) { + public HumanPlayer(FGWBoardViewer viewer) { this.type = PlayerType.HUMAN; this.status = PlayerStatus.NOTEXISTING; this.viewer = viewer; @@ -84,10 +80,10 @@ public class HumanPlayer implements flowerwarspp.preset.Player { */ @Override public void init(int boardSize, PlayerColor color) { - this.myBoard = new MyBoard(boardSize); + this.myBoard = new FGWBoard(boardSize); this.color = color; if(viewer==null) { - this.viewer = new Viewer() ; + this.viewer = new FGWBoardViewer(myBoard) ; } this.status=PlayerStatus.INITIALIZED; } @@ -113,7 +109,9 @@ public class HumanPlayer implements flowerwarspp.preset.Player { } while(this.status != PlayerStatus.REQUEST){ this.nextMove = viewer.deliverNextMove(); - if(this.nextMove == null || myBoard.legalMove(this.nextMove, this.color)){ + + //if(this.nextMove == null || myBoard.legalMove(this.nextMove, this.color)){ + if(this.nextMove == null ){ this.status = PlayerStatus.REQUEST; } } @@ -133,9 +131,9 @@ public class HumanPlayer implements flowerwarspp.preset.Player { if(this.status != PlayerStatus.REQUEST){ //check the correct order. Red player starts with request() throw new Exception("call request() before confirm()"); } - this.myBoard.place(this.nextMove); // TODO See how this is exact called in main function - if(boardStatus != this.myBoard.getBoardStatus()){ - throw new Exception("Confusion at boardstatus! Board of Player not in the same state as Control Board!"); + this.myBoard.make(this.nextMove); + if(boardStatus != this.myBoard.getStatus()){ + throw new Exception("Confusion! Board of Player not in the same state as Control Board!"); } this.status = PlayerStatus.CONFIRM; } @@ -160,8 +158,8 @@ public class HumanPlayer implements flowerwarspp.preset.Player { else if(this.status != PlayerStatus.CONFIRM){ throw new Exception("call confirm() before update()"); } - this.myBoard.place(opponentMove); - if(boardStatus != this.myBoard.getBoardStatus()){ + this.myBoard.make(opponentMove); + if(boardStatus != this.myBoard.getStatus()){ throw new Exception("confusion at boardstatus"); } this.status = PlayerStatus.UPDATE; -- GitLab