From 3da406151e1255373697b8c7179cb13cc714a1b4 Mon Sep 17 00:00:00 2001 From: Malte Tammena Date: Mon, 16 Oct 2017 10:43:50 +0200 Subject: [PATCH 1/3] Changed AI names --- src/player/{Player2.java => MalteAI.java} | 0 src/player/{Player1.java => MaurizioAI.java} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/player/{Player2.java => MalteAI.java} (100%) rename src/player/{Player1.java => MaurizioAI.java} (100%) diff --git a/src/player/Player2.java b/src/player/MalteAI.java similarity index 100% rename from src/player/Player2.java rename to src/player/MalteAI.java diff --git a/src/player/Player1.java b/src/player/MaurizioAI.java similarity index 100% rename from src/player/Player1.java rename to src/player/MaurizioAI.java From 51d18de92f87d631b00ec79f9b10215f34d05cba Mon Sep 17 00:00:00 2001 From: Malte Tammena Date: Mon, 16 Oct 2017 10:55:48 +0200 Subject: [PATCH 2/3] Fixed the issues. Signed-off-by: Malte Tammena --- Makefile | 4 ++-- src/game/Main.java | 8 ++++---- src/player/MalteAI.java | 4 ++-- src/player/MaurizioAI.java | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index dee4017..774101d 100644 --- a/Makefile +++ b/Makefile @@ -17,8 +17,8 @@ src/game/GameHistory.java \ src/game/GameEntry.java \ src/game/PlayerObject.java \ src/player/Player.java \ -src/player/Player1.java \ -src/player/Player2.java +src/player/MalteAI.java \ +src/player/MaurizioAI.java OBJECTS=$($(subst $(CLASSPATH),$(BUILDS),$(CLASSES)):.java=.class) diff --git a/src/game/Main.java b/src/game/Main.java index 4bea8c2..4e0a53b 100644 --- a/src/game/Main.java +++ b/src/game/Main.java @@ -1,14 +1,14 @@ package game; import player.Player; -import player.Player1; -import player.Player2; +import player.MaurizioAI; +import player.MalteAI; public class Main { public static void main(String[] args) { - Player p1 = new Player1("Malte"); - Player p2 = new Player2("Maurizio"); + Player p1 = new MalteAI("Malte"); + Player p2 = new MaurizioAI("Maurizio"); new Game(p1, p2).start(); } } diff --git a/src/player/MalteAI.java b/src/player/MalteAI.java index d7f1759..0b7b371 100644 --- a/src/player/MalteAI.java +++ b/src/player/MalteAI.java @@ -2,12 +2,12 @@ package player; import java.util.Random; -public class Player2 implements Player{ +public class MalteAI implements Player{ private String name; private Random ran; - public Player2(String name){ + public MalteAI(String name){ this.name = name; this.ran = new Random(); } diff --git a/src/player/MaurizioAI.java b/src/player/MaurizioAI.java index 2c5f9c0..2d782a2 100644 --- a/src/player/MaurizioAI.java +++ b/src/player/MaurizioAI.java @@ -2,12 +2,12 @@ package player; import java.util.Random; -public class Player1 implements Player { +public class MaurizioAI implements Player { private String name; private Random ran; - public Player1(String name){ + public MaurizioAI(String name){ this.name = name; this.ran = new Random(); } From 9a32883dbd0b9d067fdab6c6af37428bdbcd2bfa Mon Sep 17 00:00:00 2001 From: Malte Tammena Date: Mon, 16 Oct 2017 11:10:05 +0200 Subject: [PATCH 3/3] Fixing winner being called Player 1/2. Signed-off-by: Malte Tammena --- src/game/Game.java | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/game/Game.java b/src/game/Game.java index 5b14463..a9ad413 100644 --- a/src/game/Game.java +++ b/src/game/Game.java @@ -145,13 +145,15 @@ public class Game { // --- CHECK WIN --- // Check rows outer:for (int i = 0; i < GAME_COLUMNS; i++) { + // Player One's counter int count1 = 0; + // Player Two's counter int count2 = 0; for (int j = 0; j < GAME_ROWS; j++) { - if (this.board[i][j] == 1) { + if (this.board[i][j] == p1.getID()) { count1++; count2 = 0; - } else if (this.board[i][j] == 2) { + } else if (this.board[i][j] == p2.getID()) { count1 = 0; count2++; } else { @@ -159,12 +161,12 @@ public class Game { count2 = 0; } if (count1 >= 4) { - log("Player 1 won!"); + log(p1.getP().getName() + " won!"); this.gameOn = false; break outer; } if (count2 >= 4) { - log("Player 2 won!"); + log(p2.getP().getName() + " won!"); this.gameOn = false; break outer; } @@ -172,13 +174,15 @@ public class Game { } // Check columns outer:for (int j = 0; j < GAME_ROWS; j++) { + // Player One's counter int count1 = 0; + // Player Two's counter int count2 = 0; for (int i = 0; i < GAME_COLUMNS; i++) { - if (this.board[i][j] == 1) { + if (this.board[i][j] == p1.getID()) { count1++; count2 = 0; - } else if (this.board[i][j] == 2) { + } else if (this.board[i][j] == p2.getID()) { count1 = 0; count2++; } else { @@ -186,12 +190,12 @@ public class Game { count2 = 0; } if (count1 >= 4) { - log("Player 1 won!"); + log(p1.getP().getName() + " won!"); this.gameOn = false; break outer; } if (count2 >= 4) { - log("Player 2 won!"); + log(p2.getP().getName() + " won!"); this.gameOn = false; break outer; } @@ -228,10 +232,10 @@ public class Game { count2 = 0; reverse = false; } - if (this.board[posX][posY] == 1) { + if (this.board[posX][posY] == p1.getID()) { count1++; count2 = 0; - } else if (this.board[posX][posY] == 2) { + } else if (this.board[posX][posY] == p2.getID()) { count1 = 0; count2++; } else { @@ -239,12 +243,12 @@ public class Game { count2 = 0; } if (count1 >= 4) { - log("Player 1 won!"); + log(p1.getP().getName() + " won!"); this.gameOn = false; break outer; } if (count2 >= 4) { - log("Player 2 won!"); + log(p2.getP().getName() + " won!"); this.gameOn = false; break outer; } @@ -282,10 +286,10 @@ public class Game { count2 = 0; reverse = false; } - if (this.board[posX][posY] == 1) { + if (this.board[posX][posY] == p1.getID()) { count1++; count2 = 0; - } else if (this.board[posX][posY] == 2) { + } else if (this.board[posX][posY] == p2.getID()) { count1 = 0; count2++; } else { @@ -293,12 +297,12 @@ public class Game { count2 = 0; } if (count1 >= 4) { - log("Player 1 won!"); + log(p1.getP().getName() + " won!"); this.gameOn = false; break outer; } if (count2 >= 4) { - log("Player 2 won!"); + log(p2.getP().getName() + " won!"); this.gameOn = false; break outer; }