-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalcs.java
More file actions
56 lines (53 loc) · 1.14 KB
/
Calcs.java
File metadata and controls
56 lines (53 loc) · 1.14 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
46
47
48
49
50
51
52
53
54
55
56
//Here the calculations take place
public void actionPerformed(ActionEvent e){
JButton o=(JButton)e.getSource();
ArrayList<Integer> possibleMoves=board.findPossibleMoves(-1);
if(possibleMoves.size()>0){
int i=0;
for(i=0;i<64;i++){
if(buttons[i]==o){
try{
board.move(-1,i/8,i%8);
}
catch(Exception exception){
JOptionPane.showMessageDialog(null,exception.getMessage());
return;
}
update(board);
break;
}
}
}
boolean flag=true;
while(flag){
int count=0;
possibleMoves=board.findPossibleMoves(1);
if(possibleMoves.size()>0){
System.out.println("Bot's move");
int pos=Game.bot.think(board,possibleMoves);
int x=pos/8;
int y=pos%8;
try{
board.move(1,x,y);
}
catch(Exception exception){
System.out.println(exception.getMessage());
}
update(board);
}
else
count++;
possibleMoves=board.findPossibleMoves(-1);
if(possibleMoves.size()>0)
flag=false;
else
count++;
if(count==2){
board.displayResult();
board=new Board();
update(board);
return;
}
}
System.out.println("Your move");
}