home · contact · privacy
Add basic movement AI test, extend move command directions.
authorChristian Heller <c.heller@plomlompom.de>
Thu, 24 Aug 2017 22:39:09 +0000 (00:39 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Thu, 24 Aug 2017 22:39:09 +0000 (00:39 +0200)
server.py

index e8bca6abf402cb0ea9bef2d175c2f12d454dda7b..aa8b1c3aab7b1bf8b85fc3930d5de17d997ccd12 100755 (executable)
--- a/server.py
+++ b/server.py
@@ -103,9 +103,18 @@ class Thing:
             self.position[0] -= 1
         elif direction == 'DOWN':
             self.position[0] += 1
+        elif direction == 'RIGHT':
+            self.position[1] += 1
+        elif direction == 'LEFT':
+            self.position[1] -= 1
 
     def decide_task(self):
-        self.set_task('wait')
+        if self.position[1] > 1:
+            self.set_task('move', 'LEFT')
+        elif self.position[1] < 3:
+            self.set_task('move', 'RIGHT')
+        else:
+            self.set_task('wait')
 
     def set_task(self, task, *args, **kwargs):
         self.task = Task(task, args, kwargs)
@@ -258,8 +267,9 @@ class CommandHandler:
 
     def cmd_move(self, direction, connection_id):
         """Set player task to 'move' with direction arg, finish player turn."""
-        if not direction in {'UP', 'DOWN'}:
-            raise ArgumentError('MOVE ARGUMENT MUST BE "UP" or "DOWN"')
+        if not direction in {'UP', 'DOWN', 'RIGHT', 'LEFT'}:
+            raise ArgumentError('MOVE ARGUMENT MUST BE ONE OF: '
+                                'UP, DOWN, RIGHT, LEFT')
         self.world.player.set_task('move', direction=direction)
         self.proceed_to_next_player_turn(connection_id)