-
Notifications
You must be signed in to change notification settings - Fork 0
/
BlackBoxDomineering2.java
116 lines (93 loc) · 2.55 KB
/
BlackBoxDomineering2.java
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import java.util.Scanner;
public class BlackBoxDomineering2 {
private static class BlackBoxDomi implements MoveChannel<DomineeringMove>{
private String player;
public BlackBoxDomi(String player){
this.player = player;
}
/**
* Split the string 'x,y' and send the move
* @return - the move that the opponent plays
*/
@Override
public DomineeringMove getMove() {
@SuppressWarnings("resource")
Scanner moves = new Scanner(System.in);
String move = moves.nextLine();
String[] separateMoves = {};
int firstCoord = 0;
int secondCoord = 0;
separateMoves = move.split(",");
try{
firstCoord = Integer.parseInt(separateMoves[0]);
secondCoord = Integer.parseInt(separateMoves[1]);
}catch(NumberFormatException e){
System.exit(1);
}
if(player.equals("first")){
return new DomineeringMove(firstCoord, secondCoord, firstCoord, secondCoord + 1);
}else{
return new DomineeringMove(firstCoord, secondCoord, firstCoord + 1, secondCoord);
}
}
/**
* Print the move and flush after that to delete it from the Buffer reader
*/
@Override
public void giveMove(DomineeringMove move) {
System.out.println(move);
System.out.flush();
}
/**
* Exit when the game ends
*/
@Override
public void end(int Value) {
System.exit(0);
}
@Override
public void comment(String msg) {
}
}
public static void main(String[] args){
try{
assert(args.length == 4);
}catch(AssertionError e){
System.exit(1);
}
String player = args[0];
String blackBoxPlayer = args[1];
String width = args[2];
String height = args[3];
int exactWidth = 0;
int exactHeight = 0;
try{
exactWidth = Integer.parseInt(width);
exactHeight = Integer.parseInt(height);
}catch(NumberFormatException e){
System.exit(1);
}
DomineeringBoard2 board = new DomineeringBoard2(exactWidth, exactHeight);
/**
* Play first player if types "first", play second if typed "second"
* Play heuristic if the board size (width or height) is more than 5
*/
if(player.equals("first")){
if(exactWidth + exactHeight >= 10){
board.heuristicTree(2).firstPlayer(new BlackBoxDomi("first"));
}else{
board.tree().firstPlayer(new BlackBoxDomi("first"));
}
player = "first";
}else if(player.equals("second")){
if(exactWidth + exactHeight >= 10){
board.heuristicTree(2).secondPlayer(new BlackBoxDomi("second"));
}else{
board.tree().secondPlayer(new BlackBoxDomi("second"));
}
player = "second";
}else{
System.exit(1);
}
}
}