Not a working state, implementing winning conditions
Signed-off-by: Malte Tammena <malte.tammena@gmx.de>
This commit is contained in:
parent
0dda4b6d0c
commit
3fe047f1bb
|
@ -36,11 +36,6 @@ public class Game {
|
|||
*/
|
||||
private int[][] board;
|
||||
|
||||
/**
|
||||
* Unplayed pieces in the game.
|
||||
*/
|
||||
private int piecesLeft;
|
||||
|
||||
/**
|
||||
* Is the game still running?
|
||||
*/
|
||||
|
@ -81,6 +76,7 @@ public class Game {
|
|||
if(gameOn) {
|
||||
turn = !turn;
|
||||
logGame();
|
||||
checkState();
|
||||
} else {
|
||||
System.out.println("*******************");
|
||||
System.out.println("Thanks for Playing!");
|
||||
|
@ -114,6 +110,42 @@ public class Game {
|
|||
}
|
||||
}
|
||||
|
||||
private int crawl(int i, int j) {
|
||||
int symbol = this.board[i][j];
|
||||
if (i > 0) {
|
||||
if (j > 0) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void checkState() {
|
||||
outer:for (int i = 0; i < this.board.length; i++) {
|
||||
for (int j = 0; j < this.board[i].length; j++) {
|
||||
if (crawl(i, j) >= 4) {
|
||||
log("We have a winner!");
|
||||
break outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
// --- CHECK DRAW ---
|
||||
boolean draw = true;
|
||||
outer:for (int i = 0; i < this.board.length; i++) {
|
||||
for (int j = 0; j < this.board[i].length; j++) {
|
||||
if (this.board[i][j] == 0) {
|
||||
draw = false;
|
||||
break outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (draw) {
|
||||
this.gameOn = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deep copies the board.
|
||||
*
|
||||
|
|
|
@ -1,19 +1,23 @@
|
|||
package player;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Player1 implements Player{
|
||||
|
||||
private String name;
|
||||
private Random ran;
|
||||
|
||||
public Player1(String name){
|
||||
this.name = name;
|
||||
this.ran = new Random();
|
||||
}
|
||||
|
||||
public int move(int[][] board){
|
||||
for(int i=0;i<board.length;i++){
|
||||
if(board[i][0] == 0){
|
||||
return i;
|
||||
}
|
||||
int choice = ran.nextInt(7);
|
||||
while (board[choice][0] != 0) {
|
||||
choice = ran.nextInt(7);
|
||||
}
|
||||
return -1; // that means the board is full
|
||||
return choice;
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
|
|
|
@ -1,19 +1,23 @@
|
|||
package player;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Player2 implements Player{
|
||||
|
||||
private String name;
|
||||
private Random ran;
|
||||
|
||||
public Player2(String name){
|
||||
this.name = name;
|
||||
this.ran = new Random();
|
||||
}
|
||||
|
||||
public int move(int[][] board){
|
||||
for(int i=0;i<board.length;i++){
|
||||
if(board[i][0] == 0){
|
||||
return i;
|
||||
}
|
||||
int choice = ran.nextInt(7);
|
||||
while (board[choice][0] != 0) {
|
||||
choice = ran.nextInt(7);
|
||||
}
|
||||
return -1; // that means the board is full
|
||||
return choice;
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
|
|
Loading…
Reference in a new issue