Commit b76ae08d authored by Matt Tower's avatar Matt Tower

RandomPlayer class 8:57 Nov 11

parent b304cb03
......@@ -25,10 +25,7 @@ public class RandomPlayer extends Player implements AutoPlayable {
* declares the board, AI mark, Random object, random number variable,
* Arraylists to store rows and columns of free spaces on the current board
*/
private Board theBoard;
private Mark myMark;
private Random rand = new Random();
private int randNum;
private ArrayList<Integer> rowOptions = new ArrayList<Integer>();
private ArrayList<Integer> colOptions = new ArrayList<Integer>();
......@@ -44,28 +41,12 @@ public class RandomPlayer extends Player implements AutoPlayable {
}
/**
* returns the board
*
* @return - the board
*/
public Board getBoard() {
return this.theBoard;
}
/**
* generates a random number within board dimensions, used for choosing
* random coordinates
* RandomPlayer makes a random move
*
* @return - randomly generated number within board dimensions
*/
public int genRandNum() {
return this.rand.nextInt(theBoard.getSize());
}
/**
* finds the free spaces in the board currently
* @return - true if move was made successfully, false otherwise
*/
private void findFreeSpaces() {
@Override
public boolean decideMove() {
for (int i = 0; i < theBoard.getSize(); i++) {
for (int j = 0; j < theBoard.getSize(); j++) {
if (theBoard.isEmpty(i, j)) {
......@@ -74,17 +55,7 @@ public class RandomPlayer extends Player implements AutoPlayable {
}
}
}
}
/**
* RandomPlayer makes a random move
*
* @return - true if move was made successfully, false otherwise
*/
@Override
public boolean decideMove() {
findFreeSpaces();
randNum = rand.nextInt(theBoard.getSize());
int randNum = rand.nextInt(rowOptions.size());
return move(rowOptions.get(randNum), colOptions.get(randNum));
}
}
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