@@ -7,7 +7,23 @@ def __init__(self, length, initial_bananas, step):
7
7
self .bananastores = {0 : BananaStore (initial_bananas , initial_bananas )}
8
8
self .step = step
9
9
self .initial_bananas = initial_bananas
10
-
10
+ self .camel = None
11
+
12
+ def spawn_camel (self , camel_carrying_capacity ):
13
+ """
14
+ Create a camel in the world.
15
+ """
16
+ if self .camel is None :
17
+ self .camel = Camel (camel_carrying_capacity )
18
+ else :
19
+ raise AttributeError ("There is only one camel." )
20
+
21
+ def kill_camel (self ):
22
+ """
23
+ >:)
24
+ """
25
+ self .camel = None
26
+
11
27
def get_final_bananas (self , camel_carrying_capacity ):
12
28
my_camel = Camel (camel_carrying_capacity )
13
29
if my_camel .location in self .bananastores :
@@ -18,20 +34,53 @@ def get_final_bananas(self, camel_carrying_capacity):
18
34
# Camel needs to drop bananas, but keep enough to get back
19
35
# Camel goes back to get move bananas
20
36
return "Hello!"
37
+
38
+ def round_trip (self , end_point ):
39
+ """
40
+ Perform a round trip - update all banana stores and camel's banana store.
41
+ """
42
+ # Camel picks up bananas
43
+ bananas_at_start = self .bananastores [self .camel .location ]
44
+ bananas_to_pick_up = max (self .camel .banana_store .remaining_capacity (), bananas_at_start .bananas )
45
+ self .camel .banana_store .add (bananas_to_pick_up )
46
+
47
+ # Camel walks to destination and drops bananas
48
+ distance = end_point - self .camel .location
49
+ self .camel .move (distance )
50
+ number_of_bananas_to_drop = self .camel .banana_store .bananas - self .camel .bananas_required (distance )
51
+
52
+
53
+
21
54
22
55
23
56
class Camel :
24
57
25
- def __init__ (self , max_bananas ):
26
- self .max_bananas = max_bananas
27
- self .banana_store = BananaStore (0 , self .max_bananas )
58
+ def __init__ (self , camel_carrying_capacity ):
59
+ self .camel_carrying_capacity = camel_carrying_capacity
60
+ self .banana_consumption_rate = 1
61
+ self .banana_store = BananaStore (0 , self .camel_carrying_capacity )
28
62
self .location = 0
29
63
30
64
def move (self , distance ):
31
65
"""Positive distance moves towards destination
32
66
negative distance moves towards the beginning"""
33
67
self .location += distance
34
- self .banana_store .remove (abs (distance ))
68
+ self .banana_store .remove (self .bananas_required (distance ))
69
+
70
+ def bananas_required (self , distance ):
71
+ return self .banana_consumption_rate * abs (distance )
72
+
73
+ def possible_round_trip (self ):
74
+ """
75
+ Return the maximum possible round trip distance, assuming the camel drops all its bananas.
76
+ """
77
+ return self .banana_store .bananas // 2
78
+
79
+ def drop_bananas (self , box ):
80
+ """
81
+
82
+ """
83
+
35
84
36
85
37
86
class BananaStore :
@@ -72,5 +121,6 @@ def remaining_capacity(self):
72
121
for x in range (1000 ):
73
122
step = x
74
123
world = World (length , initial_bananas , step )
124
+ world .spawn_camel (camel_carrying_capacity )
75
125
results = world .get_final_bananas (camel_carrying_capacity )
76
126
print (results )
0 commit comments