Commit 49cc2733 authored by Anna Maria Eilertsen's avatar Anna Maria Eilertsen
Browse files

refactored code for checking winner + wincondition

parent 9f5902ce
......@@ -65,7 +65,7 @@ public abstract class MNKGame {
grid.set(x, y, currentPlayer);
if(getWinner(x, y)!=Piece.NONE) {
if(checkWinCondition(x, y)) {
winnerPiece = currentPlayer;
}
......@@ -75,12 +75,16 @@ public abstract class MNKGame {
public boolean hasWinner() {
return winnerPiece!=Piece.NONE;
}
public Piece getWinner(int x, int y) {
public Piece getWinner() {
return winnerPiece;
}
private boolean checkWinCondition(int x, int y) {
int count = 0;
Piece current = grid.get(x, y);
if(current==Piece.NONE)
return Piece.NONE;
return false;
System.out.println();
System.out.println("Currently at " + x + "," + y + " value " + current);
......@@ -98,7 +102,7 @@ public abstract class MNKGame {
count++;
}
if(count==k)
return current;
return true;
}
count = 0;
......@@ -114,7 +118,7 @@ public abstract class MNKGame {
count++;
}
if(count==k)
return current;
return true;
}
count = 0;
......@@ -131,7 +135,7 @@ public abstract class MNKGame {
count++;
}
if(count==k)
return current;
return true;
}
count = 0;
......@@ -148,9 +152,9 @@ public abstract class MNKGame {
count++;
}
if(count==k)
return current;
return true;
}
return Piece.NONE;
return false;
}
@Override
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment