Exemple #1
0
 def test_gfx(self):
     board = [[0, 8, 16, 2048], [0, 4, 32, 1024], [8192, 2, 64, 512],
              [4096, 0, 128, 256]]
     size = 4
     gfx = Gfx(size, size, fps=4)
     gfx.draw(board)
     sleep(2)
Exemple #2
0
    def test_gfx(self):
        my_grid = Grid()
        my_gfx = Gfx(fps=4)
        my_agent = Agent()
        my_agent.set_grid(my_grid)
        for i in range(15):
            r = random.randint(0, 2)
            relative_direction = (r - 1) * 90
            my_agent.move(relative_direction)

            my_gfx.draw(my_grid, my_agent)
Exemple #3
0
    def __init__(self):
        arg_parser = argparse.ArgumentParser()
        arg_parser.add_argument(
            '--disable-gfx',
            nargs='?',
            dest='disable_gfx',
            const=True,
            required=False,
            default=False
        )
        arg_parser.add_argument(
            '--print-execution-time',
            nargs='?',
            dest='print_execution_time',
            help='At the end of the run, print the execution time',
            const=True,
            required=False,
            default=False
        )
        arg_parser.add_argument(
            '--max-depth',
            dest='max_depth',
            type=int,
            choices=[2, 3, 4],
            required=False,
            default=3
        )
        args = arg_parser.parse_args()

        if args.disable_gfx:
            from board_printer import BoardPrinter
            self.gfx = BoardPrinter()
        else:
            from gfx import Gfx
            self.gfx = Gfx(grid_width=self.size, grid_height=self.size, fps=30.0)

        Node.max_depth = args.max_depth

        if args.print_execution_time:
            self.start_time = time.time()

        self.run()

        if args.print_execution_time:
            print "execution time: %s seconds" % (time.time() - self.start_time)
Exemple #4
0
    def __init__(self):
        arg_parser = argparse.ArgumentParser()
        arg_parser.add_argument('--disable-gfx',
                                nargs='?',
                                dest='disable_gfx',
                                const=True,
                                required=False,
                                default=False)
        arg_parser.add_argument(
            '--print-execution-time',
            nargs='?',
            dest='print_execution_time',
            help='At the end of the run, print the execution time',
            const=True,
            required=False,
            default=False)
        arg_parser.add_argument('--max-depth',
                                dest='max_depth',
                                type=int,
                                choices=[2, 3, 4],
                                required=False,
                                default=3)
        args = arg_parser.parse_args()

        if args.disable_gfx:
            from board_printer import BoardPrinter
            self.gfx = BoardPrinter()
        else:
            from gfx import Gfx
            self.gfx = Gfx(grid_width=self.size,
                           grid_height=self.size,
                           fps=30.0)

        Node.max_depth = args.max_depth

        if args.print_execution_time:
            self.start_time = time.time()

        self.run()

        if args.print_execution_time:
            print "execution time: %s seconds" % (time.time() -
                                                  self.start_time)
Exemple #5
0
class Main(object):
    size = 4

    def __init__(self):
        arg_parser = argparse.ArgumentParser()
        arg_parser.add_argument('--disable-gfx',
                                nargs='?',
                                dest='disable_gfx',
                                const=True,
                                required=False,
                                default=False)
        arg_parser.add_argument(
            '--print-execution-time',
            nargs='?',
            dest='print_execution_time',
            help='At the end of the run, print the execution time',
            const=True,
            required=False,
            default=False)
        arg_parser.add_argument('--max-depth',
                                dest='max_depth',
                                type=int,
                                choices=[2, 3, 4],
                                required=False,
                                default=3)
        args = arg_parser.parse_args()

        if args.disable_gfx:
            from board_printer import BoardPrinter
            self.gfx = BoardPrinter()
        else:
            from gfx import Gfx
            self.gfx = Gfx(grid_width=self.size,
                           grid_height=self.size,
                           fps=30.0)

        Node.max_depth = args.max_depth

        if args.print_execution_time:
            self.start_time = time.time()

        self.run()

        if args.print_execution_time:
            print "execution time: %s seconds" % (time.time() -
                                                  self.start_time)

    def run(self):
        board = Board(size=self.size)
        board.place_new_value_randomly()

        current_node = Node(board=board)
        for x in xrange(10000):
            if self.gfx is not None:
                self.gfx.draw(current_node.board.board_values)

            expected_heuristic_value, next_node = current_node.expectimax_max()
            if next_node is None:
                print
                print 'game over'
                print current_node.board
                print x, 'moves'
                break
            else:
                current_node = next_node
            current_node.board.place_new_value_randomly()
Exemple #6
0
    print "File relay non trovato..."
    AtomicWrite.writeFile('/tmp/presetTXTB.txt', ';')


if not os.path.isfile('/tmp/tx.txt'):
    print "File relay non trovato..."
    AtomicWrite.writeFile('/tmp/tx.txt', '')


def getFileContent(filename):
    txt = open(filename)
    return txt.read()

rg16080b = RG16080B()
#display = Display("dummy")
mygfx = Gfx()

while True:

    mygfx.clear()

    ### ricavo i dati
    band = getFileContent("/tmp/band.txt")
    relay = getFileContent("/tmp/relay.txt")
    presetA = getFileContent("/tmp/presetA.txt")
    presetTXTA = getFileContent("/tmp/presetTXTA.txt")
    presetTXTB = getFileContent("/tmp/presetTXTB.txt")
    tx = getFileContent("/tmp/tx.txt")

    ### stampo a schermo
    mygfx.writeText(5,0,"BANDA: " + band)
Exemple #7
0
    def __init__(self):
        arg_parser = argparse.ArgumentParser()
        arg_parser.add_argument('-i',
                                '--input',
                                dest='filename',
                                type=str,
                                help='The name of the input file',
                                required=True)
        arg_parser.add_argument('--mode',
                                dest='mode',
                                type=str,
                                choices=['astar', 'bfs', 'dfs'],
                                required=False,
                                default="astar")
        arg_parser.add_argument('--fps',
                                dest='fps',
                                type=float,
                                required=False,
                                default=16.0)
        arg_parser.add_argument(
            '--draw-every',
            dest='draw_every',
            help=
            'Use this argument to skip frames when visualizing large and complex problems',
            type=int,
            required=False,
            default=1)
        arg_parser.add_argument('--disable-gfx',
                                nargs='?',
                                dest='disable_gfx',
                                const=True,
                                required=False,
                                default=False)
        arg_parser.add_argument(
            '--print-execution-time',
            nargs='?',
            dest='print_execution_time',
            help=
            'At the end of the run, print the execution time of the A* algorithm. Useful for'
            ' testing the performance of the algorithm while gfx is disabled.',
            const=True,
            required=False,
            default=False)
        arg_parser.add_argument(
            '--sleep-afterwards',
            nargs='?',
            dest='sleep_afterwards',
            help=
            'At the end of the run, sleep for a couple of seconds. This gives you time to'
            ' take a screenshot of the solution, for example',
            const=True,
            required=False,
            default=False)
        args = arg_parser.parse_args()
        self.sleep_afterwards = args.sleep_afterwards

        if args.mode == 'bfs':
            CspNode.H_MULTIPLIER = 0
        elif args.mode == 'dfs':
            CspNode.H_MULTIPLIER = 0
            CspNode.ARC_COST_MULTIPLIER = 0

        f = open(args.filename)
        lines = []
        for line in f:
            lines.append(line.strip())
        f.close()

        num_cols, num_rows, row_segments, col_segments = self.parse_lines(
            lines)

        # initialize constraint network
        self.constraint_network = NgConstraintNetwork(
            num_cols=num_cols,
            num_rows=num_rows,
            row_segments=row_segments,
            col_segments=col_segments)

        if not args.disable_gfx:
            from gfx import Gfx
            self.gfx = Gfx(grid_width=num_cols,
                           grid_height=num_rows,
                           fps=args.fps)

        self.a_star = AStar(
            draw=self.gfx.draw if not args.disable_gfx else lambda _: 0,
            disable_gfx=args.disable_gfx,
            draw_every=args.draw_every,
            print_path=False)

        if args.print_execution_time:
            self.start_time = time.time()

        self.run()

        if args.print_execution_time:
            print "execution time: %s seconds" % (time.time() -
                                                  self.start_time)
Exemple #8
0
 def test_gfx(self):
     board = [[0, 8, 16, 2048], [0, 4, 32, 1024], [8192, 2, 64, 512], [4096, 0, 128, 256]]
     size = 4
     gfx = Gfx(size, size, fps=4)
     gfx.draw(board)
     sleep(2)
Exemple #9
0

from rg16080b import RG16080B
from gfx import Gfx

rg16080b = RG16080B()

mygfx = Gfx()
count = 0
while True:

    count += 1

    #mygfx.setAllWhite()

    #data = mygfx.getData()
#       for i in range(0,160*80):
#               y = i / 160
#               x = i % 160
#               if data[i] == "1":
#                       display.setPixel(y,x,True)

    mygfx.writeText(5,5,"test");

    #mygfx.writeText(5,37,str(count))

    data = mygfx.getData()

    rg16080b.writePixels(data)
    #display.writePng()
    ### attendo
Exemple #10
0
    def __init__(self):
        arg_parser = argparse.ArgumentParser()
        arg_parser.add_argument('-i',
                                '--input',
                                dest='filename',
                                type=str,
                                help='The name of the input file',
                                required=True)
        arg_parser.add_argument('--mode',
                                dest='mode',
                                type=str,
                                choices=['astar', 'bfs', 'dfs'],
                                required=False,
                                default="astar")
        arg_parser.add_argument(
            '-k',
            '--num-colors',
            dest='num_colors',
            type=int,
            choices=[2, 3, 4, 5, 6, 7, 8],
            required=True,
        )
        arg_parser.add_argument('--fps',
                                dest='fps',
                                type=float,
                                required=False,
                                default=16.0)
        arg_parser.add_argument(
            '--draw-every',
            dest='draw_every',
            help=
            'Use this argument to skip frames when visualizing large and complex problems',
            type=int,
            required=False,
            default=1)
        arg_parser.add_argument('--disable-gfx',
                                nargs='?',
                                dest='disable_gfx',
                                const=True,
                                required=False,
                                default=False)

        arg_parser.add_argument(
            '--print-execution-time',
            nargs='?',
            dest='print_execution_time',
            help=
            'At the end of the run, print the execution time of the A* algorithm. Useful for'
            ' testing the performance of the algorithm while gfx is disabled.',
            const=True,
            required=False,
            default=False)
        args = arg_parser.parse_args()

        if args.mode == 'bfs':
            VcCspNode.H_MULTIPLIER = 0
        elif args.mode == 'dfs':
            VcCspNode.H_MULTIPLIER = 0
            VcCspNode.ARC_COST_MULTIPLIER = 0

        f = open(args.filename)
        lines = []
        for line in f:
            lines.append(line.strip())
        f.close()

        num_vertices, num_edges, vertices, edges = self.parse_lines(lines)

        # initialize constraint network
        initial_domain = range(args.num_colors)
        self.constraint_network = VertexColorConstraintNetwork(
            vertices=vertices, edges=edges, initial_domain=initial_domain)

        if not args.disable_gfx:
            from gfx import Gfx
            self.gfx = Gfx(fps=args.fps)

        self.a_star = AStar(
            draw=self.gfx.draw if not args.disable_gfx else lambda _: 0,
            disable_gfx=args.disable_gfx,
            draw_every=args.draw_every,
            print_path=False)

        if args.print_execution_time:
            self.start_time = time.time()

        self.run()

        if args.print_execution_time:
            print "execution time: %s seconds" % (time.time() -
                                                  self.start_time)
Exemple #11
0
	AtomicWrite.writeFile('/tmp/presetA.txt', '0000000000000000')
if not os.path.isfile('/tmp/presetTXTA.txt'):
	print "File relay non trovato..."
	AtomicWrite.writeFile('/tmp/presetTXTA.txt', ';')
if not os.path.isfile('/tmp/tx.txt'):
	print "File relay non trovato..."
	AtomicWrite.writeFile('/tmp/tx.txt', '')


def getFileContent(filename):
        txt = open(filename)
        return txt.read()

####rg16080b = RG16080B()
#display = Display("dummy")
mygfx = Gfx()

while True:

	mygfx.clear()

	### ricavo i dati
	band = getFileContent("/tmp/band.txt")
	relay = getFileContent("/tmp/relay.txt")
	presetA = getFileContent("/tmp/presetA.txt")
	presetTXTA = getFileContent("/tmp/presetTXTA.txt")
	tx = getFileContent("/tmp/tx.txt")

	### stampo a schermo
	mygfx.writeText(5,0,"BANDA: " + band)
	mygfx.writeText(5,15,"RELAY: " + relay)
Exemple #12
0
class Main(object):
    size = 4

    def __init__(self):
        arg_parser = argparse.ArgumentParser()
        arg_parser.add_argument(
            '--disable-gfx',
            nargs='?',
            dest='disable_gfx',
            const=True,
            required=False,
            default=False
        )
        arg_parser.add_argument(
            '--print-execution-time',
            nargs='?',
            dest='print_execution_time',
            help='At the end of the run, print the execution time',
            const=True,
            required=False,
            default=False
        )
        arg_parser.add_argument(
            '--max-depth',
            dest='max_depth',
            type=int,
            choices=[2, 3, 4],
            required=False,
            default=3
        )
        args = arg_parser.parse_args()

        if args.disable_gfx:
            from board_printer import BoardPrinter
            self.gfx = BoardPrinter()
        else:
            from gfx import Gfx
            self.gfx = Gfx(grid_width=self.size, grid_height=self.size, fps=30.0)

        Node.max_depth = args.max_depth

        if args.print_execution_time:
            self.start_time = time.time()

        self.run()

        if args.print_execution_time:
            print "execution time: %s seconds" % (time.time() - self.start_time)

    def run(self):
        board = Board(size=self.size)
        board.place_new_value_randomly()

        current_node = Node(board=board)
        for x in xrange(10000):
            if self.gfx is not None:
                self.gfx.draw(current_node.board.board_values)

            expected_heuristic_value, next_node = current_node.expectimax_max()
            if next_node is None:
                print
                print 'game over'
                print current_node.board
                print x, 'moves'
                break
            else:
                current_node = next_node
            current_node.board.place_new_value_randomly()
Exemple #13
0
    def __init__(self):
        """
        Parse command line arguments, read input file, set up board and call run()
        """

        arg_parser = argparse.ArgumentParser()
        arg_parser.add_argument(
            '-i',
            '--input',
            dest='filename',
            type=str,
            help='The name of the input file',
            required=True
        )
        arg_parser.add_argument(
            '--mode',
            dest='mode',
            type=str,
            choices=['astar', 'bfs', 'dfs'],
            required=False,
            default="astar"
        )
        arg_parser.add_argument(
            '--fps',
            dest='fps',
            type=float,
            required=False,
            default=16.0
        )
        arg_parser.add_argument(
            '--draw-every',
            dest='draw_every',
            help='Use this argument to skip frames when visualizing large and complex problems',
            type=int,
            required=False,
            default=1
        )
        arg_parser.add_argument(
            '--disable-gfx',
            nargs='?',
            dest='disable_gfx',
            const=True,
            required=False,
            default=False
        )
        arg_parser.add_argument(
            '--print-path',
            nargs='?',
            dest='print_path',
            help='If a solution is found, print the backtracked nodes that led to the solution',
            const=True,
            required=False,
            default=False
        )
        arg_parser.add_argument(
            '--print-execution-time',
            nargs='?',
            dest='print_execution_time',
            help='At the end of the run, print the execution time of the A* algorithm. Useful for'
                 ' testing the performance of the algorithm while gfx is disabled.',
            const=True,
            required=False,
            default=False
        )
        args = arg_parser.parse_args()

        if args.mode == 'bfs':
            NavNode.H_MULTIPLIER = 0
        elif args.mode == 'dfs':
            NavNode.H_MULTIPLIER = 0
            NavNode.ARC_COST_MULTIPLIER = 0

        f = open(args.filename)
        lines = []
        for line in f:
            lines.append(line.strip())
        f.close()

        self.disable_gfx = args.disable_gfx
        self.print_path = args.print_path
        self.print_execution_time = args.print_execution_time
        self.draw_every = args.draw_every

        dimensions, start, goal, barriers = self.parse_lines(lines)
        self.board = Board(dimensions, start, goal, barriers)
        NavNode.board = self.board

        if not self.disable_gfx:
            from gfx import Gfx
            self.gfx = Gfx(board=self.board, fps=args.fps)

        if self.print_execution_time:
            self.start_time = time.time()
        self.run()
        if self.print_execution_time:
            print "execution time: %s seconds" % (time.time() - self.start_time)