def __init__(self, pilite):
        super(GolThread, self).__init__(name='GameOfLive')

        self._run = True

        self.gol = GameOfLive(14, 9)

        self.gol.board[3][3:6] = [1, 1, 1]

        self.pilite = pilite
class GolThread(threading.Thread):
    def __init__(self, pilite):
        super(GolThread, self).__init__(name='GameOfLive')

        self._run = True

        self.gol = GameOfLive(14, 9)

        self.gol.board[3][3:6] = [1, 1, 1]

        self.pilite = pilite

    def stop(self):
        self._run = False
        self.join()

    def run(self):
        time.sleep(10)
        #self.serialbuffer += '$$$SPEED100\r'
        self.pilite.keyEntry(d=1, S='A', i=None, P=None, s=None, v=None, V=None, W=None)
        time.sleep(2)
        #self.pilite.keyEntry(d=1, S='$$$SPEED10\r', i=None, P=None, s=None, v=None, V=None, W=None)
        #time.sleep(5)
        #self.pilite.keyEntry(d=1, S='Arnold', i=None, P=None, s=None, v=None, V=None, W=None)
        #time.sleep(5)
        #self.pilite.keyEntry(d=1, S='$$$ALL,ON\r', i=None, P=None, s=None, v=None, V=None, W=None)
        self.pilite.keyEntry(d=1, S='$$$F000000000000000000000000000000111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\r', i=None, P=None, s=None, v=None, V=None, W=None)
        time.sleep(5)

        while self._run:
            print "Step!"
            cmd = '$$$F'
            for row in self.gol.board:
                cmd += ''.join([ str(i) for i in row ])
            print "Will send '{}' with length {}".format(cmd, len(cmd))
            self.pilite.keyEntry(d=1, S=(cmd+'\r'), i=None, P=None, s=None, v=None, V=None, W=None)
            #self.serialbuffer += cmd+'\r'

            self.gol.calculatenextboard()

            self._run=False
            time.sleep(5)
Пример #3
0
# -*- coding: utf8 -*-

from gol import GameOfLive

import serial
import time
import random
import logging

if __name__ == '__main__':
    logging.basicConfig(level='DEBUG')

    x, y = (14, 9)
    gol = GameOfLive(x, y)

    #for i in range(random.randint(x*y/10, x*y/4)):
        #gol.board[random.randrange(x)][random.randrange(y)] = 1

    gol.board[0][0:3] = [0, 1, 0]
    gol.board[1][0:3] = [0, 0, 1]
    gol.board[2][0:3] = [1, 1, 1]
    #gol.board[3][0:5] = [0, 0, 1, 1]


    s = serial.Serial('/dev/ttyAMA0', baudrate=9600)
    s.setTimeout(1)

    s.write('$$$ALL,OFF\r')

    #starttime = time.time()