Commit 4d538c31 authored by Stefano Cobelli's avatar Stefano Cobelli

BlockerPanel ready to be tested

parent 3fdfe06d
......@@ -7,8 +7,6 @@
*/
package model.player;
import java.util.ArrayList;
import model.Board;
import model.Mark;
......@@ -41,7 +39,7 @@ public class BlockerPlayer extends Player implements AutoPlayable {
}
if (checkSpots(marks) != -1)
return move(row, checkSpots(marks));
marks.
marks = new Mark[theBoard.getSize()];
}
// Cols
for (int col = 0; col < theBoard.getSize(); col++) {
......@@ -49,71 +47,48 @@ public class BlockerPlayer extends Player implements AutoPlayable {
marks[col] = theBoard.getMark(row, col);
}
if (checkSpots(marks) != -1)
return marks.add(theBoard.getMark(checkSpots(marks), col));
marks.clear();
return move(checkSpots(marks), col);
marks = new Mark[theBoard.getSize()];
}
// DiagNW
for (int rowCol = 0; rowCol < theBoard.getSize(); rowCol++) {
marks.add(theBoard.getMark(rowCol, rowCol));
marks[rowCol] = (theBoard.getMark(rowCol, rowCol));
}
if (checkSpots(marks) != -1)
return marks.add(theBoard.getMark(checkSpots(marks),
checkSpots(marks)));
marks.clear();
return move(checkSpots(marks), checkSpots(marks));
marks = new Mark[theBoard.getSize()];
// DiagNE
for (int rowCol = 0; rowCol < theBoard.getSize(); rowCol++) {
marks.add(theBoard.getMark(rowCol, theBoard.getSize() - rowCol));
marks[rowCol] = theBoard.getMark(rowCol, theBoard.getSize()
- rowCol);
}
if (checkSpots(marks) != -1)
return marks.add(theBoard.getMark(checkSpots(marks),
checkSpots(marks)));
return move(checkSpots(marks), theBoard.getSize()
- checkSpots(marks));
return false;
}
/**
* Checks an array list of marks to see if there's a blocking opertunity
* Checks an array of marks to see if there's a blocking opertunity. Array
* could be a row, col, or diag
*
* @param mark0
* @param mark1
* @param mark2
* @param marks
* - array of marks
* @return the index of the spot to block
*/
public int checkSpots(Mark[] marks) {
boolean openSpot;
for (Mark i : marks) {
int openSpot = -1;
for (int i = 0; i < marks.length; i++) {
if (marks[i] == this.getMark())
return -1;
if (marks[i] == Mark.NONE) {
if (openSpot == -1)
return -1;
else
openSpot = i;
}
}
return openSpot;
}
/*
* (non-Javadoc)
*
* @see model.player.AutoPlayable#getDecidedRow()
*/
@Override
public int getDecidedRow() {
// TODO Auto-generated method stub
return 0;
}
/*
* (non-Javadoc)
*
* @see model.player.AutoPlayable#getDecidedCol()
*/
@Override
public int getDecidedCol() {
// TODO Auto-generated method stub
return 0;
}
/**
* Utility array that clears an array
*/
public void clearArray(Mark[] marks) {
for (int i = 0; i < theBoard.getSize(); 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