Exemple #1
0
def main():
    maxx = maxy = 10

    board = arena.Arena(maxx, maxy)

    board.update( ((3, 5), 20) )

    dna = [("MOV", 1),          # 0 Move one ahead
           ("TUR", 1),          # 1 Turn right
           ("SEN", 1),          # 2 Sense ahead
           ("JGZ", 6),          # 3 Found food!
           ("MOV", 1),          # 4 Move one ahead
           ("JMP", 0),          # 5 Repeat
           ("EAT", 1)           # 6 Eat the food found
           ]

    bacterium = organism.Organism((5, 5), organism.SOUTH, dna)

    orglist = [bacterium]

    retval = None

    quit = False
    tick = 0

    while not quit:
        for current_org in orglist:
            retval = current_org.run(board.arena)
            if retval:
                board.update( (retval[0], retval[1]) )
        prompt = "(tick: %d)> " % tick
        quit = raw_input(prompt)
        tick += 1
Exemple #2
0
 def test_inventory(self):
     an_arena = arena.Arena(12, 12)
     snap = world.WorldSnapshot(an_arena)
     test_loc = an_arena.get_location(spatial.Point(1, 1))
     test_pc = character.Pc()
     test_loc.additem(test_pc)
     self.assertEquals(test_pc.inventory,
                       queries.inventory(snap, test_pc.id))
Exemple #3
0
 def reset(self):
     self.episode += 1
     self.main_arena = arena.Arena(s.arena_size, self.renders)
     self.steps = 0
     self.score = 0
     self.merge_delay = 5
     self.merge_counter = 0
     return self.main_arena.state()
Exemple #4
0
    def __init__(self):
        self.renders = False
        if self.renders:
            pygame.init()
            pygame.display.set_caption("tetris")
            self.screen = pygame.display.set_mode(s.screen_size)

        self.main_arena = arena.Arena(s.arena_size, renders=self.renders)
        self.steps = 0
        self.score = 0
        self.merge_delay = 5
        self.merge_counter = 0
        self.episode = 0
Exemple #5
0
def main():
    pygame.init()
    pygame.display.set_caption("tetris")
    screen = pygame.display.set_mode(s.screen_size)
    running = True
    step = 0
    score = 0
    merge_delay = 20
    merge_counter = 0

    main_arena = arena.Arena(s.arena_size, renders=True)
    while running:
        if step % 10 == 0:
            if main_arena.update_moving_blocks():
                merge_counter = 0
        if merge_counter > merge_delay:
            main_arena.check_block_merge()
            merge_counter = 0
        time.sleep(0.03)
        main_arena.render(screen)
        pygame.display.flip()
        screen.fill((220, 220, 220))
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_UP:
                    main_arena.rotate_block()
                if event.key == pygame.K_RIGHT:
                    main_arena.move_block_right()
                if event.key == pygame.K_LEFT:
                    main_arena.move_block_left()
                if event.key == pygame.K_DOWN:
                    main_arena.place_block()
                if event.key == pygame.K_0:
                    pass
                    # main_arena.add_moving_block()
        step += 1
        merge_counter += 1
        running = main_arena.running
 def test_main(self):
     """Test application runs without issue on two example files."""
     file1 = '../examples/ww/simple.py'
     file2 = '../examples/ww/random_move.py'
     arena.Arena(["arena", file1, file2, '-n 1']).run()
Exemple #7
0
 def setUp(self):
     self.unit1 = mock.Mock()
     self.unit2 = mock.Mock()
     self.ai_func = mock.Mock()
     self.arena = arena.Arena(self.unit1, self.unit2, self.ai_func)
Exemple #8
0
    path1 = argv[1]
    path2 = argv[2]

    with open(path1, 'r') as f:
        prog1 = COINFLIP.CP_Parser.parse_code(f.read())

    with open(path2, 'r') as f:
        prog2 = COINFLIP.CP_Parser.parse_code(f.read())

    x_size, y_size = 20, 20
    bots_par_team = int(argv[3])
    smap = [[1] * x_size] + [[1] + [0] *
                             (x_size - 2) + [1]] * (y_size - 2) + [[1] * x_size
                                                                   ]
    arena = arena.Arena(smap)

    progs = {'tom': prog1, 'jerry': prog2}

    bots = []
    used_pos = {}

    for i in xrange(bots_par_team):
        for player in progs.keys():
            pos = None
            while pos == None or pos in used_pos:
                pos = (randint(1, x_size - 2), randint(1, y_size - 2))
            orient = randint(0, 3) * 90
            bots.append(
                bot.EvalBot(progs[player],
                            player,
Exemple #9
0
from arena import Continuous, Discrete, Category

space = [
    Category(['up', 'down', 'left', 'right'], 'x'),
    Discrete(4, 7, 'y'),
    Continuous(-np.inf, 3.0, 'z'),
    Continuous(np.inf, -np.inf, 'k'),
    Discrete(np.inf, 5.8),
    Discrete(-np.inf, -9, step=3.16889),
    Discrete(-np.inf, np.inf)
]

x = [a.sample() for a in space]
y = [a.sample() for a in space]

grl = arena.Arena('grl-arena')

agent = arena.Actor('agent')

mdp = arena.MDP(
    name='ergodic-mdp',
    control_space=[arena.Sequence(range(2))],
    state_space=[arena.Sequence(range(4))]
)

pomdp = arena.POMDP(
    name='ergodic-pomdp',
    control_space=[arena.Sequence(range(2))],
    state_space=[arena.Sequence(range(4))],
    feedback_space=[arena.Sequence(range(6))]
)
Exemple #10
0
import arena

arena.Arena()
Exemple #11
0
			File format:
				One monster definition per line
				Fields are space-delimited
				First field is monster type (string matching class name)
				Second field is monster subid (distinguish in output)
				Beyond that should be pairs of elements such that the first is the keyword and the second is the value
					Class Constructors are required to properly convert strings to the intended data type for such inputs
		"""
        monsterGroup.AddMonster(MakeMonsterFromString(line, battlefield,
                                                      monsterGroup),
                                ephemeral=False)
    battlefield.AddGroups(monsterGroup)


"""
	Then basically want a statistician class to take an Arena and fight it # times, tracking which group is winning and make nice outputs based on that
	Ideally the statistician can listen to all the groups and/or monsters individually to track block/health/damage give/take too
"""

if __name__ == '__main__':
    args = parse(build())
    # Set seed as necssary
    if args.seed is not None:
        arena.global_rng.seed(args.seed)
    # Make groups
    colliseum = arena.Arena(ID="SpireArena")
    for combat_group in args.group:
        with open(combat_group, 'r') as f:
            MakeMonsterGroupFromFile(f, colliseum)
    winner = colliseum.Brawl(args.max_turns)
Exemple #12
0
args1 = dict({'numMCTSSims': 50, 'cpuct': 1.0})
mcts1 = MCTS(game, neural_net_mister_x, args1)
n1p = lambda x, y: np.argmax(mcts1.get_action_prob(x, y, temp=0))
"""human_vs_cpu = False
if human_vs_cpu:
    player2 = human_player
else:
    n2 = NNet(game)
    #n2.load_checkpoint('')
    args2 = dict({'numMCTSSims': 50, 'cpuct': 1.0})
    mcts2 = MCTS(game, n2, args2)
    n2p = lambda x: np.argmax(mcts2.get_action_prob(x, temp=0))

    player2 = n2p  # Player 2 is neural network if it's cpu vs cpu.
"""
neural_net_detectives = []
neural_net_detective = NNet(game, game.detectives[0])
# n2.load_checkpoint('')
args2 = dict({'numMCTSSims': 50, 'cpuct': 1.0})
mcts2 = MCTS(game, neural_net_detective, args2)
n2p = lambda x, y: np.argmax(mcts2.get_action_prob(x, y, temp=0))
for i in range(number_of_detectives):
    game.detectives[i].neural_net = neural_net_detective
    neural_net_detectives.append(n2p)

arena = arena.Arena(n1p, neural_net_detectives, game, display=game.display)

#print(arena.play_games(2, verbose=True))
print(arena.play_game(verbose=True))
Exemple #13
0
 def test_order_schema(self):
     rl = arena.Arena()
     rl.order_schema([[0, 0], [0, 0]])
Exemple #14
0
 def __init__(self):
     an_arena = arena.Arena(12, 12)
     self.current = WorldSnapshot(an_arena)
     self.bestiary = bestiary.Bestiary()
     self.genMobs = self.bestiary.get_random_mobs
Exemple #15
0
def printstats(profiler):
    s = StringIO.StringIO()
    sortby = 'cumulative'
    ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
    ps.print_stats()
    print s.getvalue()


def getcycletime(i):
    return Fraction(1, 2) if i % 2 == 0 else Fraction(1, 3)


w = 8
h = 8
a = arena.Arena(h, w)
players = []

filenames = []
for i in range(1, len(sys.argv)):
    arg = sys.argv[i]
    if arg == 'debug':
        debug = 1
    elif arg == 'profile':
        profiler = 1
    else:
        filenames.append(os.path.normpath(arg))

pr = None
if profiler:
    pr = cProfile.Profile()