Commit 24c57f54 authored by Stefano Cobelli's avatar Stefano Cobelli

Blocker player appears to be working, ready for junit tests

parent d2017dac
......@@ -155,7 +155,6 @@ public class TTTController implements ActionListener {
}
}
if (theGame.getCurPlayer() instanceof AutoPlayable) {
System.out.println("AI turn");
Integer[] aiMove = ((AutoPlayable) theGame.getCurPlayer())
.decideMove();
boardPanel.getButtonBoard()[aiMove[0]][aiMove[1]]
......
......@@ -7,6 +7,7 @@
*/
package model.player;
import java.util.Arrays;
import java.util.Random;
import model.Board;
......@@ -39,27 +40,29 @@ public class BlockerPlayer extends Player implements AutoPlayable {
// Rows
for (int row = 0; row < theBoard.getSize(); row++) {
for (int col = 0; col < theBoard.getSize(); col++) {
marks[row] = theBoard.getMark(row, col);
marks[col] = theBoard.getMark(row, col);
}
if (checkSpots(marks) != -1) {
move(row, checkSpots(marks));
Integer[] answer = { row, checkSpots(marks) };
return answer;
}
marks = new Mark[theBoard.getSize()];
Arrays.fill(marks, null);
}
// Cols
for (int col = 0; col < theBoard.getSize(); col++) {
for (int row = 0; row < theBoard.getSize(); row++) {
marks[col] = theBoard.getMark(row, col);
marks[row] = theBoard.getMark(row, col);
}
if (checkSpots(marks) != -1) {
move(checkSpots(marks), col);
Integer[] answer = { checkSpots(marks), col };
return answer;
}
marks = new Mark[theBoard.getSize()];
Arrays.fill(marks, null);
}
// DiagNW
for (int rowCol = 0; rowCol < theBoard.getSize(); rowCol++) {
marks[rowCol] = (theBoard.getMark(rowCol, rowCol));
......@@ -70,6 +73,7 @@ public class BlockerPlayer extends Player implements AutoPlayable {
return answer;
}
marks = new Mark[theBoard.getSize()];
Arrays.fill(marks, null);
// DiagNE
for (int rowCol = 0; rowCol < theBoard.getSize(); rowCol++) {
marks[rowCol] = theBoard.getMark(rowCol, (theBoard.getSize() - 1)
......@@ -83,6 +87,8 @@ public class BlockerPlayer extends Player implements AutoPlayable {
return answer;
}
System.out.println("Getting random");
Integer[][] coors = new Integer[theBoard.getSize() * theBoard.getSize()][2];
int index = 0;
for (int row = 0; row < theBoard.getSize(); row++) {
......@@ -115,7 +121,7 @@ public class BlockerPlayer extends Player implements AutoPlayable {
if (marks[i] == this.getMark())
return -1;
if (marks[i] == Mark.NONE) {
if (openSpot == -1)
if (openSpot != -1)
return -1;
else
openSpot = i;
......
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