class Thing:
- def __init__(self, position):
+ def __init__(self, type_, position):
+ self.type = type_
self.position = position
self.task = Task('wait')
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)
'x.X.x\n'+\
'x...x\n'+\
'xxxxx'
- self.things = [Thing(position=[3, 3]), Thing([1, 1])]
+ self.things = [Thing('human', [3, 3]), Thing('monster', [1, 1])]
self.player_i = 0
self.player = self.things[self.player_i]
self.send_all('NEW_TURN ' + str(self.world.turn))
self.send_all('MAP_SIZE ' + self.stringify_yx(self.world.map_size))
self.send_all('TERRAIN\n' + self.world.map_)
- self.send_all('POSITION ' + self.stringify_yx(self.world.player.position))
+ for thing in self.world.things:
+ self.send_all('THING TYPE:' + thing.type + ' '
+ + self.stringify_yx(thing.position))
def cmd_fib(self, tokens, connection_id):
"""Reply with n-th Fibonacci numbers, n taken from tokens[1:].
self.send_all('NEW_TURN ' + str(self.world.turn))
self.send_all('MAP_SIZE ' + self.stringify_yx(self.world.map_size))
self.send_all('TERRAIN\n' + self.world.map_)
- self.send_all('POSITION ' + self.stringify_yx(self.world.player.position))
+ for thing in self.world.things:
+ self.send_all('THING TYPE:' + thing.type + ' '
+ + self.stringify_yx(thing.position))
self.pool_result = self.pool.map_async(fib, (35, 35))
def cmd_get_turn(self, connection_id):
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)