Commit b76ae08d authored by Matt Tower's avatar Matt Tower
Browse files

RandomPlayer class 8:57 Nov 11

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