-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTutorial.py
137 lines (120 loc) · 5.12 KB
/
Tutorial.py
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
import hexcoords
import sensor_gen
import world
from ENV import BLUE, RED
from main import Save
class Tutorial1:
def __init__(self):
hexcoords.Position.set_radius(5)
self.runing = True
self.red_units: set[world.Entity] = set()
self.blue_units: set[world.Entity] = set()
self.blue_base = world.Entity(
hexcoords.Position(0, 0, 0),
hexcoords.DIRECTION_EAST,
BLUE
)
self.world = world.World(5,
self.blue_base,
world.Entity(pos=hexcoords.Position(0, 0, 0), dir=hexcoords.DIRECTION_EAST, col=RED),
empty=True)
self.save = Save(self.world.world_map, [self.blue_base], folder="tutorial", filename="tutorial1")
self.ticks = 0
self.world_map = self.world.world_map
self.pheros = self.world.pheromone
self.red_unit_map = self.world.red_info
self.blue_unit_map = self.world.blue_info
self.save.add_step(self.red_units, *self.pheros)
self.save.add_step(self.red_units, *self.pheros)
self.save.add_step(self.red_units, *self.pheros)
self.save.dump()
Tutorial1()
def mock_val():
return 1
class Tutorial2():
def __init__(self):
hexcoords.Position.set_radius(5)
self.red_base = world.Entity(pos=hexcoords.Position(0, 2, -2), dir=hexcoords.DIRECTION_WEST, col=RED)
self.blue_base = world.Entity(pos=hexcoords.Position(0, -2, 2), dir=hexcoords.DIRECTION_EAST, col=BLUE)
self.unit_main = world.Entity(pos=hexcoords.Position(1, 0, -1), dir=hexcoords.DIRECTION_NORTH_EAST, col=RED)
self.red_units: set[world.Entity] = set()
self.red_units.add(self.unit_main)
self.blue_units: set[world.Entity] = set()
blue1 = world.Entity(pos=hexcoords.Position(-1, 1, 0), dir=hexcoords.DIRECTION_WEST, col=BLUE)
blue1.identity = mock_val
blue2 = world.Entity(pos=hexcoords.Position(-3, 2, 1), dir=hexcoords.DIRECTION_EAST, col=BLUE)
blue2.identity = mock_val
self.blue_units.add(blue1)
self.blue_units.add(blue2)
self.world = world.World(5,
world.Entity(pos=hexcoords.Position(0, 0, 0), dir=hexcoords.DIRECTION_EAST, col=RED),
world.Entity(pos=hexcoords.Position(0, 0, 0), dir=hexcoords.DIRECTION_EAST, col=RED),
empty=True)
self.world.register_entity(self.red_base)
self.world.register_entity(self.blue_base)
self.world.register_entity(blue1)
self.world.register_entity(blue2)
self.save = Save(self.world.world_map,
[self.red_base, self.blue_base]
, folder="tutorial", filename="tutorial2")
self.ticks = 0
self.world.emit_green_pheromon(pos=hexcoords.Position(2, 0, -2), value=102)
self.world.emit_red_pheromon(pos=hexcoords.Position(-1, 3, -2), value=102)
self.world.emit_blue_pheromon(pos=hexcoords.Position(2, 0, -2), value=102)
self.world.emit_blue_pheromon(pos=hexcoords.Position(-2, 3, -1), value=204)
self.world.emit_green_pheromon(pos=hexcoords.Position(-2, 1, 1), value=102)
self.world_map = self.world.world_map
self.pheros = self.world.pheromone
self.red_unit_map = self.world.red_info
self.blue_unit_map = self.world.blue_info
self.save_data()
self.MV()
self.save_data()
self.MV()
self.save_data()
self.TL()
self.save_data()
self.MV()
self.save_data()
self.TL()
self.save_data()
self.MV()
self.save_data()
self.MV()
self.save_data()
self.TL()
self.save_data()
self.MV()
self.save_data()
self.save_data()
self.save.declare_loser(BLUE)
self.save.data_out = True
self.save.dump()
def TL(self):
self.unit_main.turn_left()
def TR(self):
self.unit_main.turn_right()
def MV(self):
self.unit_main.move_in_direction()
def save_data(self):
self.save.add_step(self.red_units.union(self.blue_units), *self.pheros,
vision=sensor_gen.get_vision_data(
self.unit_main.position,
self.unit_main.direction,
self.world_map,
self.blue_unit_map,
self.red_unit_map
),
smell=sensor_gen.get_pheromone_data(
self.unit_main.position,
self.unit_main.direction,
self.pheros
),
sensor=sensor_gen.get_sensor_data(
self.unit_main.position,
self.unit_main.direction,
self.world_map,
self.blue_unit_map,
self.red_unit_map
))
Tutorial2()