Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Stefano Cobelli
205_hw02
Commits
b76ae08d
Commit
b76ae08d
authored
Nov 11, 2014
by
Matt Tower
Browse files
RandomPlayer class 8:57 Nov 11
parent
b304cb03
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/model/player/RandomPlayer.java
View file @
b76ae08d
...
...
@@ -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
));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment