tp1 partie 1 et partie 2.1/2.2
This commit is contained in:
19
TTT_java/AIPlayer.java
Normal file
19
TTT_java/AIPlayer.java
Normal file
@@ -0,0 +1,19 @@
|
||||
import java.util.Random;
|
||||
|
||||
public class AIPlayer extends Player {
|
||||
private Random random;
|
||||
|
||||
public AIPlayer(char mark) {
|
||||
super(mark);
|
||||
random = new Random();
|
||||
}
|
||||
|
||||
public void makeMove(Board board) {
|
||||
int row, col;
|
||||
do {
|
||||
row = random.nextInt(3);
|
||||
col = random.nextInt(3);
|
||||
} while (!board.isCellEmpty(row, col));
|
||||
board.placeMark(row, col, getMark());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user