Skip to content

Commit

Permalink
fix bug in trade_util
Browse files Browse the repository at this point in the history
  • Loading branch information
ppppppw committed Aug 6, 2021
1 parent 1670f52 commit 056e9ee
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions capital/trade_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,13 @@ def get_rand_good(goods_dict, nonzero=False):
# we can't allocate what we don't have!
print("Goods are depleted!")
return None
lst = [good for good in
goods_dict if goods_dict[good][AMT_AVAIL] > 0]
if (len(lst) == 0):
return None
# return random.choice([good for good in
# goods_dict if goods_dict[good][AMT_AVAIL] > 0])
return random.choice(lst)
# lst = [good for good in
# goods_dict if goods_dict[good][AMT_AVAIL] > 0]
# if (len(lst) == 0):
# return None
return random.choice([good for good in
goods_dict if goods_dict[good][AMT_AVAIL] > 0])
# return random.choice(lst)


def incr_util(good_dict, good, amt=None, agent=None, graph=False, comp=None):
Expand Down Expand Up @@ -367,11 +367,12 @@ def _init1(side1, side2, distance_bt):
"""
pass
side1["good"] = get_rand_good(side1["trader"]["goods"])
if (side1["good"] is None):
return REJECT
# if (side1["good"] is None):
# return REJECT
side1_good = side1["trader"]["goods"][side1["good"]]
# check trader_distance vs. transport here!
if \
# if \
if (side1["good"] is None) or \
(check_transportability(side1_good, distance_bt) == REJECT):
return REJECT
else:
Expand All @@ -384,10 +385,11 @@ def _init2(trade, side2, distance_bt):
Code for init2 state of negotiate.
"""
side2["good"] = get_rand_good(side2["trader"]["goods"])
if (side2["good"] is None):
return REJECT
# if (side2["good"] is None):
# return REJECT
side2_good = side2["trader"]["goods"][side2["good"]]
if \
# if \
if (side2["good"] is None) or \
(check_transportability(side2_good, distance_bt) == REJECT):
return REJECT
else:
Expand Down

0 comments on commit 056e9ee

Please sign in to comment.