示例#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)
示例#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)
示例#3
0
文件: main.py 项目: afcarl/it3105
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()
示例#4
0
文件: test_gfx.py 项目: iver56/it3105
 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)
示例#5
0
文件: main.py 项目: iver56/it3105
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()