-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComputerPlayer.java
More file actions
28 lines (25 loc) · 898 Bytes
/
ComputerPlayer.java
File metadata and controls
28 lines (25 loc) · 898 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
public class ComputerPlayer implements Player {
private Board board;
private char move;
public ComputerPlayer(Board board, char move){
this.board = board;
this.move = move;
}
public void playerPlays(){
int computerMoveX, computerMoveY;
while (true) {
computerMoveX = (int)(Math.random() * (board.getBoardSize()));
computerMoveY = (int)(Math.random() * (board.getBoardSize())) ;
if (!board.isValidMove(computerMoveX, computerMoveY))
break;
}
System.out.println("*****************Computer's move*****************");
placeMove(computerMoveX, computerMoveY,move);
}
private void placeMove (int x, int y, char move){ //**************************
if (board.isValidMove(x,y))
return;
else
board.placeMove(x, y, move);
}
}