Диаграмма по проге
12.06.2013, 00:16. Показов 1277. Ответов 0
Сделал прогу, а диаграмму составить не могу, даже не представляю как это сделать. Надо составить UML-диаграмму прецедентов. Прочитал на вики, что надо описать, что с чем взаимодействует, но все равно не понимаю, как ее рисовать.
Мир Вампуса – это пещера, состоящая из залов. Среда разделена на клетки. Вампус – зверь, который поедает всех в своем зале. Охотники ищут в пещере золото. Охотники может убить Вампуса единственной стрелой, выстрелив в прямом направлении. В пещере имеются ямы, в которые может провалиться охотник. Целью охотников является получение золота. Местоположение ям, золота и Вампуса каждый раз выбирается случайно.
Охотник имеет датчики: запаха, ветра блеска (золота), удара (о стену), звука (крик пораженного Вампуса). Агент может двигаться вперед, поворачиваться на 90 градусов, стрелять в прямом направлении (единственной стрелой). Агент знает правила действующие в среде, знает свои координаты, но не знает конфигурацию среды. Вампус не может двигаться.
javaapplication1
| Code | 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
| package javaapplication1;
import java.io.*;
import java.awt.*;
import java.applet.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.ImageObserver;
import java.beans.PropertyChangeListener;
import java.lang.reflect.InvocationTargetException;
import java.text.AttributedCharacterIterator;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.rmi.CORBA.Tie;
import javax.swing.Action;
import javax.swing.Timer;
public class JavaApplication1 extends Applet implements Runnable
{
public static int WIDTH = 10;
public static int HEIGHT = 10;
static Graphics g;
Thread thread;
Timer t;
world w;
public void paint(Graphics g) {
int step=20;
g.fillRect(0, 0, 20, 20);
for(int i=0;i<10;i++){
for(int j=0;j<10;j++){
if(world.myWorld[i][j].type==0)
{
if(world.myWorld[i][j].was==false)
{
g.setColor(Color.LIGHT_GRAY);
g.fillRect(i*step, j*step, 20, 20);
}
else
{
g.setColor(Color.WHITE);
g.fillRect(i*step, j*step, 20, 20);
}
}
if(world.myWorld[i][j].type==1){
g.setColor(Color.ORANGE);
g.fillRect(i*step, j*step, 20, 20);
g.setColor(Color.ORANGE);
if (world.Hanter.forward == 101)
g.drawLine(i*step+20, j*step+16, i*step, j*step+16);
if (world.Hanter.forward == 102)
g.drawLine(i*step+20, j*step+4, i*step, j*step+4);
if (world.Hanter.forward == 103)
g.drawLine(i*step+20, j*step+16, i*step, j*step+16);
if (world.Hanter.forward == 104)
g.drawLine(i*step+16, j*step+20, i*step+16, j*step);
}
if(world.myWorld[i][j].type==2){
g.setColor(Color.BLUE);
g.fillRect(i*step, j*step, 20, 20);}
if(world.myWorld[i][j].type==3){
g.setColor(Color.BLACK);
g.fillRect(i*step, j*step, 20, 20);}
if(world.myWorld[i][j].type==4){
g.setColor(Color.YELLOW);
g.fillRect(i*step, j*step, 20, 20);}
if(world.myWorld[i][j].wampus>0)
{
g.setColor(Color.GREEN);
g.fillRect(i*step, j*step, 20, 20);
}
}
}
for (int i=0;i<11;i++){
g.setColor(Color.BLACK);
g.drawLine(0,i*step, 200, i*step);
g.drawLine(i*step, 0, i*step,200);
}
}
public void init() {
w = new world();
world.init_world();
t = new Timer(200, ActionToPerform());
System.out.println("init");
}
@Override
public void run() {
}
public void start()
{
t.start();
}
private ActionListener ActionToPerform()
{
return new ActionListener() {
public void actionPerformed(ActionEvent ae) {
repaint();
if(!world.action())
t.stop();
}
};
}
public void stop() {
t.stop();
}
public void destroy() {
System.out.println("Method destroy()");
}
} |
|
point.java
| Code | 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
| package javaapplication1;
public class Point
{
public int x;
public int y;
public int type;
public int done; //нужна для поиска пути
public boolean was; //true посещена, false нет
public int pit; //0 неисслед, -1 точно нет ямы, 1-3 - возможно яма, 4 - точно яма
public int wampus;//0 неисслед, -1 точно ничего нет, 1 возможный вампус, -2 мертвый вампус
public int gold;//0 неисслед, -1 точно ничего, 1 возможное золото, 5 золото
public Point()
{
type=0;
was=false;
done=-1;
gold=0;
pit=0;
wampus=0;
}
public Point(int x,int y)
{
this.x=x;
this.y=y;
type=0;
was=false;
done=-1;
gold=0;
pit=0;
wampus=0;
}
} |
|
hanter.java
| Code | 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
| package javaapplication1;
public class hanter {
static int x,y;
static boolean k;
static int growl=5;//рычание
static int breeze=6;//сквозняк
static int glitter=7;//блеск
static int bump = 8;
// направления
final int SOUTH = 101;
final int NORTH = 102;
final int WEST = 103;
final int EAST = 104;
int forward;
final int FRW = 105;
final int LEFT = 106;
final int RIGHT = 107;
public hanter()
{
x=0;
y=0;
}
public hanter(int x,int y)
{
this.x=x;
this.y=y;
}
int scan (int target)
{
int p=0;
if(x<9)
if(world.myWorld[x+1][y].type==target)
p=1;
if (x>0)
if(world.myWorld[x-1][y].type==target)
p=1;
if (y<9)
if(world.myWorld[x][y+1].type==target)
p=1;
if (y>0)
if(world.myWorld[x][y-1].type==target)
p=1;
return p;
}
Point p1 = new Point();
int step(Point p1)
{
System.out.print(" STEP to ");
System.out.print(p1.x);
System.out.print(".");
System.out.print(p1.y);
System.out.print("! ");
int x_x = this.x-p1.x;
int y_y = this.y-p1.y;
if (x_x==0)
if (y_y==1) this.forward=NORTH;
else this.forward=SOUTH;
else
if (x_x==1)this.forward=WEST;
else this.forward=EAST;
this.x=p1.x;
this.y=p1.y;
return 0;
}
} |
|
wampus.java
| Code | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| package javaapplication1;
public class wampus {
int x;
int y;
public wampus()
{
x=(int)(Math.random()*10);
if(x>1)
y=(int)(Math.random()*10);
else
y=(int)(2+Math.random()*8);
}
public wampus (int x,int y)
{
this.x= x;
this.y= y;
}
} |
|
world.java
| Code | 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
| package javaapplication1;
import java.awt.Color;
import java.awt.Graphics;
import java.util.*;
import sun.net.www.http.Hurryable;
class world
{
static int xanter=1;
static int wampus=2;
static int pit=3;
static int gold=4;
static int MAP_SIZE_X = 10;
static int MAP_SIZE_Y = 10;
public static hanter Hanter = new hanter();
private static wampus Wampus = new wampus();
static List<Point>list;
static List<Point>route;
static Point myWorld[][] = new Point[MAP_SIZE_X][MAP_SIZE_Y];
private static void FillWorld(int value,int count)
{
for (int i=0;i<count;i++)
while(true)
{
int x = (int)(Math.random()*MAP_SIZE_X);
int y = (int)(Math.random()*MAP_SIZE_Y);
if (myWorld[x][y].type==0)
{
myWorld[x][y].type=value;
if (value == xanter)
{
Hanter.x= x;
Hanter.y= y;
}
if (value == wampus)
{
Wampus.x= x;
Wampus.y= y;
}
break;
}
}
}
public static void WPrint()
{
System.out.println();
System.out.println("World_done:");
for(int i=0;i<10;i++)
{
for(int j=0;j<10;j++)
{
System.out.print(myWorld[i][j].done);
}
System.out.println();
}
}
public world()
{
list = new ArrayList<Point>();
route = new ArrayList<Point>();
}
public static void init_world()
{
for (int i=0;i<10;i++)
for (int j=0;j<10;j++)
{
myWorld[i][j]= new Point(i,j);
}
myWorld[Hanter.x][Hanter.y].type=xanter;
FillWorld(pit, 5);
FillWorld(gold, 1);
FillWorld(wampus,1);
System.out.println("init world");
}
public static void Near_Status_Pit(int x,int y,int status)
{
if(x<9 && myWorld[x+1][y].pit != -1)myWorld[x+1][y].pit=status;
if(x>0 && myWorld[x-1][y].pit != -1)myWorld[x-1][y].pit=status;
if(y<9 && myWorld[x][y+1].pit != -1)myWorld[x][y+1].pit=status;
if(y>0 && myWorld[x][y-1].pit != -1)myWorld[x][y-1].pit=status;
}
public static void Near_Status_Gold(int x,int y,int status)
{
if(x<9 && myWorld[x+1][y].gold != -1)myWorld[x+1][y].gold=status;
if(x>0 && myWorld[x-1][y].gold != -1)myWorld[x-1][y].gold=status;
if(y<9 && myWorld[x][y+1].gold != -1)myWorld[x][y+1].gold=status;
if(y>0 && myWorld[x][y-1].gold != -1)myWorld[x][y-1].gold=status;
}
public static void Near_Status_Wampus(int x,int y,int status)
{
if(x<9)
if (myWorld[x+1][y].wampus != -1)myWorld[x+1][y].wampus=status;
if(x>0)
if(myWorld[x-1][y].wampus != -1)myWorld[x-1][y].wampus=status;
if(y<9)
if(myWorld[x][y+1].wampus != -1)myWorld[x][y+1].wampus=status;
if(y>0)
if(myWorld[x][y-1].wampus != -1)myWorld[x][y-1].wampus=status;
}
public static void Update(int x, int y)
{
System.out.println();
if(!list.contains(myWorld[x][y]))
{
XYList();
System.out.print(myWorld[x][y].x);
System.out.print(".");
System.out.print(myWorld[x][y].y);
System.out.print(" done: ");
System.out.print(myWorld[x][y].done);
System.out.print(" gold: ");
System.out.print(myWorld[x][y].gold);
System.out.print(" pit: ");
System.out.print(myWorld[x][y].pit);
System.out.print(" type: ");
System.out.print(myWorld[x][y].type);
System.out.print(" wapus: ");
System.out.print(myWorld[x][y].wampus);
if (myWorld[x][y].was==false)
{
System.out.print(" :: ");
if ((myWorld[x][y].pit == -1) && (myWorld[x][y].wampus ==-1))
{
System.out.print(" sequre ");
list.add(0,myWorld[x][y]);
XYList();
}
else
if(!list.contains(myWorld[x][y]))
{
if(myWorld[x][y].pit<3 || myWorld[x][y].wampus<3)
{System.out.print(" dd ");
XYList();
}
}
}
System.out.print("::: ");
Point tmp = new Point();
for (int i=0;i<list.size();i++) //если какая-то клетка посещена,
{ //или яма, или вампус, она удаляется
tmp=list.get(i);
if ((tmp.was==true) || (tmp.type==2) || (tmp.type==3))
{
System.out.print("was: ");
System.out.print(tmp.x);
System.out.print(".");
System.out.print(tmp.y);
System.out.print(" ");
while (!list.contains(tmp))
list.remove(tmp);
}
}
for(int i=0;i<list.size();i++)//золото добавляется в начало списка
{
tmp=list.get(i);
if (tmp.gold>0 && tmp.pit<1 && tmp.wampus<1)
{
System.out.print("gold!: ");
System.out.print(tmp.x);
System.out.print(".");
System.out.print(tmp.y);
System.out.print(" ");
while (!list.contains(tmp))
list.remove(tmp);
list.add(0,tmp);
}
}
}
System.out.print("%");
XYList();
}
public static void XYList()
{
System.out.print("(List points: ");
for (int i=0;i<list.size();i++)
{
System.out.print(list.get(i).x);
System.out.print(".");
System.out.print(list.get(i).y);
System.out.print(" ");
}
System.out.print(") ");
}
public static void ROADList()
{
System.out.print("<Road points: ");
for (int i=0;i<route.size();i++)
{
System.out.print(route.get(i).x);
System.out.print(".");
System.out.print(route.get(i).y);
System.out.print("-");
}
System.out.print("> ");
}
public static void Update_Near(int x,int y)
{
System.out.println("Start Update ");
if(x<9) {Update(x+1,y);}
if(x>0) {Update(x-1,y);}
if(y<9) {Update(x,y+1);}
if(y>0) {Update(x,y-1);}
}
public static boolean action()
{
if(myWorld[Hanter.x][Hanter.y].was!=true)
{
myWorld[Hanter.x][Hanter.y].was=true;
Scaning();
list.remove(myWorld[Hanter.x][Hanter.y]);
if(!list.isEmpty())
{
if(!Search(myWorld[Hanter.x][Hanter.y],list.get(0)).isEmpty())
{
System.out.println("::");
ROADList();
while (!route.isEmpty())
{
System.out.print(route.get(route.size()-1).x);
System.out.print(route.get(route.size()-1).y);
myWorld[Hanter.x][Hanter.y].type=0;
Hanter.step(route.get(route.size()-1));
if(route.get(route.size()-1).type==4)
{
myWorld[Hanter.x][Hanter.y].type=xanter;
System.out.println();
System.out.println("End. Gold is found");
return false;
}
route.remove(route.size()-1);
ROADList();
myWorld[Hanter.x][Hanter.y].type=xanter;
System.out.print("cicle ");
}
}
}
else
{
System.out.println("cicle ");
System.out.println("End");
return false;
}
}
return true;
}
public static List Search(Point A,Point B)
{
System.out.println();
System.out.print("Search way:");
System.out.print(A.x);
System.out.print(".");
System.out.print(A.y);
System.out.print("-");
System.out.print(B.x);
System.out.print(".");
System.out.println(B.y);
route.clear();
for (int i=0;i<10;i++)
for (int j=0;j<10;j++)
{
myWorld[i][j].done=-1;
}
A.done=0;
int f=A_Star(A,B,0);
if (f==0)
{
System.out.println("Not enable point");
}
if (B.done==-1)
{
System.out.println("Route not found");
}
route.add(B);
while (B.done!=0)
{
if (B.x<9 && B.done - myWorld[B.x+1][B.y].done==1)
{
route.add(myWorld[B.x+1][B.y]);
B=myWorld[B.x+1][B.y];
}
else
{
if (B.x>0 && B.done - myWorld[B.x-1][B.y].done==1)
{
route.add(myWorld[B.x-1][B.y]);
B=myWorld[B.x-1][B.y];
}
else
{
if (B.y>0 && B.done - myWorld[B.x][B.y-1].done==1)
{
route.add(myWorld[B.x][B.y-1]);
B=myWorld[B.x][B.y-1];
}
else
{
if (B.y<9 && B.done - myWorld[B.x][B.y+1].done==1)
{
route.add(myWorld[B.x][B.y+1]);
B=myWorld[B.x][B.y+1];
}
}
}
}
}
ROADList();
return route;
}
public static int A_Star (Point A, Point B,int index)
{
int f=0;
if (A.x>0 && (myWorld[A.x-1][A.y].was==true || myWorld[A.x-1][A.y]==B) &&
(myWorld[A.x-1][A.y].done==-1 || myWorld[A.x-1][A.y].done>index+1))
{
myWorld[A.x-1][A.y].done=index+1;
A_Star(myWorld[A.x-1][A.y],B,index+1);
f=1;
}
if (A.x<9 && (myWorld[A.x+1][A.y].was==true || myWorld[A.x+1][A.y]==B) &&
(myWorld[A.x+1][A.y].done==-1 || myWorld[A.x+1][A.y].done>index+1))
{
myWorld[A.x+1][A.y].done=index+1;
A_Star(myWorld[A.x+1][A.y],B,index+1);
f=1;
}
if (A.y>0 && (myWorld[A.x][A.y-1].was==true || myWorld[A.x][A.y-1]==B) &&
(myWorld[A.x][A.y-1].done==-1 || myWorld[A.x][A.y-1].done>index+1))
{
myWorld[A.x][A.y-1].done=index+1;
A_Star(myWorld[A.x][A.y-1],B,index+1);
f=1;
}
if (A.y<9 && (myWorld[A.x][A.y+1].was==true || myWorld[A.x][A.y+1]==B) &&
(myWorld[A.x][A.y+1].done==-1 || myWorld[A.x][A.y+1].done>index+1))
{
myWorld[A.x][A.y+1].done=index+1;
A_Star(myWorld[A.x][A.y+1],B,index+1);
f=1;
}
// WPrint();
return f;
}
public static void Scaning ()
{
System.out.println("scaning start");
if(Hanter.scan(3) != 1)
Near_Status_Pit(Hanter.x,Hanter.y,-1);
else
Near_Status_Pit(Hanter.x,Hanter.y,myWorld[Hanter.x][Hanter.y].pit+1);
System.out.print("scaning 33%... ");
if(Hanter.scan(2) != 1)
Near_Status_Wampus(Hanter.x,Hanter.y,-1);
else
Near_Status_Wampus(Hanter.x,Hanter.y,(myWorld[Hanter.x][Hanter.y].wampus)+1);
System.out.print("66%... ");
if(Hanter.scan(4) != 1)
Near_Status_Gold(Hanter.x,Hanter.y,-1);
else
Near_Status_Gold(Hanter.x,Hanter.y,myWorld[Hanter.x][Hanter.y].gold+1);
System.out.println("100%");
Update_Near(Hanter.x,Hanter.y);
}
} |
|
0
|