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