-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomAI.java
More file actions
45 lines (35 loc) · 1.09 KB
/
Copy pathRandomAI.java
File metadata and controls
45 lines (35 loc) · 1.09 KB
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
39
40
41
42
43
44
45
import javax.swing.Timer;
import java.awt.*;
import java.awt.event.*;
public class RandomAI extends IAI{
public RandomAI(){
setScore(0);
}
public static void playGUI(){
GameEngine g = new GameEngine();
BoardGUI b = g.getBoard();
Timer t = new Timer(500, new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
int move = makeRandomMove();
g.aIPlay(move);
if (b.isGameOver()){
Timer t = (Timer) e.getSource();
t.stop();
playGUI();
}
}
});
t.start();
}
public void playGame(){
Board b = new Board();
b.addRandomValue();
b.addRandomValue();
do{
int move = makeRandomMove();
move(b,move);
} while (!b.isGameOver());
setScore(b.getPoints());
}
}