-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVacuumRobot.java
49 lines (39 loc) · 1.43 KB
/
VacuumRobot.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
import java.io.IOException;
import java.util.Scanner;
public class VacuumRobot {
public static void main(String[] args) throws IOException, IllegalArgumentException{
World world = new World();
String nameOfFile="";
int numberOfAgents;
if(args.length==0||args.length>2){
System.out.println("You did not enter any command line arguments.");
System.out.println("Enter name of file: ");
Scanner reader = new Scanner(System.in);
nameOfFile = reader.next();
System.out.println("Enter number of agents (1 or 2)");
numberOfAgents = reader.nextInt();
}else{
nameOfFile = args[0];
numberOfAgents = Integer.parseInt(args[1]);
}
if(numberOfAgents==0||numberOfAgents>2){
throw new IllegalArgumentException("Invalid number of agents");
}
world.buildGrid(nameOfFile);
for(int i= 0; i<numberOfAgents; i++){
world.addAgent();
}
if(numberOfAgents==1){
while (world.agents[0].isOn) {
world.agents[0].makeDecision();
System.out.println(world);
}
}else {
while (world.agents[0].isOn || world.agents[1].isOn) {
world.agents[0].makeDecision();
world.agents[1].makeDecision();
System.out.println(world);
}
}
}
}