From eecd2fc1306c5793d80cb31da4fbe4f547846f94 Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Sat, 3 Feb 2024 15:14:12 +0100 Subject: [PATCH 01/50] setFirstCard --- src/main/java/de/hsfulda/onses/services/GameService.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index 2e9424b..d316d7a 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -13,6 +13,14 @@ public class GameService { this.game.setGameService(this); fillDrawDeck(); shuffleDeck(); + + for (int i = 0; i < this.game.getDrawCardDeck().size(); i++) { + Card card = this.game.getDrawCardDeck().get(i); + if (card.getColor() != Card.Color.BLACK) { + this.game.setLastPlayedCard(card); + break; + } + } } public GameService() { this(new Game()); From 73c6a25694a3e0eb1125a46f5e87a58e71d31cc1 Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Sat, 3 Feb 2024 15:29:21 +0100 Subject: [PATCH 02/50] Test.CheckFirstCardIsSet --- src/test/java/de/hsfulda/onses/GameServiceTest.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index 81ab433..91d2c82 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -276,4 +276,15 @@ public class GameServiceTest { assertEquals(expected, counter); } + @Test + @DisplayName("CheckFirstCardIsSet") + public void CheckFirstCardIsSet () + { + GameService gameService = new GameService(); + Card card = gameService.getGame().getLastPlayedCard(); + + boolean answer = card != null; + + assertTrue(answer); + } } From dfe8814ac67862dd53b57952b4931f8094f2b63d Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Sat, 3 Feb 2024 15:30:48 +0100 Subject: [PATCH 03/50] Test.CheckFirstCardIsNotBlack --- src/test/java/de/hsfulda/onses/GameServiceTest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index 91d2c82..71f2e14 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -287,4 +287,16 @@ public class GameServiceTest { assertTrue(answer); } + + @Test + @DisplayName("CheckFirstCardIsNotBlack") + public void CheckFirstCardIsNotBlack () + { + GameService gameService = new GameService(); + Card card = gameService.getGame().getLastPlayedCard(); + + boolean answer = card.getColor() != Card.Color.BLACK; + + assertTrue(answer); + } } From 46732eae371d3a3a0c839d7cdd6746586e7bf90a Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Sat, 3 Feb 2024 15:33:49 +0100 Subject: [PATCH 04/50] ResetActionCard --- .../hsfulda/onses/services/GameService.java | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index d316d7a..586bde9 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -8,6 +8,7 @@ import java.util.Collections; public class GameService { private final Game game; + public GameService(Game game) { this.game = game; this.game.setGameService(this); @@ -22,6 +23,7 @@ public class GameService { } } } + public GameService() { this(new Game()); } @@ -33,6 +35,7 @@ public class GameService { public void nextPlayer() { game.getPlayerService().nextTurn(); } + public void drawCard(int amount) { Player player = null; if (game.getPlayerService().getCurrentTurn()) { @@ -41,18 +44,23 @@ public class GameService { player = game.getPlayerService().getPlayerList().getLast(); } for (int i = 0; i < amount; i++) { - player.getPlayerDeck().add(game.getDrawCardDeck().getFirst()); - game.getDrawCardDeck().removeFirst(); + player.getPlayerDeck().add(game.getDrawCardDeck().getFirst()); + game.getDrawCardDeck().removeFirst(); } if (amount != 1) { nextPlayer(); } } - public void playCard(Card card) - { - // add lastPlayedCard back to drawCardDeck - game.setLastPlayedCard(card); - // check for special rules (draw, colorchoose, skip,...) + + public void playCard(Card card) { + // add lastPlayedCard back to drawCardDeck + Card lastCard = game.getLastPlayedCard(); + if (lastCard.getValue() == Card.Value.CHOOSE || lastCard.getValue() == Card.Value.CHOOSEDRAW) { + lastCard.setColor(Card.Color.BLACK); + } + game.addCardToDrawCardDeck(lastCard); + game.setLastPlayedCard(card); + // check for special rules (draw, colorchoose, skip,...) // Skip if (card.getValue() == Card.Value.SKIP) { nextPlayer(); @@ -85,8 +93,7 @@ public class GameService { } } - public boolean legalMove(Card card) - { + public boolean legalMove(Card card) { boolean legalMoveFound = false; Card lastCard = game.getLastPlayedCard(); // rules: @@ -100,16 +107,16 @@ public class GameService { } public void fillDrawDeck() { - for (Card.Color i : Card.Color.values()){ - for (Card.Value j : Card.Value.values()){ - if (i != Card.Color.BLACK && j != Card.Value.CHOOSE && j != Card.Value.CHOOSEDRAW){ + for (Card.Color i : Card.Color.values()) { + for (Card.Value j : Card.Value.values()) { + if (i != Card.Color.BLACK && j != Card.Value.CHOOSE && j != Card.Value.CHOOSEDRAW) { game.addCardToDrawCardDeck(new Card().setColor(i).setValue(j)); game.addCardToDrawCardDeck(new Card().setColor(i).setValue(j)); } } } - for (int i = 0; i != 4; i++){ + for (int i = 0; i != 4; i++) { game.addCardToDrawCardDeck(new Card().setColor(Card.Color.BLACK).setValue(Card.Value.CHOOSE)); game.addCardToDrawCardDeck(new Card().setColor(Card.Color.BLACK).setValue(Card.Value.CHOOSEDRAW)); } From b2aa530e2fcc48af33b94d5149d1d535c2098029 Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Sat, 3 Feb 2024 15:35:09 +0100 Subject: [PATCH 05/50] Test.CheckResetOnBlackCards --- src/test/java/de/hsfulda/onses/GameServiceTest.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index 71f2e14..d8a54f2 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -299,4 +299,17 @@ public class GameServiceTest { assertTrue(answer); } + + @Test + @DisplayName("CheckResetOnBlackCards") + public void CheckResetOnBlackCards () { + GameService gameService = new GameService(); + gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.RED).setValue(Card.Value.FIVE)); + gameService.playCard(new Card().setColor(Card.Color.BLACK).setValue(Card.Value.CHOOSE)); + gameService.playCard(new Card().setColor(Card.Color.YELLOW).setValue(Card.Value.FIVE)); + + Card card = gameService.getGame().getDrawCardDeck().getLast(); + + assertEquals(Card.Color.BLACK, card.getColor()); + } } From b9a8f9a26e5ad626708527dd6c84efd0a409a01c Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Sat, 3 Feb 2024 16:47:22 +0100 Subject: [PATCH 06/50] refactoring: addLastPlayedCardToDrawCardDeck --- .../hsfulda/onses/services/GameService.java | 8 +++- .../de/hsfulda/onses/GameServiceTest.java | 45 +++++++++---------- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index 586bde9..55c5c98 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -52,13 +52,17 @@ public class GameService { } } - public void playCard(Card card) { - // add lastPlayedCard back to drawCardDeck + public void addLastPlayedCardToDrawCardDeck() { Card lastCard = game.getLastPlayedCard(); if (lastCard.getValue() == Card.Value.CHOOSE || lastCard.getValue() == Card.Value.CHOOSEDRAW) { lastCard.setColor(Card.Color.BLACK); } game.addCardToDrawCardDeck(lastCard); + } + + public void playCard(Card card) { + // add lastPlayedCard back to drawCardDeck + this.addLastPlayedCardToDrawCardDeck(); game.setLastPlayedCard(card); // check for special rules (draw, colorchoose, skip,...) // Skip diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index d8a54f2..2ea1066 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -3,6 +3,7 @@ package de.hsfulda.onses; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; + import static org.junit.jupiter.api.Assertions.*; import de.hsfulda.onses.models.Card; @@ -22,6 +23,7 @@ public class GameServiceTest { // assert assertEquals(input, answer); } + @Test @DisplayName("playCardBlackChoose") public void playCardBlackChoose() { @@ -49,6 +51,7 @@ public class GameServiceTest { // assert assertEquals(expected, answer); } + @Test @DisplayName("legalMoveSameColorBlue") public void legalMoveSameColorBlue() { @@ -63,9 +66,10 @@ public class GameServiceTest { // assert assertEquals(expected, answer); } + @Test @DisplayName("FillDrawCardDeck") - public void FillDrawCardDeck() { + public void FillDrawCardDeck() { GameService gameService = new GameService(); int expected = gameService.getGame().getDrawCardDeck().size() + 112; @@ -134,6 +138,7 @@ public class GameServiceTest { // assert assertEquals(expected, answer); } + @Test @DisplayName("ShuffelDeck") public void ShuffelDeck() { @@ -149,7 +154,7 @@ public class GameServiceTest { for (int i = 0; i < notshuffled.getGame().getDrawCardDeck().size(); i++) { if (shuffled.getGame().getDrawCardDeck().get(i).getValue() == notshuffled.getGame().getDrawCardDeck().get(i).getValue() && shuffled.getGame().getDrawCardDeck().get(i).getColor() == notshuffled.getGame().getDrawCardDeck().get(i).getColor()) { - counter ++; + counter++; } if (counter == notshuffled.getGame().getDrawCardDeck().size()) { fail("Deck wurde nicht richtig gemischt"); @@ -159,8 +164,7 @@ public class GameServiceTest { @Test @DisplayName("RelationshipGameService_Game") - public void RelationshipGameService_Game() - { + public void RelationshipGameService_Game() { // arrange GameService expected = new GameService(); //act @@ -168,10 +172,10 @@ public class GameServiceTest { // assert assertEquals(expected, answer); } + @Test @DisplayName("allRelationsTest") - public void allRelationsTest () - { + public void allRelationsTest() { // arrange GameService expected = new GameService(); //act @@ -186,8 +190,7 @@ public class GameServiceTest { @Test @DisplayName("SkipTest") - public void SkipTest () - { + public void SkipTest() { GameService gameservice = new GameService(); boolean expected = gameservice.getGame().getPlayerService().getCurrentTurn(); @@ -198,8 +201,7 @@ public class GameServiceTest { @Test @DisplayName("ReverseTest") - public void ReverseTest () - { + public void ReverseTest() { GameService gameservice = new GameService(); boolean expected = gameservice.getGame().getPlayerService().getCurrentTurn(); @@ -210,8 +212,7 @@ public class GameServiceTest { @Test @DisplayName("ChooseTest") - public void ChooseTest () - { + public void ChooseTest() { GameService gameservice = new GameService(); boolean expected = true; boolean answer = false; @@ -228,8 +229,7 @@ public class GameServiceTest { @Test @DisplayName("ChooseDrawTest") - public void ChooseDrawTest () - { + public void ChooseDrawTest() { GameService gameservice = new GameService(); boolean expected = true; boolean answer = false; @@ -246,8 +246,7 @@ public class GameServiceTest { @Test @DisplayName("DrawCardDeckTest") - public void DrawCardDeckTest () - { + public void DrawCardDeckTest() { GameService gameService = new GameService(); int before = gameService.getGame().getDrawCardDeck().size(); gameService.drawCard(4); @@ -260,15 +259,15 @@ public class GameServiceTest { @Test @DisplayName("DrawCardDeckRemoveTest") - public void DrawCardDeckRemoveTest () - { + public void DrawCardDeckRemoveTest() { GameService gameService = new GameService(); Card card = gameService.getGame().getDrawCardDeck().getFirst(); gameService.drawCard(1); int counter = 0; int expected = 0; for (int i = 0; i < gameService.getGame().getDrawCardDeck().size(); i++) { - if (gameService.getGame().getDrawCardDeck().get(i).getColor() == card.getColor() && gameService.getGame().getDrawCardDeck().get(i).getValue() == card.getValue()) counter++; + if (gameService.getGame().getDrawCardDeck().get(i).getColor() == card.getColor() && gameService.getGame().getDrawCardDeck().get(i).getValue() == card.getValue()) + counter++; } if (card.getColor() == Card.Color.BLACK) expected = 3; else expected = 1; @@ -278,8 +277,7 @@ public class GameServiceTest { @Test @DisplayName("CheckFirstCardIsSet") - public void CheckFirstCardIsSet () - { + public void CheckFirstCardIsSet() { GameService gameService = new GameService(); Card card = gameService.getGame().getLastPlayedCard(); @@ -290,8 +288,7 @@ public class GameServiceTest { @Test @DisplayName("CheckFirstCardIsNotBlack") - public void CheckFirstCardIsNotBlack () - { + public void CheckFirstCardIsNotBlack() { GameService gameService = new GameService(); Card card = gameService.getGame().getLastPlayedCard(); @@ -302,7 +299,7 @@ public class GameServiceTest { @Test @DisplayName("CheckResetOnBlackCards") - public void CheckResetOnBlackCards () { + public void CheckResetOnBlackCards() { GameService gameService = new GameService(); gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.RED).setValue(Card.Value.FIVE)); gameService.playCard(new Card().setColor(Card.Color.BLACK).setValue(Card.Value.CHOOSE)); From 8bb224a07b2101e181a977f7ad9d229588378378 Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Sat, 3 Feb 2024 16:50:41 +0100 Subject: [PATCH 07/50] refactoring: setFirstCard --- .../hsfulda/onses/services/GameService.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index 55c5c98..766a28f 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -14,14 +14,7 @@ public class GameService { this.game.setGameService(this); fillDrawDeck(); shuffleDeck(); - - for (int i = 0; i < this.game.getDrawCardDeck().size(); i++) { - Card card = this.game.getDrawCardDeck().get(i); - if (card.getColor() != Card.Color.BLACK) { - this.game.setLastPlayedCard(card); - break; - } - } + setFirstCard(); } public GameService() { @@ -130,4 +123,14 @@ public class GameService { Collections.shuffle(game.getDrawCardDeck()); } + public void setFirstCard() { + for (int i = 0; i < this.game.getDrawCardDeck().size(); i++) { + Card card = this.game.getDrawCardDeck().get(i); + if (card.getColor() != Card.Color.BLACK) { + this.game.setLastPlayedCard(card); + break; + } + } + } + } From 65612f4e8435320c906b920497d17eccb154e20b Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Sat, 3 Feb 2024 17:01:54 +0100 Subject: [PATCH 08/50] refactoring: adjusting playCard --- .../hsfulda/onses/services/GameService.java | 55 +++++++++---------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index 766a28f..ec2d647 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -59,34 +59,33 @@ public class GameService { game.setLastPlayedCard(card); // check for special rules (draw, colorchoose, skip,...) // Skip - if (card.getValue() == Card.Value.SKIP) { - nextPlayer(); - nextPlayer(); - } - // Reverse - if (card.getValue() == Card.Value.REVERSE) { - nextPlayer(); - nextPlayer(); - } - // Choose - if (card.getValue() == Card.Value.CHOOSE) { - // Abfrage Farbe - Card.Color color = Card.Color.BLUE; //Vorübergehend Blau - game.changeLastPlayedCardColor(color); - nextPlayer(); - } - // Draw - if (card.getValue() == Card.Value.DRAWTWO) { - nextPlayer(); - drawCard(2); - } - // ChooseDraw - if (card.getValue() == Card.Value.CHOOSEDRAW) { - // Abfrage Farbe - Card.Color color = Card.Color.BLUE; //Vorübergehend Blau - game.changeLastPlayedCardColor(color); - nextPlayer(); - drawCard(4); + + switch (card.getValue()) { + case SKIP: + nextPlayer(); + nextPlayer(); + break; + case REVERSE: + nextPlayer(); + nextPlayer(); + break; + case CHOOSE: + // Abfrage Farbe + Card.Color color = Card.Color.BLUE; //Vorübergehend Blau + game.changeLastPlayedCardColor(color); + nextPlayer(); + break; + case CHOOSEDRAW: + // Abfrage Farbe + Card.Color color1 = Card.Color.BLUE; //Vorübergehend Blau + game.changeLastPlayedCardColor(color1); + nextPlayer(); + drawCard(4); + break; + case DRAWTWO: + nextPlayer(); + drawCard(2); + break; } } From c6e75dfd85b2a8b7782f82c4542ff76e0ba21175 Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Sat, 3 Feb 2024 17:06:47 +0100 Subject: [PATCH 09/50] refactoring: addChangeColor --- .../de/hsfulda/onses/services/GameService.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index ec2d647..5600b04 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -53,6 +53,12 @@ public class GameService { game.addCardToDrawCardDeck(lastCard); } + public void changeColor() { + // Abfrage Farbe + Card.Color color = Card.Color.BLUE; //Vorübergehend Blau + game.changeLastPlayedCardColor(color); + } + public void playCard(Card card) { // add lastPlayedCard back to drawCardDeck this.addLastPlayedCardToDrawCardDeck(); @@ -70,15 +76,11 @@ public class GameService { nextPlayer(); break; case CHOOSE: - // Abfrage Farbe - Card.Color color = Card.Color.BLUE; //Vorübergehend Blau - game.changeLastPlayedCardColor(color); + changeColor(); nextPlayer(); break; case CHOOSEDRAW: - // Abfrage Farbe - Card.Color color1 = Card.Color.BLUE; //Vorübergehend Blau - game.changeLastPlayedCardColor(color1); + changeColor(); nextPlayer(); drawCard(4); break; From 74807391e67f43344e08a8b758427d93e2aa02a7 Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Sat, 3 Feb 2024 17:31:15 +0100 Subject: [PATCH 10/50] addRemoveCardFromPlayerDeck --- .../hsfulda/onses/services/PlayerService.java | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/services/PlayerService.java b/src/main/java/de/hsfulda/onses/services/PlayerService.java index 3b32e3a..1d74ef9 100644 --- a/src/main/java/de/hsfulda/onses/services/PlayerService.java +++ b/src/main/java/de/hsfulda/onses/services/PlayerService.java @@ -2,6 +2,7 @@ package de.hsfulda.onses.services; import de.hsfulda.onses.models.Game; import de.hsfulda.onses.models.Player; +import de.hsfulda.onses.models.Card; import java.util.ArrayList; @@ -15,12 +16,12 @@ public class PlayerService { public ArrayList getPlayerList() { return playerList; } + public void addPlayerToList(Player player) { playerList.add(player); } - public void nextTurn() - { + public void nextTurn() { currentTurn = !currentTurn; } @@ -43,9 +44,29 @@ public class PlayerService { return this; } - public PlayerService() - { + public PlayerService() { addPlayerToList(new Player().setPlayerService(this)); addPlayerToList(new Player().setPlayerService(this)); } + + public void removeCardFromPlayerDeck(Card card) { + Player player; + if (this.currentTurn) { + player = playerList.getFirst(); + for (int i = 0; i < player.getPlayerDeck().size(); i++) { + if (player.getPlayerDeck().get(i) == card) { + player.getPlayerDeck().remove(i); + break; + } + } + } else { + player = playerList.getLast(); + for (int i = 0; i < player.getPlayerDeck().size(); i++) { + if (player.getPlayerDeck().get(i) == card) { + player.getPlayerDeck().remove(i); + break; + } + } + } + } } From 7984827407130d8b6132b0ac40a3706f807b8883 Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Sat, 3 Feb 2024 17:48:31 +0100 Subject: [PATCH 11/50] Test.CheckForCardRemoval --- .../de/hsfulda/onses/PlayerServiceTest.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/PlayerServiceTest.java b/src/test/java/de/hsfulda/onses/PlayerServiceTest.java index 5dc2fd2..0bb951a 100644 --- a/src/test/java/de/hsfulda/onses/PlayerServiceTest.java +++ b/src/test/java/de/hsfulda/onses/PlayerServiceTest.java @@ -1,6 +1,8 @@ package de.hsfulda.onses; +import com.sun.tools.jconsole.JConsoleContext; +import de.hsfulda.onses.models.Card; import de.hsfulda.onses.services.PlayerService; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -90,4 +92,22 @@ public class PlayerServiceTest { assertEquals(expected, answer1); assertEquals(expected, answer2); } + + @Test + @DisplayName("CheckForCardRemoval") + void CheckForCardRemoval() { + PlayerService playerService = new PlayerService(); + + Card card1 = new Card().setColor(Card.Color.YELLOW).setValue(Card.Value.TWO); + Card card2 = new Card().setColor(Card.Color.RED).setValue(Card.Value.ONE); + + playerService.getPlayerList().getFirst().addCardToPlayerDeck(card1); + playerService.getPlayerList().getFirst().addCardToPlayerDeck(card2); + int before = playerService.getPlayerList().getFirst().getPlayerDeck().size(); + + playerService.removeCardFromPlayerDeck(card1); + int after = playerService.getPlayerList().getFirst().getPlayerDeck().size(); + + assertEquals(before - 1, after); + } } From 27d5587a57e63ee29ac2e88db08656bfa23eb6fd Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Sat, 3 Feb 2024 17:54:54 +0100 Subject: [PATCH 12/50] refactoring: adjustingRemoveCardFromPlayerDeck --- .../de/hsfulda/onses/services/PlayerService.java | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/services/PlayerService.java b/src/main/java/de/hsfulda/onses/services/PlayerService.java index 1d74ef9..3c3fb47 100644 --- a/src/main/java/de/hsfulda/onses/services/PlayerService.java +++ b/src/main/java/de/hsfulda/onses/services/PlayerService.java @@ -53,20 +53,9 @@ public class PlayerService { Player player; if (this.currentTurn) { player = playerList.getFirst(); - for (int i = 0; i < player.getPlayerDeck().size(); i++) { - if (player.getPlayerDeck().get(i) == card) { - player.getPlayerDeck().remove(i); - break; - } - } } else { player = playerList.getLast(); - for (int i = 0; i < player.getPlayerDeck().size(); i++) { - if (player.getPlayerDeck().get(i) == card) { - player.getPlayerDeck().remove(i); - break; - } - } } + player.getPlayerDeck().remove(card); } } From 8e894dcc981b7e32ac175e695923476ac810db3c Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Sat, 3 Feb 2024 18:10:16 +0100 Subject: [PATCH 13/50] addCheckForWinner --- src/main/java/de/hsfulda/onses/services/GameService.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index 5600b04..b21c590 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -89,6 +89,11 @@ public class GameService { drawCard(2); break; } + if (this.game.getPlayerService().getPlayerList().getFirst().getPlayerDeck().isEmpty()) { + System.out.println("Player wins"); + } else if (this.game.getPlayerService().getPlayerList().getLast().getPlayerDeck().isEmpty()) { + System.out.println("Bot wins"); + } } public boolean legalMove(Card card) { From da40f493440a9bb5109b5d3f68f4123619c2cdff Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Sat, 3 Feb 2024 18:23:13 +0100 Subject: [PATCH 14/50] refactoring: convertCheckForWinIntoFunction --- .../de/hsfulda/onses/services/GameService.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index b21c590..c098f88 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -59,6 +59,14 @@ public class GameService { game.changeLastPlayedCardColor(color); } + public void checkForWin() { + if (this.game.getPlayerService().getPlayerList().getFirst().getPlayerDeck().isEmpty()) { + System.out.println("Player wins"); + } else if (this.game.getPlayerService().getPlayerList().getLast().getPlayerDeck().isEmpty()) { + System.out.println("Bot wins"); + } + } + public void playCard(Card card) { // add lastPlayedCard back to drawCardDeck this.addLastPlayedCardToDrawCardDeck(); @@ -89,11 +97,7 @@ public class GameService { drawCard(2); break; } - if (this.game.getPlayerService().getPlayerList().getFirst().getPlayerDeck().isEmpty()) { - System.out.println("Player wins"); - } else if (this.game.getPlayerService().getPlayerList().getLast().getPlayerDeck().isEmpty()) { - System.out.println("Bot wins"); - } + checkForWin(); } public boolean legalMove(Card card) { From 600d75c26927fb4c34eabc5004f5cd752683bc68 Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Sat, 3 Feb 2024 18:26:40 +0100 Subject: [PATCH 15/50] refactoring: renameChangeColorToChooseColor --- src/main/java/de/hsfulda/onses/services/GameService.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index c098f88..cc34ee2 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -53,7 +53,7 @@ public class GameService { game.addCardToDrawCardDeck(lastCard); } - public void changeColor() { + public void chooseColor() { // Abfrage Farbe Card.Color color = Card.Color.BLUE; //Vorübergehend Blau game.changeLastPlayedCardColor(color); @@ -84,11 +84,11 @@ public class GameService { nextPlayer(); break; case CHOOSE: - changeColor(); + chooseColor(); nextPlayer(); break; case CHOOSEDRAW: - changeColor(); + chooseColor(); nextPlayer(); drawCard(4); break; From 9cef72266e5df5dd50609fcc38b7c03bd58055fe Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Sat, 3 Feb 2024 18:50:30 +0100 Subject: [PATCH 16/50] addBotMove --- .../java/de/hsfulda/onses/services/PlayerService.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/de/hsfulda/onses/services/PlayerService.java b/src/main/java/de/hsfulda/onses/services/PlayerService.java index 3c3fb47..ce5b5e8 100644 --- a/src/main/java/de/hsfulda/onses/services/PlayerService.java +++ b/src/main/java/de/hsfulda/onses/services/PlayerService.java @@ -3,6 +3,7 @@ package de.hsfulda.onses.services; import de.hsfulda.onses.models.Game; import de.hsfulda.onses.models.Player; import de.hsfulda.onses.models.Card; +import de.hsfulda.onses.services.GameService; import java.util.ArrayList; @@ -58,4 +59,12 @@ public class PlayerService { } player.getPlayerDeck().remove(card); } + + public void botMove() { + for (int i = 0; i < this.playerList.getLast().getPlayerDeck().size(); i++) { + if (getGame().getGameService().legalMove(this.playerList.getLast().getPlayerDeck().get(i))) { + //do something... + } + } + } } From b068cb2cf475278a2b04a03ca30067e79327a2d5 Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Sat, 3 Feb 2024 18:57:17 +0100 Subject: [PATCH 17/50] removeCardFromBotDeck --- src/main/java/de/hsfulda/onses/services/PlayerService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/hsfulda/onses/services/PlayerService.java b/src/main/java/de/hsfulda/onses/services/PlayerService.java index ce5b5e8..089e50c 100644 --- a/src/main/java/de/hsfulda/onses/services/PlayerService.java +++ b/src/main/java/de/hsfulda/onses/services/PlayerService.java @@ -63,7 +63,8 @@ public class PlayerService { public void botMove() { for (int i = 0; i < this.playerList.getLast().getPlayerDeck().size(); i++) { if (getGame().getGameService().legalMove(this.playerList.getLast().getPlayerDeck().get(i))) { - //do something... + this.removeCardFromPlayerDeck(this.playerList.getLast().getPlayerDeck().get(i)); + break; } } } From d0afdd0f57012cb31973afdd759c80c124e23f5c Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Sat, 3 Feb 2024 19:11:31 +0100 Subject: [PATCH 18/50] Test.CheckCardRemovalFromBotDeck --- .../de/hsfulda/onses/PlayerServiceTest.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/PlayerServiceTest.java b/src/test/java/de/hsfulda/onses/PlayerServiceTest.java index 0bb951a..c9dad13 100644 --- a/src/test/java/de/hsfulda/onses/PlayerServiceTest.java +++ b/src/test/java/de/hsfulda/onses/PlayerServiceTest.java @@ -3,6 +3,7 @@ package de.hsfulda.onses; import com.sun.tools.jconsole.JConsoleContext; import de.hsfulda.onses.models.Card; +import de.hsfulda.onses.services.GameService; import de.hsfulda.onses.services.PlayerService; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -110,4 +111,25 @@ public class PlayerServiceTest { assertEquals(before - 1, after); } + + @Test + @DisplayName("CheckCardRemovalFromBotDeck") + void CheckCardRemovalFromBotDeck() { + GameService gameService = new GameService(); + + Card card1 = new Card().setColor(Card.Color.YELLOW).setValue(Card.Value.TWO); + Card card2 = new Card().setColor(Card.Color.RED).setValue(Card.Value.ONE); + + gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.RED).setValue(Card.Value.FIVE)); + gameService.getGame().getPlayerService().setCurrentTurn(false); + + gameService.getGame().getPlayerService().getPlayerList().getLast().addCardToPlayerDeck(card1); + gameService.getGame().getPlayerService().getPlayerList().getLast().addCardToPlayerDeck(card2); + int before = gameService.getGame().getPlayerService().getPlayerList().getLast().getPlayerDeck().size(); + + gameService.getGame().getPlayerService().botMove(); + int after = gameService.getGame().getPlayerService().getPlayerList().getLast().getPlayerDeck().size(); + + assertEquals(before - 1, after); + } } From c4bc3f78aaa2fec0ef71e44d40393f040e2c1e63 Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Sat, 3 Feb 2024 19:15:01 +0100 Subject: [PATCH 19/50] refactoring: ImprovingCheckForCardRemoval --- .../java/de/hsfulda/onses/PlayerServiceTest.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/test/java/de/hsfulda/onses/PlayerServiceTest.java b/src/test/java/de/hsfulda/onses/PlayerServiceTest.java index c9dad13..1f1d140 100644 --- a/src/test/java/de/hsfulda/onses/PlayerServiceTest.java +++ b/src/test/java/de/hsfulda/onses/PlayerServiceTest.java @@ -97,17 +97,19 @@ public class PlayerServiceTest { @Test @DisplayName("CheckForCardRemoval") void CheckForCardRemoval() { - PlayerService playerService = new PlayerService(); + GameService gameService = new GameService(); Card card1 = new Card().setColor(Card.Color.YELLOW).setValue(Card.Value.TWO); Card card2 = new Card().setColor(Card.Color.RED).setValue(Card.Value.ONE); - playerService.getPlayerList().getFirst().addCardToPlayerDeck(card1); - playerService.getPlayerList().getFirst().addCardToPlayerDeck(card2); - int before = playerService.getPlayerList().getFirst().getPlayerDeck().size(); + gameService.getGame().getPlayerService().setCurrentTurn(true); + + gameService.getGame().getPlayerService().getPlayerList().getFirst().addCardToPlayerDeck(card1); + gameService.getGame().getPlayerService().getPlayerList().getFirst().addCardToPlayerDeck(card2); + int before = gameService.getGame().getPlayerService().getPlayerList().getFirst().getPlayerDeck().size(); - playerService.removeCardFromPlayerDeck(card1); - int after = playerService.getPlayerList().getFirst().getPlayerDeck().size(); + gameService.getGame().getPlayerService().removeCardFromPlayerDeck(card1); + int after = gameService.getGame().getPlayerService().getPlayerList().getFirst().getPlayerDeck().size(); assertEquals(before - 1, after); } From 7791bac6fbef01c47db7d0fdc08ec211bcd85594 Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Sun, 4 Feb 2024 18:15:29 +0100 Subject: [PATCH 20/50] botCanPlayCards --- src/main/java/de/hsfulda/onses/services/PlayerService.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/hsfulda/onses/services/PlayerService.java b/src/main/java/de/hsfulda/onses/services/PlayerService.java index 089e50c..09b9f91 100644 --- a/src/main/java/de/hsfulda/onses/services/PlayerService.java +++ b/src/main/java/de/hsfulda/onses/services/PlayerService.java @@ -63,7 +63,9 @@ public class PlayerService { public void botMove() { for (int i = 0; i < this.playerList.getLast().getPlayerDeck().size(); i++) { if (getGame().getGameService().legalMove(this.playerList.getLast().getPlayerDeck().get(i))) { - this.removeCardFromPlayerDeck(this.playerList.getLast().getPlayerDeck().get(i)); + Card playCard = this.playerList.getLast().getPlayerDeck().get(i); + this.removeCardFromPlayerDeck(playCard); + getGame().getGameService().playCard(playCard); break; } } From d7c7b7688ee1d41034c108fbbbde5968baf19fc0 Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Sun, 4 Feb 2024 18:28:13 +0100 Subject: [PATCH 21/50] CheckThatLastPlayedCardWasPlayedByBot --- .../de/hsfulda/onses/PlayerServiceTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/PlayerServiceTest.java b/src/test/java/de/hsfulda/onses/PlayerServiceTest.java index 1f1d140..74333b8 100644 --- a/src/test/java/de/hsfulda/onses/PlayerServiceTest.java +++ b/src/test/java/de/hsfulda/onses/PlayerServiceTest.java @@ -134,4 +134,23 @@ public class PlayerServiceTest { assertEquals(before - 1, after); } + + @Test + @DisplayName("CheckThatLastPlayedCardWasPlayedByBot") + void CheckThatLastPlayedCardWasPlayedByBot() { + GameService gameService = new GameService(); + + Card card1 = new Card().setColor(Card.Color.RED).setValue(Card.Value.ONE); + + gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.RED).setValue(Card.Value.FIVE)); + gameService.getGame().getPlayerService().setCurrentTurn(false); + + gameService.getGame().getPlayerService().getPlayerList().getLast().getPlayerDeck().clear(); + gameService.getGame().getPlayerService().getPlayerList().getLast().addCardToPlayerDeck(card1); + + gameService.getGame().getPlayerService().botMove(); + Card lastPlayedCard = gameService.getGame().getLastPlayedCard(); + + assertEquals(card1, lastPlayedCard); + } } From 3b2043196b38b2a50480ac21c0a7edd4a8a71c5c Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Sun, 4 Feb 2024 19:58:49 +0100 Subject: [PATCH 22/50] refactoring: removeOutdatedTest --- .../java/de/hsfulda/onses/GameServiceTest.java | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index 2ea1066..d4b5753 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -257,24 +257,6 @@ public class GameServiceTest { assertEquals(expected, answer); } - @Test - @DisplayName("DrawCardDeckRemoveTest") - public void DrawCardDeckRemoveTest() { - GameService gameService = new GameService(); - Card card = gameService.getGame().getDrawCardDeck().getFirst(); - gameService.drawCard(1); - int counter = 0; - int expected = 0; - for (int i = 0; i < gameService.getGame().getDrawCardDeck().size(); i++) { - if (gameService.getGame().getDrawCardDeck().get(i).getColor() == card.getColor() && gameService.getGame().getDrawCardDeck().get(i).getValue() == card.getValue()) - counter++; - } - if (card.getColor() == Card.Color.BLACK) expected = 3; - else expected = 1; - - assertEquals(expected, counter); - } - @Test @DisplayName("CheckFirstCardIsSet") public void CheckFirstCardIsSet() { From cb3b290dd2c7782ddc74c869b4625508b05eb72a Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Sun, 4 Feb 2024 20:03:29 +0100 Subject: [PATCH 23/50] addStartingCardsToPlayerDecks --- src/main/java/de/hsfulda/onses/services/GameService.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index cc34ee2..c07fe43 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -15,6 +15,14 @@ public class GameService { fillDrawDeck(); shuffleDeck(); setFirstCard(); + + for (int i = 0; i < 7; i++) { + this.drawCard(1); + this.nextPlayer(); + + this.drawCard(1); + this.nextPlayer(); + } } public GameService() { From e43b4b894adb215bcc8dc5036afc5d4c3efb5249 Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Sun, 4 Feb 2024 20:04:46 +0100 Subject: [PATCH 24/50] Test.CheckThatPlayerReceivedSevenCards --- src/test/java/de/hsfulda/onses/GameServiceTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index d4b5753..dceb8f7 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -291,4 +291,14 @@ public class GameServiceTest { assertEquals(Card.Color.BLACK, card.getColor()); } + + @Test + @DisplayName("CheckThatPlayerReceivedSevenCards") + public void CheckThatPlayerReceivedSevenCards() { + GameService gameService = new GameService(); + + int numberOfCards = gameService.getGame().getPlayerService().getPlayerList().getFirst().getPlayerDeck().size(); + + assertEquals(7, numberOfCards); + } } From 3d03ea8a8c17aee30c7c63f9a77da3363ecc5fe0 Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Sun, 4 Feb 2024 20:06:52 +0100 Subject: [PATCH 25/50] refactoring: fillPlayerDecks --- .../hsfulda/onses/services/GameService.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index c07fe43..cc6e016 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -15,14 +15,7 @@ public class GameService { fillDrawDeck(); shuffleDeck(); setFirstCard(); - - for (int i = 0; i < 7; i++) { - this.drawCard(1); - this.nextPlayer(); - - this.drawCard(1); - this.nextPlayer(); - } + fillPlayerDecks(); } public GameService() { @@ -151,4 +144,14 @@ public class GameService { } } + public void fillPlayerDecks() { + for (int i = 0; i < 7; i++) { + this.drawCard(1); + this.nextPlayer(); + + this.drawCard(1); + this.nextPlayer(); + } + } + } From 1637ecf8ba4cd60cb41ad705b55a468706d0f06b Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Sun, 4 Feb 2024 20:08:02 +0100 Subject: [PATCH 26/50] Test.CheckThatBotDeckHasSevenCardsAfterGameStart --- src/test/java/de/hsfulda/onses/GameServiceTest.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index dceb8f7..df7bfdd 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -257,6 +257,17 @@ public class GameServiceTest { assertEquals(expected, answer); } + @Test + @DisplayName("CheckThatBotDeckHasSevenCardsAfterGameStart") + public void CheckThatBotDeckHasSevenCardsAfterGameStart() { + GameService gameService = new GameService(); + + int expected = 7; + int actual = gameService.getGame().getPlayerService().getPlayerList().getLast().getPlayerDeck().size(); + + assertEquals(expected, actual); + } + @Test @DisplayName("CheckFirstCardIsSet") public void CheckFirstCardIsSet() { From c14c4d8309bb21c780a5c415a9bc4753a87a029a Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Sun, 4 Feb 2024 20:09:28 +0100 Subject: [PATCH 27/50] refactoring: removeFirstCardFromCardDrawDeck --- src/main/java/de/hsfulda/onses/services/GameService.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index cc6e016..2514ae7 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -139,6 +139,7 @@ public class GameService { Card card = this.game.getDrawCardDeck().get(i); if (card.getColor() != Card.Color.BLACK) { this.game.setLastPlayedCard(card); + this.game.getDrawCardDeck().remove(card); break; } } From 528470310b61ae917fbf655a8312c09769b680bb Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Sun, 4 Feb 2024 20:10:21 +0100 Subject: [PATCH 28/50] Test.CheckThatFirstCardGetsRemovedFromDrawCardDeck --- .../de/hsfulda/onses/GameServiceTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index df7bfdd..e2d77d4 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -312,4 +312,23 @@ public class GameServiceTest { assertEquals(7, numberOfCards); } + + @Test + @DisplayName("CheckThatFirstCardGetsRemovedFromDrawCardDeck") + public void CheckThatFirstCardGetsRemovedFromDrawCardDeck() { + GameService gameService = new GameService(); + + Card lastPlayedCard = gameService.getGame().getLastPlayedCard(); + + boolean lastPlayedCardDoesNotExistInDrawCardDeck = true; + + for (int i = 0; i < gameService.getGame().getDrawCardDeck().size(); i++) { + if (gameService.getGame().getDrawCardDeck().get(i) == lastPlayedCard) { + lastPlayedCardDoesNotExistInDrawCardDeck = false; + break; + } + } + + assertTrue(lastPlayedCardDoesNotExistInDrawCardDeck); + } } From bf2dd254701cfbaf3f966a1abc29830c50104cf2 Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Sun, 4 Feb 2024 20:12:00 +0100 Subject: [PATCH 29/50] botCanDrawCards --- src/main/java/de/hsfulda/onses/services/PlayerService.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/de/hsfulda/onses/services/PlayerService.java b/src/main/java/de/hsfulda/onses/services/PlayerService.java index 09b9f91..14382d3 100644 --- a/src/main/java/de/hsfulda/onses/services/PlayerService.java +++ b/src/main/java/de/hsfulda/onses/services/PlayerService.java @@ -61,6 +61,7 @@ public class PlayerService { } public void botMove() { + Card lastPlayedCard = game.getLastPlayedCard(); for (int i = 0; i < this.playerList.getLast().getPlayerDeck().size(); i++) { if (getGame().getGameService().legalMove(this.playerList.getLast().getPlayerDeck().get(i))) { Card playCard = this.playerList.getLast().getPlayerDeck().get(i); @@ -69,5 +70,8 @@ public class PlayerService { break; } } + if (lastPlayedCard == game.getLastPlayedCard()) { + game.getGameService().drawCard(1); + } } } From ddfb8e271b264e589e5e036c584f9c5929c60718 Mon Sep 17 00:00:00 2001 From: fdai7920 Date: Sun, 4 Feb 2024 20:22:28 +0100 Subject: [PATCH 30/50] unable to draw from empty DrawCardDeck --- .../de/hsfulda/onses/services/GameService.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index 2514ae7..f7618f7 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -32,14 +32,16 @@ public class GameService { public void drawCard(int amount) { Player player = null; - if (game.getPlayerService().getCurrentTurn()) { - player = game.getPlayerService().getPlayerList().getFirst(); - } else { - player = game.getPlayerService().getPlayerList().getLast(); - } - for (int i = 0; i < amount; i++) { - player.getPlayerDeck().add(game.getDrawCardDeck().getFirst()); - game.getDrawCardDeck().removeFirst(); + if (!game.getDrawCardDeck().isEmpty()) { + if (game.getPlayerService().getCurrentTurn()) { + player = game.getPlayerService().getPlayerList().getFirst(); + } else { + player = game.getPlayerService().getPlayerList().getLast(); + } + for (int i = 0; i < amount; i++) { + player.getPlayerDeck().add(game.getDrawCardDeck().getFirst()); + game.getDrawCardDeck().removeFirst(); + } } if (amount != 1) { nextPlayer(); From 67e6c5c9ad5f96c7af8eac25bf55a359e3fa3165 Mon Sep 17 00:00:00 2001 From: fdai7920 Date: Sun, 4 Feb 2024 20:27:32 +0100 Subject: [PATCH 31/50] Test.DrawCardIntoPlayerDeck --- src/test/java/de/hsfulda/onses/GameServiceTest.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index e2d77d4..87071b9 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -256,6 +256,19 @@ public class GameServiceTest { int answer = before - after; assertEquals(expected, answer); } + @Test + @DisplayName("DrawCardPlayerDeck") + public void DrawCardPlayerDeck() { + GameService gameService = new GameService(); + gameService.getGame().getPlayerService().setCurrentTurn(true); + int before = gameService.getGame().getPlayerService().getPlayerList().getFirst().getPlayerDeck().size(); + gameService.drawCard(4); + int after = gameService.getGame().getPlayerService().getPlayerList().getFirst().getPlayerDeck().size(); + + int expected = 4; + int answer = after - before; + assertEquals(expected, answer); + } @Test @DisplayName("CheckThatBotDeckHasSevenCardsAfterGameStart") From 8daba2ef47419d49f94232704db94f80cde710da Mon Sep 17 00:00:00 2001 From: fdai7920 Date: Sun, 4 Feb 2024 20:29:07 +0100 Subject: [PATCH 32/50] Test.DrawCardBotDeck --- src/test/java/de/hsfulda/onses/GameServiceTest.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index 87071b9..208dac7 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -243,6 +243,19 @@ public class GameServiceTest { assertEquals(expected, answer); } + @Test + @DisplayName("DrawCardPlayerDeckBot") + public void DrawCardPlayerDeckBot() { + GameService gameService = new GameService(); + gameService.getGame().getPlayerService().setCurrentTurn(false); + int before = gameService.getGame().getPlayerService().getPlayerList().getLast().getPlayerDeck().size(); + gameService.drawCard(2); + int after = gameService.getGame().getPlayerService().getPlayerList().getLast().getPlayerDeck().size(); + + int expected = 2; + int answer = after - before; + assertEquals(expected, answer); + } @Test @DisplayName("DrawCardDeckTest") From 5ddbe1bf1b2b40dd59472b5e8addf1d5a2422d30 Mon Sep 17 00:00:00 2001 From: fdai7920 Date: Sun, 4 Feb 2024 20:37:42 +0100 Subject: [PATCH 33/50] refactoring: simplify fillPlayerDecks --- src/main/java/de/hsfulda/onses/services/GameService.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index f7618f7..bd223d5 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -148,13 +148,9 @@ public class GameService { } public void fillPlayerDecks() { - for (int i = 0; i < 7; i++) { - this.drawCard(1); - this.nextPlayer(); - this.drawCard(1); - this.nextPlayer(); - } + this.drawCard(7); + this.drawCard(7); } } From b95b951a96d678e0020b1cf2e0b4615076dcad6f Mon Sep 17 00:00:00 2001 From: fdai7920 Date: Sun, 4 Feb 2024 20:41:02 +0100 Subject: [PATCH 34/50] add DrawCardByChoice --- src/main/java/de/hsfulda/onses/services/GameService.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index bd223d5..d57b108 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -31,8 +31,8 @@ public class GameService { } public void drawCard(int amount) { - Player player = null; if (!game.getDrawCardDeck().isEmpty()) { + Player player = null; if (game.getPlayerService().getCurrentTurn()) { player = game.getPlayerService().getPlayerList().getFirst(); } else { @@ -42,6 +42,13 @@ public class GameService { player.getPlayerDeck().add(game.getDrawCardDeck().getFirst()); game.getDrawCardDeck().removeFirst(); } + if (amount == 1 && !player.getPlayerDeck().isEmpty()) { //refactoring DrawnCard + Card card = player.getPlayerDeck().getLast(); + if (legalMove(card)) { + player.getPlayerService().removeCardFromPlayerDeck(card); + playCard(card);} + else nextPlayer(); + } } if (amount != 1) { nextPlayer(); From fe79dba5156f8a31ada73bc0185e2eaa5acafe83 Mon Sep 17 00:00:00 2001 From: fdai7920 Date: Sun, 4 Feb 2024 20:43:49 +0100 Subject: [PATCH 35/50] Test.DrawByChoiceAndPlay --- .../de/hsfulda/onses/GameServiceTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index 208dac7..889f4b1 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -283,6 +283,25 @@ public class GameServiceTest { assertEquals(expected, answer); } + @Test + @DisplayName("DrawByChoiceForcePlay") + public void DrawByChoiceForcePlay() { + + GameService gameService = new GameService(); + Card input = new Card().setColor(Card.Color.RED).setValue(Card.Value.ONE); + + gameService.drawCard(gameService.getGame().getDrawCardDeck().size()); + gameService.getGame().getPlayerService().setCurrentTurn(true); + gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.RED).setValue(Card.Value.SEVEN)); + gameService.getGame().addCardToDrawCardDeck(input); + gameService.getGame().getPlayerService().getPlayerList().getFirst().addCardToPlayerDeck(new Card().setColor(Card.Color.BLUE).setValue(Card.Value.TWO)); + gameService.drawCard(1); + + Card answer = gameService.getGame().getPlayerService().getPlayerList().getFirst().getPlayerDeck().getLast(); + + assertNotEquals(input, answer); + } + @Test @DisplayName("CheckThatBotDeckHasSevenCardsAfterGameStart") public void CheckThatBotDeckHasSevenCardsAfterGameStart() { From 453e794f21eaf8657909982afcc6c95275cecd8c Mon Sep 17 00:00:00 2001 From: fdai7920 Date: Sun, 4 Feb 2024 20:48:54 +0100 Subject: [PATCH 36/50] refactoring: renamed card to drawnCard in drawCard --- .../java/de/hsfulda/onses/services/GameService.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index d57b108..09c5d0a 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -42,11 +42,13 @@ public class GameService { player.getPlayerDeck().add(game.getDrawCardDeck().getFirst()); game.getDrawCardDeck().removeFirst(); } - if (amount == 1 && !player.getPlayerDeck().isEmpty()) { //refactoring DrawnCard - Card card = player.getPlayerDeck().getLast(); - if (legalMove(card)) { - player.getPlayerService().removeCardFromPlayerDeck(card); - playCard(card);} + if (amount == 1 && !player.getPlayerDeck().isEmpty()) { + Card drawnCard = player.getPlayerDeck().getLast(); + + if (legalMove(drawnCard)) { + player.getPlayerService().removeCardFromPlayerDeck(drawnCard); + playCard(drawnCard); + } else nextPlayer(); } } From 70c31be4288269b0bc8169446a71fb6763865e05 Mon Sep 17 00:00:00 2001 From: fdai7920 Date: Sun, 4 Feb 2024 20:52:11 +0100 Subject: [PATCH 37/50] Test.DrawByChoiceAndKeep --- .../de/hsfulda/onses/GameServiceTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index 889f4b1..728f4b6 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -243,6 +243,25 @@ public class GameServiceTest { assertEquals(expected, answer); } + @Test + @DisplayName("DrawByChoiceForceKeep") + public void DrawByChoiceForceKeep() { + + GameService gameService = new GameService(); + Card input = new Card().setColor(Card.Color.RED).setValue(Card.Value.ONE); + + gameService.drawCard(gameService.getGame().getDrawCardDeck().size()); + gameService.getGame().getPlayerService().setCurrentTurn(true); + gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.GREEN).setValue(Card.Value.SEVEN)); + gameService.getGame().addCardToDrawCardDeck(input); + gameService.getGame().getPlayerService().getPlayerList().getFirst().addCardToPlayerDeck(new Card().setColor(Card.Color.BLUE).setValue(Card.Value.TWO)); + gameService.drawCard(1); + + Card answer = gameService.getGame().getPlayerService().getPlayerList().getFirst().getPlayerDeck().getLast(); + + assertEquals(input, answer); + } + @Test @DisplayName("DrawCardPlayerDeckBot") public void DrawCardPlayerDeckBot() { From 1a3893fd8109a709efc7bb0ee79dbb2cad376da2 Mon Sep 17 00:00:00 2001 From: fdai7920 Date: Sun, 4 Feb 2024 20:54:09 +0100 Subject: [PATCH 38/50] refactoring: simplify DrawByChoiceTests --- src/test/java/de/hsfulda/onses/GameServiceTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index 728f4b6..fde7519 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -250,7 +250,7 @@ public class GameServiceTest { GameService gameService = new GameService(); Card input = new Card().setColor(Card.Color.RED).setValue(Card.Value.ONE); - gameService.drawCard(gameService.getGame().getDrawCardDeck().size()); + gameService.getGame().getDrawCardDeck().clear(); gameService.getGame().getPlayerService().setCurrentTurn(true); gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.GREEN).setValue(Card.Value.SEVEN)); gameService.getGame().addCardToDrawCardDeck(input); @@ -309,7 +309,7 @@ public class GameServiceTest { GameService gameService = new GameService(); Card input = new Card().setColor(Card.Color.RED).setValue(Card.Value.ONE); - gameService.drawCard(gameService.getGame().getDrawCardDeck().size()); + gameService.getGame().getDrawCardDeck().clear(); gameService.getGame().getPlayerService().setCurrentTurn(true); gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.RED).setValue(Card.Value.SEVEN)); gameService.getGame().addCardToDrawCardDeck(input); From 4020c1e7d683ab5a0c9d76323cdf2f6f63ed7e12 Mon Sep 17 00:00:00 2001 From: fdai7920 Date: Sun, 4 Feb 2024 20:57:54 +0100 Subject: [PATCH 39/50] add nextTurn if not ActionCard --- src/main/java/de/hsfulda/onses/services/GameService.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index 09c5d0a..08b75d8 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -108,6 +108,9 @@ public class GameService { nextPlayer(); drawCard(2); break; + default: + nextPlayer(); + break; } checkForWin(); } From a364773a69babc8a861ee9bc33c2d4435c6a3d70 Mon Sep 17 00:00:00 2001 From: fdai7920 Date: Sun, 4 Feb 2024 21:04:59 +0100 Subject: [PATCH 40/50] refactoring: merge same cases in playCard --- src/main/java/de/hsfulda/onses/services/GameService.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index 08b75d8..1101305 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -87,11 +87,7 @@ public class GameService { // Skip switch (card.getValue()) { - case SKIP: - nextPlayer(); - nextPlayer(); - break; - case REVERSE: + case SKIP, REVERSE: nextPlayer(); nextPlayer(); break; @@ -160,7 +156,6 @@ public class GameService { } public void fillPlayerDecks() { - this.drawCard(7); this.drawCard(7); } From 99d3ba2df9ec2c470f2efa23a9ac65f35640fe6b Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Mon, 5 Feb 2024 18:50:36 +0100 Subject: [PATCH 41/50] add ChooseColor for Bot --- .../hsfulda/onses/services/GameService.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index 1101305..598d19b 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -5,6 +5,7 @@ import de.hsfulda.onses.models.Game; import de.hsfulda.onses.models.Player; import java.util.Collections; +import java.util.Random; public class GameService { private final Game game; @@ -69,6 +70,31 @@ public class GameService { // Abfrage Farbe Card.Color color = Card.Color.BLUE; //Vorübergehend Blau game.changeLastPlayedCardColor(color); + + if (!game.getPlayerService().getCurrentTurn()){ + int min = 0; + int max = 3; + Random rand = new Random(); + int randomNum = rand.nextInt((max - min) + 1) + min; + switch (randomNum){ + case 0: + color = Card.Color.BLUE; + game.changeLastPlayedCardColor(color); + break; + case 1: + color = Card.Color.RED; + game.changeLastPlayedCardColor(color); + break; + case 2: + color = Card.Color.YELLOW; + game.changeLastPlayedCardColor(color); + break; + case 3: + color = Card.Color.GREEN; + game.changeLastPlayedCardColor(color); + break; + } + } } public void checkForWin() { From 2d7abb293604cd6513b46fba25cdd96881fc090b Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Mon, 5 Feb 2024 19:11:00 +0100 Subject: [PATCH 42/50] Test.ChooseColorBotTest --- .../de/hsfulda/onses/GameServiceTest.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index fde7519..d84fdc7 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -1,6 +1,7 @@ package de.hsfulda.onses; +import de.hsfulda.onses.models.Game; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -395,4 +396,24 @@ public class GameServiceTest { assertTrue(lastPlayedCardDoesNotExistInDrawCardDeck); } + + @Test + @DisplayName("ChooseColorBotTest") + public void ChooseColorBotTest() { + GameService gameService = new GameService(); + Card card = new Card().setColor(Card.Color.BLACK).setValue(Card.Value.CHOOSE); + boolean answer = false; + + gameService.getGame().getPlayerService().getPlayerList().getLast().getPlayerDeck().clear(); + gameService.getGame().getPlayerService().getPlayerList().getLast().getPlayerDeck().add(card); + + gameService.getGame().getPlayerService().setCurrentTurn(false); + gameService.playCard(card); + + if (gameService.getGame().getLastPlayedCard().getColor() != Card.Color.BLACK){ + answer = true; + } + + assertTrue(answer); + } } From 4c81eec3e9e67a6bb80f0d340ee77282d8f6c7fc Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Mon, 5 Feb 2024 19:16:34 +0100 Subject: [PATCH 43/50] addTestModeToGameService --- src/main/java/de/hsfulda/onses/services/GameService.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index 598d19b..547d214 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -10,6 +10,13 @@ import java.util.Random; public class GameService { private final Game game; + private boolean test = false; + + public GameService setTest(boolean test) { + this.test = test; + return this; + } + public GameService(Game game) { this.game = game; this.game.setGameService(this); From 38be81d52bb66c94333e4cd767f7e712800d15b2 Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Mon, 5 Feb 2024 19:21:47 +0100 Subject: [PATCH 44/50] refactoring: addGetTest --- src/main/java/de/hsfulda/onses/services/GameService.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index 547d214..30a48fb 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -17,6 +17,9 @@ public class GameService { return this; } + public boolean getTest() { + return this.test; + } public GameService(Game game) { this.game = game; this.game.setGameService(this); From 4419a013380b8ca442b065b378a5591d496c7163 Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Mon, 5 Feb 2024 19:24:20 +0100 Subject: [PATCH 45/50] Test.CheckIfTestWasInitializedWithFalse --- src/test/java/de/hsfulda/onses/GameServiceTest.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index d84fdc7..0dd4bd6 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -416,4 +416,12 @@ public class GameServiceTest { assertTrue(answer); } + + @Test + @DisplayName("CheckIfTestWasInitializedWithFalse") + public void CheckIfTestWasInitializedWithFalse() { + GameService gameService = new GameService(); + + assertFalse(gameService.getTest()); + } } From 98d7d3af314a135129266d59f8068793ff617073 Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Mon, 5 Feb 2024 19:25:54 +0100 Subject: [PATCH 46/50] Test.CheckIfTestCanBeSetToTrue --- src/test/java/de/hsfulda/onses/GameServiceTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index 0dd4bd6..3428842 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -424,4 +424,14 @@ public class GameServiceTest { assertFalse(gameService.getTest()); } + + @Test + @DisplayName("CheckIfTestCanBeSetToTrue") + public void CheckIfTestCanBeSetToTrue() { + GameService gameService = new GameService(); + + gameService.setTest(!gameService.getTest()); + + assertTrue(gameService.getTest()); + } } From abd8881d42d037f5853c3d2d372c3bced0987275 Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Mon, 5 Feb 2024 19:37:17 +0100 Subject: [PATCH 47/50] refactoring: moveTestsIntoTestMode --- .../de/hsfulda/onses/GameServiceTest.java | 55 ++++++++++++++----- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index 3428842..d54b1cc 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -19,6 +19,7 @@ public class GameServiceTest { Card input = new Card().setColor(Card.Color.RED).setValue(Card.Value.EIGHT); // act GameService gameService = new GameService(); + gameService.setTest(true); gameService.playCard(input); Card answer = gameService.getGame().getLastPlayedCard(); // assert @@ -32,6 +33,7 @@ public class GameServiceTest { Card input = new Card().setColor(Card.Color.BLACK).setValue(Card.Value.CHOOSE); // act GameService gameService = new GameService(); + gameService.setTest(true); gameService.playCard(input); Card answer = gameService.getGame().getLastPlayedCard(); // assert @@ -46,6 +48,7 @@ public class GameServiceTest { boolean expected = true; // act GameService gameService = new GameService(); + gameService.setTest(true); gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.RED).setValue(Card.Value.FIVE)); boolean answer = gameService.legalMove(input); @@ -61,6 +64,7 @@ public class GameServiceTest { boolean expected = true; // act GameService gameService = new GameService(); + gameService.setTest(true); gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.BLUE).setValue(Card.Value.ONE)); boolean answer = gameService.legalMove(input); @@ -72,6 +76,7 @@ public class GameServiceTest { @DisplayName("FillDrawCardDeck") public void FillDrawCardDeck() { GameService gameService = new GameService(); + gameService.setTest(true); int expected = gameService.getGame().getDrawCardDeck().size() + 112; gameService.fillDrawDeck(); @@ -88,6 +93,7 @@ public class GameServiceTest { boolean expected = true; // act GameService gameService = new GameService(); + gameService.setTest(true); gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.YELLOW).setValue(Card.Value.ONE)); boolean answer = gameService.legalMove(input); @@ -103,6 +109,7 @@ public class GameServiceTest { boolean expected = true; // act GameService gameService = new GameService(); + gameService.setTest(true); gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.YELLOW).setValue(Card.Value.THREE)); boolean answer = gameService.legalMove(input); @@ -118,6 +125,7 @@ public class GameServiceTest { boolean expected = true; // act GameService gameService = new GameService(); + gameService.setTest(true); gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.YELLOW).setValue(Card.Value.THREE)); boolean answer = gameService.legalMove(input); @@ -133,6 +141,7 @@ public class GameServiceTest { boolean expected = true; // act GameService gameService = new GameService(); + gameService.setTest(true); gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.GREEN).setValue(Card.Value.FIVE)); boolean answer = gameService.legalMove(input); @@ -192,35 +201,38 @@ public class GameServiceTest { @Test @DisplayName("SkipTest") public void SkipTest() { - GameService gameservice = new GameService(); - boolean expected = gameservice.getGame().getPlayerService().getCurrentTurn(); + GameService gameService = new GameService(); + gameService.setTest(true); + boolean expected = gameService.getGame().getPlayerService().getCurrentTurn(); - gameservice.playCard(new Card().setValue(Card.Value.SKIP).setColor(Card.Color.BLACK)); + gameService.playCard(new Card().setValue(Card.Value.SKIP).setColor(Card.Color.BLACK)); - assertEquals(expected, gameservice.getGame().getPlayerService().getCurrentTurn()); + assertEquals(expected, gameService.getGame().getPlayerService().getCurrentTurn()); } @Test @DisplayName("ReverseTest") public void ReverseTest() { - GameService gameservice = new GameService(); - boolean expected = gameservice.getGame().getPlayerService().getCurrentTurn(); + GameService gameService = new GameService(); + gameService.setTest(true); + boolean expected = gameService.getGame().getPlayerService().getCurrentTurn(); - gameservice.playCard(new Card().setValue(Card.Value.REVERSE).setColor(Card.Color.BLACK)); + gameService.playCard(new Card().setValue(Card.Value.REVERSE).setColor(Card.Color.BLACK)); - assertEquals(expected, gameservice.getGame().getPlayerService().getCurrentTurn()); + assertEquals(expected, gameService.getGame().getPlayerService().getCurrentTurn()); } @Test @DisplayName("ChooseTest") public void ChooseTest() { - GameService gameservice = new GameService(); + GameService gameService = new GameService(); + gameService.setTest(true); boolean expected = true; boolean answer = false; - gameservice.playCard(new Card().setValue(Card.Value.CHOOSE).setColor(Card.Color.BLACK)); + gameService.playCard(new Card().setValue(Card.Value.CHOOSE).setColor(Card.Color.BLACK)); - if (gameservice.getGame().getLastPlayedCard().getColor() != Card.Color.BLACK) { + if (gameService.getGame().getLastPlayedCard().getColor() != Card.Color.BLACK) { answer = true; } @@ -231,13 +243,14 @@ public class GameServiceTest { @Test @DisplayName("ChooseDrawTest") public void ChooseDrawTest() { - GameService gameservice = new GameService(); + GameService gameService = new GameService(); + gameService.setTest(true); boolean expected = true; boolean answer = false; - gameservice.playCard(new Card().setValue(Card.Value.CHOOSEDRAW).setColor(Card.Color.BLACK)); + gameService.playCard(new Card().setValue(Card.Value.CHOOSEDRAW).setColor(Card.Color.BLACK)); - if (gameservice.getGame().getLastPlayedCard().getColor() != Card.Color.BLACK) { + if (gameService.getGame().getLastPlayedCard().getColor() != Card.Color.BLACK) { answer = true; } @@ -249,6 +262,7 @@ public class GameServiceTest { public void DrawByChoiceForceKeep() { GameService gameService = new GameService(); + gameService.setTest(true); Card input = new Card().setColor(Card.Color.RED).setValue(Card.Value.ONE); gameService.getGame().getDrawCardDeck().clear(); @@ -267,6 +281,7 @@ public class GameServiceTest { @DisplayName("DrawCardPlayerDeckBot") public void DrawCardPlayerDeckBot() { GameService gameService = new GameService(); + gameService.setTest(true); gameService.getGame().getPlayerService().setCurrentTurn(false); int before = gameService.getGame().getPlayerService().getPlayerList().getLast().getPlayerDeck().size(); gameService.drawCard(2); @@ -281,6 +296,7 @@ public class GameServiceTest { @DisplayName("DrawCardDeckTest") public void DrawCardDeckTest() { GameService gameService = new GameService(); + gameService.setTest(true); int before = gameService.getGame().getDrawCardDeck().size(); gameService.drawCard(4); int after = gameService.getGame().getDrawCardDeck().size(); @@ -293,6 +309,7 @@ public class GameServiceTest { @DisplayName("DrawCardPlayerDeck") public void DrawCardPlayerDeck() { GameService gameService = new GameService(); + gameService.setTest(true); gameService.getGame().getPlayerService().setCurrentTurn(true); int before = gameService.getGame().getPlayerService().getPlayerList().getFirst().getPlayerDeck().size(); gameService.drawCard(4); @@ -308,6 +325,7 @@ public class GameServiceTest { public void DrawByChoiceForcePlay() { GameService gameService = new GameService(); + gameService.setTest(true); Card input = new Card().setColor(Card.Color.RED).setValue(Card.Value.ONE); gameService.getGame().getDrawCardDeck().clear(); @@ -327,6 +345,7 @@ public class GameServiceTest { public void CheckThatBotDeckHasSevenCardsAfterGameStart() { GameService gameService = new GameService(); + gameService.setTest(true); int expected = 7; int actual = gameService.getGame().getPlayerService().getPlayerList().getLast().getPlayerDeck().size(); @@ -337,6 +356,7 @@ public class GameServiceTest { @DisplayName("CheckFirstCardIsSet") public void CheckFirstCardIsSet() { GameService gameService = new GameService(); + gameService.setTest(true); Card card = gameService.getGame().getLastPlayedCard(); boolean answer = card != null; @@ -348,6 +368,7 @@ public class GameServiceTest { @DisplayName("CheckFirstCardIsNotBlack") public void CheckFirstCardIsNotBlack() { GameService gameService = new GameService(); + gameService.setTest(true); Card card = gameService.getGame().getLastPlayedCard(); boolean answer = card.getColor() != Card.Color.BLACK; @@ -359,6 +380,7 @@ public class GameServiceTest { @DisplayName("CheckResetOnBlackCards") public void CheckResetOnBlackCards() { GameService gameService = new GameService(); + gameService.setTest(true); gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.RED).setValue(Card.Value.FIVE)); gameService.playCard(new Card().setColor(Card.Color.BLACK).setValue(Card.Value.CHOOSE)); gameService.playCard(new Card().setColor(Card.Color.YELLOW).setValue(Card.Value.FIVE)); @@ -373,6 +395,7 @@ public class GameServiceTest { public void CheckThatPlayerReceivedSevenCards() { GameService gameService = new GameService(); + gameService.setTest(true); int numberOfCards = gameService.getGame().getPlayerService().getPlayerList().getFirst().getPlayerDeck().size(); assertEquals(7, numberOfCards); @@ -383,6 +406,7 @@ public class GameServiceTest { public void CheckThatFirstCardGetsRemovedFromDrawCardDeck() { GameService gameService = new GameService(); + gameService.setTest(true); Card lastPlayedCard = gameService.getGame().getLastPlayedCard(); boolean lastPlayedCardDoesNotExistInDrawCardDeck = true; @@ -401,6 +425,7 @@ public class GameServiceTest { @DisplayName("ChooseColorBotTest") public void ChooseColorBotTest() { GameService gameService = new GameService(); + gameService.setTest(true); Card card = new Card().setColor(Card.Color.BLACK).setValue(Card.Value.CHOOSE); boolean answer = false; @@ -430,7 +455,7 @@ public class GameServiceTest { public void CheckIfTestCanBeSetToTrue() { GameService gameService = new GameService(); - gameService.setTest(!gameService.getTest()); + gameService.setTest(true); assertTrue(gameService.getTest()); } From 2c9c3acb680c580bf7e867acc9d1025f8bc72eb7 Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Mon, 5 Feb 2024 19:39:42 +0100 Subject: [PATCH 48/50] addBotMovesAfterPlayer --- src/main/java/de/hsfulda/onses/services/GameService.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index 30a48fb..ea8824f 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -145,6 +145,11 @@ public class GameService { break; } checkForWin(); + if (!this.test) { + if (!game.getPlayerService().getCurrentTurn()) { + game.getPlayerService().botMove(); + } + } } public boolean legalMove(Card card) { From 258c69122f343946fb01efa01b22c1dc7b53637f Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Mon, 5 Feb 2024 19:48:11 +0100 Subject: [PATCH 49/50] Test.CheckIfBotMovesAutomaticallyAfterPlayer --- .../java/de/hsfulda/onses/GameServiceTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index d54b1cc..de47a5e 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -459,4 +459,19 @@ public class GameServiceTest { assertTrue(gameService.getTest()); } + + @Test + @DisplayName("CheckIfBotMovesAutomaticallyAfterPlayer") + public void CheckIfBotMovesAutomaticallyAfterPlayer() { + GameService gameService = new GameService(); + + Card card = new Card().setColor(Card.Color.BLUE).setValue(Card.Value.ONE); + gameService.getGame().getPlayerService().getPlayerList().getLast().getPlayerDeck().add(new Card().setColor(Card.Color.BLUE).setValue(Card.Value.FIVE)); + + gameService.playCard(card); + + boolean answer = gameService.getGame().getLastPlayedCard() != card; + + assertTrue(answer); + } } From 291652d4030faaee7e3a57460036f3b85adaa040 Mon Sep 17 00:00:00 2001 From: fdai7793 Date: Mon, 5 Feb 2024 19:56:13 +0100 Subject: [PATCH 50/50] refactoring: fix test in PlayerServiceTest --- src/test/java/de/hsfulda/onses/PlayerServiceTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/de/hsfulda/onses/PlayerServiceTest.java b/src/test/java/de/hsfulda/onses/PlayerServiceTest.java index 74333b8..c629c71 100644 --- a/src/test/java/de/hsfulda/onses/PlayerServiceTest.java +++ b/src/test/java/de/hsfulda/onses/PlayerServiceTest.java @@ -123,6 +123,7 @@ public class PlayerServiceTest { Card card2 = new Card().setColor(Card.Color.RED).setValue(Card.Value.ONE); gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.RED).setValue(Card.Value.FIVE)); + gameService.setTest(true); gameService.getGame().getPlayerService().setCurrentTurn(false); gameService.getGame().getPlayerService().getPlayerList().getLast().addCardToPlayerDeck(card1);