-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomPlayer.java
More file actions
38 lines (36 loc) · 865 Bytes
/
Copy pathRandomPlayer.java
File metadata and controls
38 lines (36 loc) · 865 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import java.util.*;
import java.awt.Color;
/**
* Represents a
* random player in a chess game
* who plays random moves each turn.
*
* @author Linda Zeng
* @version 4.9.23
*/
public class RandomPlayer extends Player
{
/**
* Constructs a random player with given attributes.
*
* @param boardP board to play on
* @param nameP name of player
* @param colorP color to play
*/
public RandomPlayer(Board boardP, String nameP, Color colorP)
{
super(boardP, nameP, colorP);
}
/**
* Returns next move the
* player will play (randomized)
*
* @return player's next move
*/
public Move nextMove()
{
ArrayList<Move> moves = getBoard().allMoves(getColor());
int random = (int)(Math.random() * moves.size());
return moves.get(random);
}
}