Merge branch 'master' into malte-ai

This commit is contained in:
Malte Tammena 2017-10-16 11:25:53 +02:00
commit 3a7b86a1ff
5 changed files with 30 additions and 26 deletions

View file

@ -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)

View file

@ -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;
}

View file

@ -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();
}
}

View file

@ -4,12 +4,12 @@ import java.util.Random;
import java.util.Set;
import java.util.HashSet;
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();
}

View file

@ -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();
}