summaryrefslogtreecommitdiff
path: root/src/ch/epfl/maze/tests/GhostsTest.java
blob: 782a8f32081eab32e3db6a1b54d8b26a804b589d (plain)
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package ch.epfl.maze.tests;

import ch.epfl.maze.graphics.Display;
import ch.epfl.maze.physical.Animal;
import ch.epfl.maze.physical.Daedalus;
import ch.epfl.maze.physical.Prey;
import ch.epfl.maze.physical.pacman.Blinky;
import ch.epfl.maze.physical.pacman.Clyde;
import ch.epfl.maze.physical.pacman.Inky;
import ch.epfl.maze.physical.pacman.Pinky;
import ch.epfl.maze.simulation.DaedalusSimulation;
import ch.epfl.maze.simulation.Simulation;
import ch.epfl.maze.util.Direction;
import ch.epfl.maze.util.LabyrinthGenerator;
import ch.epfl.maze.util.Vector2D;
import junit.framework.TestCase;
import org.junit.Test;

/**
 * Test suite for ghosts implementation.
 */

public class GhostsTest extends TestCase {

    /**
     * Tests the behavior of Blinky.
     * <p>
     * In this case, Blinky should go straight to the PacMan's position.
     */

    @Test
    public void testBlinky() {
        int[][] labyrinth = LabyrinthGenerator.getDebugBlinky();

        Daedalus d = new Daedalus(labyrinth);
        Simulation simulation = new DaedalusSimulation(d);

        d.addPredator(new Blinky(new Vector2D(6, 1)));
        d.addPrey(new PacMan(new Vector2D(1, 5), false));

        Display display = new Display(simulation);
        display.setDebug(true);
        display.run();
    }

    /**
     * Tests the behavior of Pinky.
     * <p>
     * In this case, Pinky should go back and forth.
     */

    @Test
    public void testPinky() {
        int[][] labyrinth = LabyrinthGenerator.getDebugPinky();

        Daedalus d = new Daedalus(labyrinth);
        Simulation simulation = new DaedalusSimulation(d);

        d.addPredator(new Pinky(new Vector2D(1, 1)));
        d.addPrey(new PacMan(new Vector2D(6, 3), true));

        Display display = new Display(simulation);
        display.setDebug(true);
        display.run();
    }

    /**
     * Tests the behavior of Inky.
     * <p>
     * In this case, Inky should target the red tile of the labyrinth.
     */

    @Test
    public void testInky() {
        int[][] labyrinth = LabyrinthGenerator.getDebugInky();

        Daedalus d = new Daedalus(labyrinth);
        Simulation simulation = new DaedalusSimulation(d);

        d.addPredator(new Inky(new Vector2D(9, 9)));
        d.addPredator(new Blinky(new Vector2D(7, 7)));
        d.addPrey(new PacMan(new Vector2D(5, 5), false));

        Display display = new Display(simulation);
        display.setDebug(true);
        display.run();
    }

    /**
     * Tests the behavior of Clyde.
     * <p>
     * In this case, Clyde should go back and forth.
     */

    @Test
    public void testClyde() {
        int[][] labyrinth = LabyrinthGenerator.getDebugClyde();

        Daedalus d = new Daedalus(labyrinth);
        Simulation simulation = new DaedalusSimulation(d);

        d.addPredator(new Clyde(new Vector2D(1, 3)));
        d.addPrey(new PacMan(new Vector2D(8, 3), false));

        Display display = new Display(simulation);
        display.setDebug(true);
        display.run();
    }

    /**
     * Mock class to create a dummy PacMan in our testing unit.
     */

    private class PacMan extends Prey {

        private boolean mMoves;

        /**
         * Constructs a dummy PacMan that can move back and forth.
         *
         * @param position Starting position of PacMan in the labyrinth
         * @param moves    Determines if the dummy PacMan will move back and forth
         */

        public PacMan(Vector2D position, boolean moves) {
            super(position);
            mMoves = moves;
        }

        @Override
        public Direction move(Direction[] choices, Daedalus daedalus) {
            if (mMoves) {
                return getPosition().getX() % 2 == 0 ? Direction.RIGHT : Direction.LEFT;
            }
            return Direction.NONE;
        }

        @Override
        public Animal copy() {
            return new PacMan(getPosition(), mMoves);
        }
    }
}