Mercurial > rinkhals
comparison gamelib/gameboard.py @ 462:aba7f1439571
avoid division by zero
author | Adrianna Pińska <adrianna.pinska@gmail.com> |
---|---|
date | Mon, 23 Nov 2009 21:06:16 +0000 |
parents | 279caa00f3fa |
children | e3408c803b12 |
comparison
equal
deleted
inserted
replaced
461:279caa00f3fa | 462:aba7f1439571 |
---|---|
841 return len([(x,y) for x in range(width) for y in range(height) if self.tv.get((x,y)) == self.WOODLAND]) | 841 return len([(x,y) for x in range(width) for y in range(height) if self.tv.get((x,y)) == self.WOODLAND]) |
842 | 842 |
843 def calculate_wood_groat_exchange_rate(self): | 843 def calculate_wood_groat_exchange_rate(self): |
844 # per five planks | 844 # per five planks |
845 width, height = self.tv.size | 845 width, height = self.tv.size |
846 sell_price = float(10*width*height)/self.trees_left() | 846 treesleft = max(1, self.trees_left()) |
847 sell_price = float(10*width*height)/treesleft | |
847 buy_price = sell_price*(1.1) | 848 buy_price = sell_price*(1.1) |
848 self.wood_sell_price, self.wood_buy_price = int(sell_price), int(buy_price) | 849 self.wood_sell_price, self.wood_buy_price = int(sell_price), int(buy_price) |
849 | 850 |
850 def save_game(self): | 851 def save_game(self): |
851 return serializer.simplify(self) | 852 return serializer.simplify(self) |