9 private int m_nrofblocks;
13 public int m_nrofpacs;
14 public int[] m_pacMenX;
15 public int[] m_pacMenY;
16 public int[] m_directions;
17 public int[] m_pacOriX;
18 public int[] m_pacOriY;
19 public int[] m_leftLives;
20 public int[] m_leftLevels;
21 //public int[] m_destinationX; // for ghosts to expact pamen's behaviour
22 //public int[] m_destinationY;
25 public int m_paccount;
26 public int m_deathcount;
29 public int m_nrofghosts;
30 public int[] m_ghostsX;
31 public int[] m_ghostsY;
32 public int[] m_ghostdirections;
33 public int[] m_targets;
34 public int m_ghostcount;
35 public int m_failghostcount;
40 public Map(int nrofpacs, int nrofghosts) {
41 //System.printString("step 1\n");
42 this.m_nrofblocks = 15;
43 this.m_map = new int[this.m_nrofblocks*this.m_nrofblocks];
45 this.m_nrofpacs = nrofpacs;
46 this.m_pacMenX = new int[this.m_nrofpacs];
47 this.m_pacMenY = new int[this.m_nrofpacs];
48 this.m_directions = new int[this.m_nrofpacs];
49 this.m_pacOriX = new int[this.m_nrofpacs];
50 this.m_pacOriY = new int[this.m_nrofpacs];
51 this.m_leftLives = new int[this.m_nrofpacs];
52 this.m_leftLevels = new int[this.m_nrofpacs];
53 //this.m_destinationX = new int[this.m_nrofpacs * 2];
54 //this.m_destinationY = new int[this.m_nrofpacs * 2];
55 this.m_desX = new int[this.m_nrofpacs];
56 this.m_desY = new int[this.m_nrofpacs];
58 this.m_deathcount = 0;
60 this.m_nrofghosts = nrofghosts;
61 this.m_ghostsX = new int[this.m_nrofghosts];
62 this.m_ghostsY = new int[this.m_nrofghosts];
63 this.m_ghostdirections = new int[this.m_nrofghosts];
64 this.m_targets = new int[this.m_nrofghosts];
65 this.m_ghostcount = 0;
66 this.m_failghostcount = 0;
68 this.m_r = new Random();
70 for(int i = 0; i < this.m_nrofblocks*this.m_nrofblocks; i++) {
74 //System.printString("step 2\n");
75 for(int i = 0; i < this.m_nrofpacs; i++) {
76 this.m_pacMenX[i] = this.m_pacMenY[i] = -1;
77 this.m_directions[i] = 0;
78 this.m_pacOriX[i] = this.m_pacOriY[i] = -1;
79 this.m_leftLives[i] = this.m_leftLevels[i] = 0;
80 //this.m_destinationX[i] = this.m_destinationY[i] = -1;
81 //this.m_destinationX[this.m_nrofpacs + i] = this.m_destinationY[this.m_nrofpacs + i] = -1;
82 this.m_desX[i] = this.m_desY[i] = -1;
84 //System.printString("step 3\n");
85 for(int i = 0; i < this.m_nrofghosts; i++) {
86 this.m_ghostsX[i] = this.m_ghostsY[i] = -1;
87 this.m_targets[i] = -1;
89 //System.printString("step 4\n");
95 this.m_map[i++]=3;this.m_map[i++]=10;this.m_map[i++]=10;this.m_map[i++]=6;this.m_map[i++]=9;this.m_map[i++]=12;this.m_map[i++]=3;this.m_map[i++]=10;this.m_map[i++]=6;this.m_map[i++]=9;this.m_map[i++]=12;this.m_map[i++]=3;this.m_map[i++]=10;this.m_map[i++]=10;this.m_map[i++]=6;
96 this.m_map[i++]=5;this.m_map[i++]=11;this.m_map[i++]=14;this.m_map[i++]=1;this.m_map[i++]=10;this.m_map[i++]=10;this.m_map[i++]=4;this.m_map[i++]=15;this.m_map[i++]=1;this.m_map[i++]=10;this.m_map[i++]=10;this.m_map[i++]=4;this.m_map[i++]=11;this.m_map[i++]=14;this.m_map[i++]=5;
97 this.m_map[i++]=1;this.m_map[i++]=10;this.m_map[i++]=10;this.m_map[i++]=4;this.m_map[i++]=11;this.m_map[i++]=6;this.m_map[i++]=1;this.m_map[i++]=10;this.m_map[i++]=4;this.m_map[i++]=3;this.m_map[i++]=14;this.m_map[i++]=1;this.m_map[i++]=10;this.m_map[i++]=10;this.m_map[i++]=4;
98 this.m_map[i++]=5;this.m_map[i++]=3;this.m_map[i++]=6;this.m_map[i++]=9;this.m_map[i++]=6;this.m_map[i++]=5;this.m_map[i++]=5;this.m_map[i++]=7;this.m_map[i++]=5;this.m_map[i++]=5;this.m_map[i++]=3;this.m_map[i++]=12;this.m_map[i++]=3;this.m_map[i++]=6;this.m_map[i++]=5;
99 this.m_map[i++]=5;this.m_map[i++]=9;this.m_map[i++]=8;this.m_map[i++]=14;this.m_map[i++]=5;this.m_map[i++]=13;this.m_map[i++]=5;this.m_map[i++]=5;this.m_map[i++]=5;this.m_map[i++]=13;this.m_map[i++]=5;this.m_map[i++]=11;this.m_map[i++]=8;this.m_map[i++]=12;this.m_map[i++]=5;
100 this.m_map[i++]=9;this.m_map[i++]=2;this.m_map[i++]=10;this.m_map[i++]=2;this.m_map[i++]=8;this.m_map[i++]=2;this.m_map[i++]=12;this.m_map[i++]=5;this.m_map[i++]=9;this.m_map[i++]=2;this.m_map[i++]=8;this.m_map[i++]=2;this.m_map[i++]=10;this.m_map[i++]=2;this.m_map[i++]=12;
101 this.m_map[i++]=6;this.m_map[i++]=5;this.m_map[i++]=7;this.m_map[i++]=5;this.m_map[i++]=7;this.m_map[i++]=5;this.m_map[i++]=11;this.m_map[i++]=8;this.m_map[i++]=14;this.m_map[i++]=5;this.m_map[i++]=7;this.m_map[i++]=5;this.m_map[i++]=7;this.m_map[i++]=5;this.m_map[i++]=3;
102 this.m_map[i++]=4;this.m_map[i++]=5;this.m_map[i++]=5;this.m_map[i++]=5;this.m_map[i++]=5;this.m_map[i++]=5;this.m_map[i++]=10;this.m_map[i++]=10;this.m_map[i++]=10;this.m_map[i++]=5;this.m_map[i++]=5;this.m_map[i++]=5;this.m_map[i++]=5;this.m_map[i++]=5;this.m_map[i++]=1;
103 this.m_map[i++]=12;this.m_map[i++]=5;this.m_map[i++]=13;this.m_map[i++]=5;this.m_map[i++]=13;this.m_map[i++]=5;this.m_map[i++]=11;this.m_map[i++]=10;this.m_map[i++]=14;this.m_map[i++]=5;this.m_map[i++]=13;this.m_map[i++]=5;this.m_map[i++]=13;this.m_map[i++]=5;this.m_map[i++]=9;
104 this.m_map[i++]=3;this.m_map[i++]=8;this.m_map[i++]=10;this.m_map[i++]=8;this.m_map[i++]=10;this.m_map[i++]=0;this.m_map[i++]=10;this.m_map[i++]=2;this.m_map[i++]=10;this.m_map[i++]=0;this.m_map[i++]=10;this.m_map[i++]=8;this.m_map[i++]=10;this.m_map[i++]=8;this.m_map[i++]=6;
105 this.m_map[i++]=5;this.m_map[i++]=3;this.m_map[i++]=2;this.m_map[i++]=2;this.m_map[i++]=6;this.m_map[i++]=5;this.m_map[i++]=15;this.m_map[i++]=5;this.m_map[i++]=15;this.m_map[i++]=5;this.m_map[i++]=3;this.m_map[i++]=2;this.m_map[i++]=2;this.m_map[i++]=6;this.m_map[i++]=5;
106 this.m_map[i++]=5;this.m_map[i++]=9;this.m_map[i++]=8;this.m_map[i++]=8;this.m_map[i++]=4;this.m_map[i++]=1;this.m_map[i++]=10;this.m_map[i++]=8;this.m_map[i++]=10;this.m_map[i++]=4;this.m_map[i++]=1;this.m_map[i++]=8;this.m_map[i++]=8;this.m_map[i++]=12;this.m_map[i++]=5;
107 this.m_map[i++]=1;this.m_map[i++]=10;this.m_map[i++]=10;this.m_map[i++]=6;this.m_map[i++]=13;this.m_map[i++]=5;this.m_map[i++]=11;this.m_map[i++]=2;this.m_map[i++]=14;this.m_map[i++]=5;this.m_map[i++]=13;this.m_map[i++]=3;this.m_map[i++]=10;this.m_map[i++]=10;this.m_map[i++]=4;
108 this.m_map[i++]=5;this.m_map[i++]=11;this.m_map[i++]=14;this.m_map[i++]=1;this.m_map[i++]=10;this.m_map[i++]=8;this.m_map[i++]=6;this.m_map[i++]=13;this.m_map[i++]=3;this.m_map[i++]=8;this.m_map[i++]=10;this.m_map[i++]=4;this.m_map[i++]=11;this.m_map[i++]=14;this.m_map[i++]=5;
109 this.m_map[i++]=9;this.m_map[i++]=10;this.m_map[i++]=10;this.m_map[i++]=12;this.m_map[i++]=3;this.m_map[i++]=6;this.m_map[i++]=9;this.m_map[i++]=10;this.m_map[i++]=12;this.m_map[i++]=3;this.m_map[i++]=6;this.m_map[i++]=9;this.m_map[i++]=10;this.m_map[i++]=10;this.m_map[i++]=12; // 15*15
112 public void placePacman(Pacman t) {
113 this.m_pacMenX[t.m_index] = t.m_locX;
114 this.m_pacMenY[t.m_index] = t.m_locY;
118 public void placeGhost(Ghost t) {
119 this.m_ghostsX[t.m_index] = t.m_locX;
120 this.m_ghostsY[t.m_index] = t.m_locY;
124 public boolean check(Pacman t) {
125 boolean death = false;
127 while((!death) && (i < this.m_ghostsX.length)) {
128 if((t.m_locX == this.m_ghostsX[i]) && (t.m_locY == this.m_ghostsY[i])) {
132 //System.printString("Pacman " + t.m_index + " caught! " + t.m_leftLives + "\n");
136 if((!death) && (t.m_locX == t.m_tx) && (t.m_locY == t.m_ty)) {
137 // reach the destination
138 //System.printString("Hit destination!\n");
142 //System.printString("Pacman " + t.m_index + " hit, upgrade! " + t.m_leftLevels + "\n");
146 // pacman has no more lives or no more levels
149 this.m_pacMenX[t.m_index] = -1;
150 this.m_pacMenY[t.m_index] = -1;
153 this.m_leftLives[t.m_index]--;
154 } else if(t.m_success) {
155 this.m_leftLevels[t.m_index]--;
158 this.m_pacMenX[t.m_index] = t.m_locX;
159 this.m_pacMenY[t.m_index] = t.m_locY;
160 this.m_directions[t.m_index] = 0;
161 //System.printString("Pacman " + t.m_index + " reset: (" + t.m_locX + ", " + t.m_locY + ")\n");
163 //this.m_destinationX[t.m_index] = this.m_destinationY[t.m_index] = -1;
164 //this.m_destinationX[this.m_nrofblocks + t.m_index] = this.m_destinationY[this.m_nrofblocks + t.m_index] = -1;
169 public boolean isfinish() {
170 return this.m_nrofpacs == 0;
173 public Vector getNeighbours(int index) {
174 Vector neighbours = new Vector();
175 int tmp = this.m_map[index];
176 int locX = index % this.m_nrofblocks;
177 int locY = index / this.m_nrofblocks;
178 if((int)(tmp & 1) == 0) {
181 neighbours.addElement(new Integer(locY * this.m_nrofblocks + this.m_nrofblocks - 1));
183 neighbours.addElement(new Integer(index - 1));
186 if((int)(tmp & 2) == 0) {
189 neighbours.addElement(new Integer((this.m_nrofblocks - 1) * this.m_nrofblocks + locX));
191 neighbours.addElement(new Integer((locY - 1) * this.m_nrofblocks + locX));
194 if((int)(tmp & 4) == 0) {
196 if(locX == this.m_nrofblocks - 1) {
197 neighbours.addElement(new Integer(locY * this.m_nrofblocks));
199 neighbours.addElement(new Integer(index + 1));
202 if((int)(tmp & 8) == 0) {
204 if(locY == this.m_nrofblocks - 1) {
205 neighbours.addElement(new Integer(locX));
207 neighbours.addElement(new Integer((locY + 1) * this.m_nrofblocks + locX));
213 /*public int[] getDominatePoint(int locX, int locY) {
214 int[] point = new int[2];
217 if(((int)(this.m_map.m_map[locX + locY * this.m_map.m_nrofblocks] & 2) +
218 (int)(this.m_map.m_map[locX + locY * this.m_map.m_nrofblocks] & 1) +
219 (int)(this.m_map.m_map[locX + locY * this.m_map.m_nrofblocks] & 8) +
220 (int)(this.m_map.m_map[locX + locY * this.m_map.m_nrofblocks] & 4)) == 4) {
221 // can not reach this point
224 } else if (((int)(this.m_map.m_map[locX + locY * this.m_map.m_nrofblocks] & 2) +
225 (int)(this.m_map.m_map[locX + locY * this.m_map.m_nrofblocks] & 1) +
226 (int)(this.m_map.m_map[locX + locY * this.m_map.m_nrofblocks] & 8) +
227 (int)(this.m_map.m_map[locX + locY * this.m_map.m_nrofblocks] & 4)) < 3) {
228 // can only reach it from multiple place
230 if (((int)(this.m_map.m_map[locX + locY * this.m_map.m_nrofblocks] & 2) {