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
41 """
42 The state of the ship for an outside observer
43 """
44
45 - def __init__(self, x, y, orientation, speed=0, angularSpeed=0):
46 """
47 Initialize an I{external state} of a ship, namely its position and speeds
48
49 @type x: float
50 @param x: x-position, in meters
51
52 @type y: float
53 @param y: y-position, in meters
54
55 @type orientation: float
56 @param orientation: the ship orientation, where -180 < orientation <= 180 degrees
57
58 @type speed: float
59 @param speed: ship forward speed in m/sec (TODO: need to replace it by x-speed and y-speed)
60
61 @type angularSpeed: float
62 @param angularSpeed: ship angular speed in deg / sec
63 """
64 self.x = x
65 self.y = y
66 self.orientation = orientation
67 self.speed = speed
68 self.angularSpeed = angularSpeed
69
71 return (isinstance(other, self.__class__) and self.__dict__ == other.__dict__)
72
74 return "\nExternal State:" + \
75 " x=" + str(self.x) + \
76 " y=" + str(self.y) + \
77 " orientation=" + str(self.orientation) + \
78 " speed=" + str(self.speed) + \
79 " angularSpeed=" + str(self.angularSpeed) + "\n"
80
81
82
83
84
86 """
87 This is a base class for the world state.
88 """
89
90 - def __init__(self, sea, ships, shipExternalStates):
91 """
92 Initialize the world state that is external to the agent.
93
94 @type sea: Sea
95 @param sea: the sea model
96
97 @type ships: array of Ship
98 @param ships: the ships being simulated
99
100 @type shipExternalStates: array of ShipExternalStates
101 @param shipExternalStates: the external states of the ships, namely their global positions
102 """
103
104 self.sea = sea
105 self.ships = ships
106 self.shipExternalStates = shipExternalStates
107
109 res = "\n\nWorld State: \n"
110 res += str(self.sea)
111 res += "\nShips:\n"
112 for ship, state in zip(self.ships, self.shipExternalStates):
113 res += str(ship) + str(state)
114 return res
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