diff options
author | Walter Bender <walter.bender@gmail.com> | 2011-12-16 03:38:39 (GMT) |
---|---|---|
committer | Walter Bender <walter.bender@gmail.com> | 2011-12-16 03:38:39 (GMT) |
commit | 9a4e59f23d3543d8537983aee3ab3858c32371e1 (patch) | |
tree | 329ac96f0c2bd8475f90f21970bfebe0251eb07a | |
parent | 53754e5186c75be8e3b43c69f0c8990f251596af (diff) |
add imported strategy to strategy list
-rw-r--r-- | TurtlePondActivity.py | 6 | ||||
-rw-r--r-- | game.py | 22 |
2 files changed, 12 insertions, 16 deletions
diff --git a/TurtlePondActivity.py b/TurtlePondActivity.py index 65700ee..f9ebfbc 100644 --- a/TurtlePondActivity.py +++ b/TurtlePondActivity.py @@ -191,8 +191,8 @@ class TurtlePondActivity(activity.Activity): ''' Load Python code from the Journal. ''' self._chooser('org.laptop.Pippy', self._load_python_code_from_journal) + self.custom_button.set_active(True) self._game.level = CUSTOM - # FIXME: set radio button self._game.new_game() def _load_python_code_from_journal(self, dsobject): @@ -205,8 +205,8 @@ class TurtlePondActivity(activity.Activity): file_handle.close() except IOError: _logger.debug("couldn't open %s" % dsobject.file_path) - self._game.strategy = python_code - self._game.strategy_msg = _('customized strategy') + self._game.strategies[CUSTOM] = python_code + self._game.msgs[CUSTOM] = _('customized strategy') def _chooser(self, filter, action): ''' Choose an object from the datastore and take some action ''' @@ -51,27 +51,22 @@ BEGINNER_STRATEGY = 'def _turtle_strategy(self, turtle):\n\ return self._dot_to_grid(dots[(i + n) % 6])\n\ self._orientation = (i + n) % 6\n\ return turtle\n' -INTERMEDIATE_MSG = _('turtle is looking for any open dot') +INTERMEDIATE_MSG = _('looking for an open path') INTERMEDIATE_STRATEGY = 'def _turtle_strategy(self, turtle):\n\ - self._set_label(self.strategy_msg)\n\ dots = self._surrounding_dots(turtle)\n\ - for i in range(6):\n\ + for i in range(6): # search for an edge\n\ if self._dots[dots[i]].type is None:\n\ self._orientation = i\n\ return self._dot_to_grid(dots[i])\n\ - dots_ordered_by_weight = self._ordered_weights(turtle)\n\ - for i in range(6):\n\ - self._orientation = dots.index(dots_ordered_by_weight[i])\n\ - if self._daylight_ahead(turtle):\n\ - return self._dot_to_grid(dots[self._orientation])\n\ - n = int(uniform(0, 6))\n\ - for i in range(6):\n\ + if self._daylight_ahead(turtle):\n\ + return self._dot_to_grid(dots[self._orientation])\n\ + n = int(uniform(0, 6)) # choose a random orientation\n\ + for i in range(6): # search for an opening\n\ if not self._dots[dots[(i + n) % 6]].type:\n\ self._orientation = (i + n) % 6\n\ return self._dot_to_grid(dots[(i + n) % 6])\n\ - self._orientation = (i + n) % 6\n\ return turtle\n' -EXPERT_MSG = _('turtle is looking for any open dot') +EXPERT_MSG = _('using a weight function') EXPERT_STRATEGY = 'def _turtle_strategy(self, turtle):\n\ self._set_label(self.strategy_msg)\n\ dots = self._surrounding_dots(turtle)\n\ @@ -187,7 +182,8 @@ class Game(): def reset_strategy(self): ''' Reload default strategy ''' - self.custom_strategy = self.strategies[2] + self.custom_strategy = EXPERT_STRATEGY + self.custom_msg = _('strategy from Journal') self.level = 3 def new_game(self, saved_state=None): |