El fichero olvidado, como siempre XD
> iepe!
>
> Aquí os dejo un pequeño sistema para poder comunicarse con el servidor
> RealTimeBattle de una manera bastante cómoda en python, una especie de
> esqueleto.
>
> Si lo ejecutais en el RTB os dará pythonizados todos los comandos
> recibidos y realtimebattletizará todos los argumentos pythonizados.
>
> Animo!
>
> PD: hay alguien que se anime en publicar en la wiki todo esto del rtb?
#!/usr/bin/env python
#from signal import signal, SIGUSR1
from sys import stdin, stdout
def trans(obj, typ):
'''trans(object, type) -> type(object), object if exception.'''
try:
obj = typ(obj)
except ValueError:
pass
return obj
class Pipe(object):
'''Pipe() -> pipe for stdin and stdout with formatting.'''
def send(self, **kwargs):
'''send(**kwargs) -> write to stdout formated kwargs.
Keys will be writed as commands and value/s as args,
transforming them both to strings.'''
for k, v in kwargs.items():
if hasattr(v, '__iter__'):
v = ' '.join(map(lambda i: str(i), v))
stdout.write('%s %s \n' % (k,v))
# stdout.flush()
def recv(self):
'''recv() -> read a line from stdin and return a tuple
with the command and his arguments as list.'''
r = [ trans(word, float) for word in stdin.readline().strip().split() ]
return r[0], r[1:]
class Robot(object):
'''Robot() -> RealTimeBattle robot.'''
def __init__(self):
self.pipe = Pipe()
def is_quitting(self):
return False
def process(self):
print 'Print received ' + str(self.pipe.recv())
if __name__ == '__main__':
robot = Robot()
robot.pipe.send(RobotOption=(3, 0))
robot.pipe.send(RobotOption=(1, 1))
while not robot.is_quitting():
robot.process()
_______________________________________________
HackMeeting mailing list
[email protected]
https://listas.sindominio.net/mailman/listinfo/hackmeeting