-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathroadwest.py
More file actions
65 lines (50 loc) · 2.04 KB
/
roadwest.py
File metadata and controls
65 lines (50 loc) · 2.04 KB
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
#==============================================================================
# RoadWest class
#
# By Johnny Lin
# May 2015
#==============================================================================
import numpy as N
class RoadWest(object):
"""Create and manage a road west.
As cattle location information is stored in a Cattle object, the
purpose of the environmenet objects is to keep track of possible
spatial locations.
"""
def __init__(self, adjacent_salebarn=None):
self.length = 1
self.width = 3*16 #- Value depends on Farm width attribute
self.adjacent_salebarn = adjacent_salebarn
self.list_cattle = []
def loc_on_road(self, inCattle):
"""Return location on the road.
Since the road allows one cattle at any location, this method
only returns the value of how far you're down the road. The
end of the road is at the salebarn, and so the highest location
index is at the salebarn.
"""
if inCattle.farm_just_left == None:
if isinstance(inCattle, RoadWest):
return inCattle.loc_in_environ[1]
else:
return None
else:
aFarm = inCattle.farm_just_left
return aFarm.farm_index * aFarm.width + inCattle.loc_in_environ[1]
def move_cattle(self, inCattle):
"""Move cattle down the road or into the salebarn.
Assume that more than one cattle can occupy a single location.
"""
loc = N.array([0, inCattle.loc_in_environ[1] + 1])
if loc[1] >= self.width: #- end of the road, goto salebarn
self.list_cattle.remove(inCattle)
inCattle.environ = self.adjacent_salebarn
inCattle.inSale1 = True
inCattle.environ.list_cattle.append(inCattle)
loc = N.array([0, 0])
inCattle.loc_in_environ = loc
return inCattle
def feed_cattle(self, inCattle):
"""Cattle eat no food and gain no weight on the road.
"""
return inCattle