diff options
author | Pacien TRAN-GIRARD | 2015-11-26 10:28:22 +0100 |
---|---|---|
committer | Pacien TRAN-GIRARD | 2015-11-26 10:28:22 +0100 |
commit | 093fd685341c334be63ec950e44aa3a1edc82915 (patch) | |
tree | 5f8b1083833ded4efa90ccf3323c48f18df1db81 /src/ch/epfl/maze | |
parent | 1e2eff1e9829f8ffa694f3258433c91c804ab473 (diff) | |
download | maze-solver-093fd685341c334be63ec950e44aa3a1edc82915.tar.gz |
Refactor main programs
Diffstat (limited to 'src/ch/epfl/maze')
-rw-r--r-- | src/ch/epfl/maze/main/Console.java | 81 | ||||
-rw-r--r-- | src/ch/epfl/maze/main/Program.java | 83 | ||||
-rw-r--r-- | src/ch/epfl/maze/util/SimulationGenerator.java | 128 |
3 files changed, 139 insertions, 153 deletions
diff --git a/src/ch/epfl/maze/main/Console.java b/src/ch/epfl/maze/main/Console.java index 0c273e1..ebe1e3e 100644 --- a/src/ch/epfl/maze/main/Console.java +++ b/src/ch/epfl/maze/main/Console.java | |||
@@ -1,18 +1,8 @@ | |||
1 | package ch.epfl.maze.main; | 1 | package ch.epfl.maze.main; |
2 | 2 | ||
3 | import ch.epfl.maze.physical.Daedalus; | ||
4 | import ch.epfl.maze.physical.Maze; | ||
5 | import ch.epfl.maze.physical.pacman.*; | ||
6 | import ch.epfl.maze.physical.zoo.Hamster; | ||
7 | import ch.epfl.maze.physical.zoo.Monkey; | ||
8 | import ch.epfl.maze.physical.zoo.Mouse; | ||
9 | import ch.epfl.maze.physical.zoo.Panda; | ||
10 | import ch.epfl.maze.simulation.DaedalusSimulation; | ||
11 | import ch.epfl.maze.simulation.MazeSimulation; | ||
12 | import ch.epfl.maze.simulation.Simulation; | 3 | import ch.epfl.maze.simulation.Simulation; |
13 | import ch.epfl.maze.util.LabyrinthGenerator; | 4 | import ch.epfl.maze.util.SimulationGenerator; |
14 | import ch.epfl.maze.util.Statistics; | 5 | import ch.epfl.maze.util.Statistics; |
15 | import ch.epfl.maze.util.Vector2D; | ||
16 | 6 | ||
17 | import java.util.Collections; | 7 | import java.util.Collections; |
18 | import java.util.List; | 8 | import java.util.List; |
@@ -30,12 +20,11 @@ public class Console { | |||
30 | * Number of simulations launched. | 20 | * Number of simulations launched. |
31 | */ | 21 | */ |
32 | public static final int NUMBER_OF_SIMULATIONS = 1000; | 22 | public static final int NUMBER_OF_SIMULATIONS = 1000; |
23 | public static final String DEFAULT_SIM = "maze"; | ||
33 | 24 | ||
34 | public static void main(String[] args) { | 25 | public static void main(String[] args) { |
35 | Simulation simulation; | 26 | String simName = args.length > 0 ? args[0] : DEFAULT_SIM; |
36 | 27 | Simulation simulation = SimulationGenerator.getSimulation(simName); | |
37 | simulation = getMazeSimulation(); | ||
38 | //simulation = getDaedalusSimulation(); | ||
39 | 28 | ||
40 | System.out.print("Launching " + NUMBER_OF_SIMULATIONS + " simulations..."); | 29 | System.out.print("Launching " + NUMBER_OF_SIMULATIONS + " simulations..."); |
41 | Map<String, List<Integer>> results = | 30 | Map<String, List<Integer>> results = |
@@ -46,68 +35,6 @@ public class Console { | |||
46 | } | 35 | } |
47 | 36 | ||
48 | /** | 37 | /** |
49 | * Creates a {@code MazeSimulation} suitable for statistics. | ||
50 | * <p> | ||
51 | * Note that there should be only <b>ONE</b> animal of each kind in the | ||
52 | * corresponding {@code Maze}. | ||
53 | * | ||
54 | * @return A {@code MazeSimulation} suitable for statistics | ||
55 | */ | ||
56 | public static Simulation getMazeSimulation() { | ||
57 | int[][] labyrinth = LabyrinthGenerator.getMedium(); | ||
58 | Maze m = new Maze(labyrinth); | ||
59 | Simulation simulation = new MazeSimulation(m); | ||
60 | |||
61 | // adds a Mouse | ||
62 | m.addAnimal(new Mouse(m.getStart())); | ||
63 | |||
64 | // adds a Monkey | ||
65 | m.addAnimal(new Monkey(m.getStart())); | ||
66 | |||
67 | // adds a Hamster | ||
68 | m.addAnimal(new Hamster(m.getStart())); | ||
69 | |||
70 | // adds a Bear (if this bonus is coded) | ||
71 | // m.addAnimal(new Bear(m.getStart())); | ||
72 | |||
73 | // adds a Panda | ||
74 | m.addAnimal(new Panda(m.getStart())); | ||
75 | |||
76 | return simulation; | ||
77 | } | ||
78 | |||
79 | /** | ||
80 | * Creates a {@code DaedalusSimulation} suitable for statistics. | ||
81 | * <p> | ||
82 | * Note that there should be only <b>ONE</b> animal of each kind in the | ||
83 | * corresponding {@code Daedalus}. | ||
84 | * | ||
85 | * @return A {@code DaedalusSimulation} suitable for statistics | ||
86 | */ | ||
87 | public static Simulation getDaedalusSimulation() { | ||
88 | int[][] labyrinth = LabyrinthGenerator.getPacMan(); | ||
89 | Daedalus d = new Daedalus(labyrinth); | ||
90 | Simulation simulation = new DaedalusSimulation(d); | ||
91 | |||
92 | // adds Pac-Man | ||
93 | d.addPrey(new PacMan(new Vector2D(9, 15))); | ||
94 | |||
95 | // adds Blinky | ||
96 | d.addPredator(new Blinky(new Vector2D(17, 1))); | ||
97 | |||
98 | // adds Pinky | ||
99 | d.addPredator(new Pinky(new Vector2D(1, 1))); | ||
100 | |||
101 | // adds Inky | ||
102 | d.addPredator(new Inky(new Vector2D(17, 17))); | ||
103 | |||
104 | // adds Clyde | ||
105 | d.addPredator(new Clyde(new Vector2D(1, 17))); | ||
106 | |||
107 | return simulation; | ||
108 | } | ||
109 | |||
110 | /** | ||
111 | * Pretty-prints the statistics computed in the parameters. | 38 | * Pretty-prints the statistics computed in the parameters. |
112 | * | 39 | * |
113 | * @param results Statistics of arrival times for every animals/preys | 40 | * @param results Statistics of arrival times for every animals/preys |
diff --git a/src/ch/epfl/maze/main/Program.java b/src/ch/epfl/maze/main/Program.java index 347eace..4692d2a 100644 --- a/src/ch/epfl/maze/main/Program.java +++ b/src/ch/epfl/maze/main/Program.java | |||
@@ -1,18 +1,8 @@ | |||
1 | package ch.epfl.maze.main; | 1 | package ch.epfl.maze.main; |
2 | 2 | ||
3 | import ch.epfl.maze.graphics.Display; | 3 | import ch.epfl.maze.graphics.Display; |
4 | import ch.epfl.maze.physical.Daedalus; | ||
5 | import ch.epfl.maze.physical.Maze; | ||
6 | import ch.epfl.maze.physical.pacman.*; | ||
7 | import ch.epfl.maze.physical.zoo.Hamster; | ||
8 | import ch.epfl.maze.physical.zoo.Monkey; | ||
9 | import ch.epfl.maze.physical.zoo.Mouse; | ||
10 | import ch.epfl.maze.physical.zoo.Panda; | ||
11 | import ch.epfl.maze.simulation.DaedalusSimulation; | ||
12 | import ch.epfl.maze.simulation.MazeSimulation; | ||
13 | import ch.epfl.maze.simulation.Simulation; | 4 | import ch.epfl.maze.simulation.Simulation; |
14 | import ch.epfl.maze.util.LabyrinthGenerator; | 5 | import ch.epfl.maze.util.SimulationGenerator; |
15 | import ch.epfl.maze.util.Vector2D; | ||
16 | 6 | ||
17 | /** | 7 | /** |
18 | * Mini-project main program that will run the simulations on a {@code Display}. | 8 | * Mini-project main program that will run the simulations on a {@code Display}. |
@@ -21,79 +11,20 @@ import ch.epfl.maze.util.Vector2D; | |||
21 | */ | 11 | */ |
22 | public class Program { | 12 | public class Program { |
23 | 13 | ||
14 | public static final String DEFAULT_SIM = "maze"; | ||
15 | |||
24 | /** | 16 | /** |
25 | * Runs one of the two available simulations | 17 | * Runs one of the two available simulations |
26 | * | 18 | * |
27 | * @see #getMazeSimulation() | 19 | * @see ch.epfl.maze.util.SimulationGenerator#getMazeSimulation() |
28 | * @see #getDaedalusSimulation() | 20 | * @see ch.epfl.maze.util.SimulationGenerator#getMultiPreyDaedalusSimulation() |
29 | */ | 21 | */ |
30 | public static void main(String[] args) { | 22 | public static void main(String[] args) { |
31 | Simulation simulation; | 23 | String simName = args.length > 0 ? args[0] : DEFAULT_SIM; |
32 | 24 | Simulation simulation = SimulationGenerator.getSimulation(simName); | |
33 | simulation = getMazeSimulation(); | ||
34 | //simulation = getDaedalusSimulation(); | ||
35 | 25 | ||
36 | Display display = new Display(simulation); | 26 | Display display = new Display(simulation); |
37 | display.run(); | 27 | display.run(); |
38 | } | 28 | } |
39 | 29 | ||
40 | /** | ||
41 | * Creates a {@code MazeSimulation} with every animal implementations. | ||
42 | * | ||
43 | * @return A {@code MazeSimulation} to display | ||
44 | */ | ||
45 | public static Simulation getMazeSimulation() { | ||
46 | int[][] labyrinth = LabyrinthGenerator.getMedium(); | ||
47 | Maze m = new Maze(labyrinth); | ||
48 | Simulation simulation = new MazeSimulation(m); | ||
49 | |||
50 | // adds a Mouse | ||
51 | m.addAnimal(new Mouse(m.getStart())); | ||
52 | |||
53 | // adds a Monkey | ||
54 | m.addAnimal(new Monkey(m.getStart())); | ||
55 | |||
56 | // adds a Hamster | ||
57 | m.addAnimal(new Hamster(m.getStart())); | ||
58 | |||
59 | // adds a Bear (if this bonus is coded) | ||
60 | //m.addAnimal(new Bear(m.getStart())); | ||
61 | |||
62 | // adds a Panda | ||
63 | m.addAnimal(new Panda(m.getStart())); | ||
64 | |||
65 | return simulation; | ||
66 | } | ||
67 | |||
68 | /** | ||
69 | * Creates a {@code DaedalusSimulation} with every ghost implementation and | ||
70 | * 3 Pac-Mans. | ||
71 | * | ||
72 | * @return A {@code DaedalusSimulation} to display | ||
73 | */ | ||
74 | public static Simulation getDaedalusSimulation() { | ||
75 | int[][] labyrinth = LabyrinthGenerator.getPacMan(); | ||
76 | Daedalus d = new Daedalus(labyrinth); | ||
77 | Simulation simulation = new DaedalusSimulation(d); | ||
78 | |||
79 | // adds Pac-Mans | ||
80 | d.addPrey(new PacMan(new Vector2D(9, 15))); | ||
81 | d.addPrey(new PacMan(new Vector2D(10, 15))); | ||
82 | d.addPrey(new PacMan(new Vector2D(8, 15))); | ||
83 | |||
84 | // adds Blinky | ||
85 | d.addPredator(new Blinky(new Vector2D(17, 1))); | ||
86 | |||
87 | // adds Pinky | ||
88 | d.addPredator(new Pinky(new Vector2D(1, 1))); | ||
89 | |||
90 | // adds Inky | ||
91 | d.addPredator(new Inky(new Vector2D(17, 17))); | ||
92 | |||
93 | // adds Clyde | ||
94 | d.addPredator(new Clyde(new Vector2D(1, 17))); | ||
95 | |||
96 | return simulation; | ||
97 | } | < |