From 6425dc9d9b503ca92d3fa8412203bcbe4406f749 Mon Sep 17 00:00:00 2001 From: Steffen Helmke Date: Mon, 10 Jan 2022 19:55:41 +0100 Subject: [PATCH] 4gewinnt: change to player 1 after player 2 played added --- src/main/java/de/tims/viergewinnt/ai/Logic.java | 2 +- src/test/java/de/tims/viergewinnt/ai/LogicTest.java | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/tims/viergewinnt/ai/Logic.java b/src/main/java/de/tims/viergewinnt/ai/Logic.java index 1aef7f6..56707b5 100644 --- a/src/main/java/de/tims/viergewinnt/ai/Logic.java +++ b/src/main/java/de/tims/viergewinnt/ai/Logic.java @@ -19,7 +19,7 @@ public class Logic { public int playChip(int[][] playfield, int column, int player) { //add board update testForWin(playfield, player); - currentPlayer = 2; + currentPlayer = (player % 2) + 1; return 0; } diff --git a/src/test/java/de/tims/viergewinnt/ai/LogicTest.java b/src/test/java/de/tims/viergewinnt/ai/LogicTest.java index 71cd919..e35cd8d 100644 --- a/src/test/java/de/tims/viergewinnt/ai/LogicTest.java +++ b/src/test/java/de/tims/viergewinnt/ai/LogicTest.java @@ -52,6 +52,19 @@ class LogicTest { assertEquals(expectedResult, realResult); } + @Test + void changePlayerTo1Test() { + int[][] playfield = new int[6][6]; + int column = 0; + int player = 2; + int expectedResult = 1; + + testObj.playChip(playfield, column, player); + int realResult = testObj.currentPlayer; + + assertEquals(expectedResult, realResult); + } + private static Stream playfieldResults() { int[][] playfield1 = {{0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0},