-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDiamondRoom.ts
102 lines (96 loc) · 4.54 KB
/
DiamondRoom.ts
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
class DiamondRoomLevel extends ALevel<DiamondRoomWorld> {
generator: DiamondRoomMapGenerator;
robot: IRobot<DiamondRoomWorld>;
constructor() {
super();
this.generator = new DiamondRoomMapGenerator();
this.robot = new MemoryRobot<DiamondRoomWorld>(this, this.resetWorld());
}
getName(): string { return "Diamond Room"; }
resetWorld(): DiamondRoomWorld {
var map: DiamondRoomMap = this.generator.getStandardMap();
return this.makeWorld(map);
}
makeWorld(map: DiamondRoomMap) {
var x: number = (Math.floor(Math.random() * ((map.getWidth() - 2)))) + 1;
var y: number = (Math.floor(Math.random() * ((map.getHeight() - 2)))) + 1;
while (map.isWall(x, y)) {
x = (Math.floor(Math.random() * ((map.getWidth() - 2)))) + 1;
y = (Math.floor(Math.random() * ((map.getHeight() - 2)))) + 1;
}
return new DiamondRoomWorld(randomDirection(), x, y, new Array<MemoryLabel>(), map, this.getNewvac(map, x, y));
}
getRobot(): IRobot<DiamondRoomWorld> {
return this.robot;
}
getNewvac(map : IMap, x : number, y: number): boolean[][] {
var newvac: boolean[][] = [];
for (var vx = 0; vx < map.getWidth(); vx++) {
newvac.push([]);
for (var vy = 0; vy < map.getHeight(); vy++) {
newvac[vx].push(false);
}
}
newvac[x][y] = true;
return newvac;
}
getTestMaps(): DiamondRoomWorld[] {
var map = this.generator.getTestMaps()[0];
var upx = Math.floor(map.getWidth() / 2);
var upy = 1;
while (map.isWall(upx, upy)) {
upy++;
}
return [new DiamondRoomWorld(Direction.North, upx, upy, [], map, this.getNewvac(map, upx, upy)),
new DiamondRoomWorld(Direction.East, upx, upy, [], map, this.getNewvac(map, upx, upy)),
new DiamondRoomWorld(Direction.West, upx, upy, [], map, this.getNewvac(map, upx, upy)),
new DiamondRoomWorld(Direction.South, upx, upy, [], map, this.getNewvac(map, upx, upy)),
new DiamondRoomWorld(Direction.North, upx+3, upy+3, [], map, this.getNewvac(map, upx+3, upy+3)),
new DiamondRoomWorld(Direction.East, upx+3, upy+3, [], map, this.getNewvac(map, upx+3, upy+3)),
new DiamondRoomWorld(Direction.West, upx+3, upy+3, [], map, this.getNewvac(map, upx+3, upy+3)),
new DiamondRoomWorld(Direction.South, upx+3, upy+3, [], map, this.getNewvac(map, upx+3, upy+3)),
new DiamondRoomWorld(Direction.North, upx, upy + Math.floor(map.getHeight() / 2), [], map, this.getNewvac(map, upx, upy + Math.floor(map.getHeight()/2))),
new DiamondRoomWorld(Direction.East, upx, upy + Math.floor(map.getHeight() / 2), [], map, this.getNewvac(map, upx, upy + Math.floor(map.getHeight() / 2))),
new DiamondRoomWorld(Direction.West, upx, upy + Math.floor(map.getHeight() / 2), [], map, this.getNewvac(map, upx, upy + Math.floor(map.getHeight() / 2))),
new DiamondRoomWorld(Direction.South, upx, upy + Math.floor(map.getHeight() / 2), [], map, this.getNewvac(map, upx, upy + Math.floor(map.getHeight() / 2)))];
}
}
class DiamondRoomMapGenerator extends AMapGenerator<DiamondRoomMap> {
constructor() {
super();
}
getStandardMap(): DiamondRoomMap {
return new DiamondRoomMap(25, 25);
}
getTestMaps(): DiamondRoomMap[] {
return [new DiamondRoomMap(11,11)];
}
}
class DiamondRoomMap extends AVacuumMap {
startx: number;
starty: number;
constructor(width: number, height: number) {
super(width, height);
var middlex = Math.floor(width / 2);
var middley = Math.floor(height / 2);
for (var x = 0; x < width; x++) {
var dist = Math.ceil(Math.abs(x - middlex) * (middley / middlex));
for (var y = 1; y <= dist; y++) {
this.walls[x][y] = true;
this.walls[x][height - 1 - y] = true;
}
}
}
}
class DiamondRoomWorld extends VacuumWorld<DiamondRoomWorld> {
map: DiamondRoomMap;
constructor(direction: Direction, x: number, y: number, memories: MemoryLabel[], map: DiamondRoomMap, vacuumed: boolean[][]) {
super(direction, x, y, memories, vacuumed);
this.map = map;
}
copyWithVacuumed(direction: Direction, x: number, y: number, memories: MemoryLabel[], vacuumed: boolean[][]): DiamondRoomWorld {
return new DiamondRoomWorld(direction, x, y, memories, this.map, vacuumed);
}
getVacuumMap(): AVacuumMap { return this.map; }
}