Commit 3fdfe06d authored by Stefano Cobelli's avatar Stefano Cobelli
Browse files

Board.getSize() added

Autoplayable now only includes decideMove()
BlockerPlayer almost completed
parent 2f9e6c00
...@@ -45,6 +45,13 @@ public class Board { ...@@ -45,6 +45,13 @@ public class Board {
clear(); clear();
} }
/**
* @return the size
*/
public int getSize() {
return size;
}
/** /**
* clears the whole board. Sets states to NONE * clears the whole board. Sets states to NONE
* *
......
...@@ -14,8 +14,4 @@ package model.player; ...@@ -14,8 +14,4 @@ package model.player;
public interface AutoPlayable { public interface AutoPlayable {
public boolean decideMove(); public boolean decideMove();
public int getDecidedRow();
public int getDecidedCol();
} }
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
*/ */
package model.player; package model.player;
import java.util.ArrayList;
import model.Board; import model.Board;
import model.Mark; import model.Mark;
...@@ -31,10 +33,59 @@ public class BlockerPlayer extends Player implements AutoPlayable { ...@@ -31,10 +33,59 @@ public class BlockerPlayer extends Player implements AutoPlayable {
*/ */
@Override @Override
public boolean decideMove() { public boolean decideMove() {
Mark[] marks = new Mark[theBoard.getSize()];
// Rows
for (int row = 0; row < theBoard.getSize(); row++) {
for (int col = 0; col < theBoard.getSize(); col++) {
marks[row] = theBoard.getMark(row, col);
}
if (checkSpots(marks) != -1)
return move(row, checkSpots(marks));
marks.
}
// Cols
for (int col = 0; col < theBoard.getSize(); col++) {
for (int row = 0; row < theBoard.getSize(); row++) {
marks[col] = theBoard.getMark(row, col);
}
if (checkSpots(marks) != -1)
return marks.add(theBoard.getMark(checkSpots(marks), col));
marks.clear();
}
// DiagNW
for (int rowCol = 0; rowCol < theBoard.getSize(); rowCol++) {
marks.add(theBoard.getMark(rowCol, rowCol));
}
if (checkSpots(marks) != -1)
return marks.add(theBoard.getMark(checkSpots(marks),
checkSpots(marks)));
marks.clear();
// DiagNE
for (int rowCol = 0; rowCol < theBoard.getSize(); rowCol++) {
marks.add(theBoard.getMark(rowCol, theBoard.getSize() - rowCol));
}
if (checkSpots(marks) != -1)
return marks.add(theBoard.getMark(checkSpots(marks),
checkSpots(marks)));
return false; return false;
} }
/**
* Checks an array list of marks to see if there's a blocking opertunity
*
* @param mark0
* @param mark1
* @param mark2
* @return the index of the spot to block
*/
public int checkSpots(Mark[] marks) {
boolean openSpot;
for (Mark i : marks) {
}
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
...@@ -58,56 +109,11 @@ public class BlockerPlayer extends Player implements AutoPlayable { ...@@ -58,56 +109,11 @@ public class BlockerPlayer extends Player implements AutoPlayable {
} }
/** /**
* Looks to see if two of the other players marks are in a specified row and * Utility array that clears an array
* the spot to block is not taken
*
* @param row
* @return col in spot to block. -1 if can't block
*/
public int findTwoInRow(int row) {
if
}
/**
* Looks to see if two of the other players marks are in a specified col and
* the spot to block is not taken
*
* @param col
* @return row in spot to block. -1 if can't block
*/
public int findTwoInCol(int col) {
}
/**
* Looks to see if two of the other players marks are in the NorthEast
* diagnal. returns the row if there's a spot to block
*
* @return row in spot to block. -1 if can't block
*/
public int findTwoInDiagNE() {
}
/**
* Looks to see if two of the other players marks are in the NorthWest
* diagnal. returns the row if there's a spot to block
*
* @return row in spot to block. -1 if can't block
*/
public int findTwoInDiagNW() {
}
/**
* Checks three marks to see if there's a blocking opertunity
*
* @param mark0
* @param mark1
* @param mark2
* @return the index of the spot to block
*/ */
public int checkThreeSpots(Mark mark0, Mark mark1, Mark mark2) { public void clearArray(Mark[] marks) {
for (int i = 0; i < theBoard.getSize(); i++) {
}
} }
} }
...@@ -17,9 +17,9 @@ import model.Mark; ...@@ -17,9 +17,9 @@ import model.Mark;
public class Player { public class Player {
/** reference to the current board */ /** reference to the current board */
private Board theBoard; protected Board theBoard;
/** mark used by player */ /** mark used by player */
private Mark myMark; protected Mark myMark;
/** /**
* constructor that initializes the board and mark * constructor that initializes the board and mark
......
Supports Markdown
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