Esempio n. 1
0
def evaluate(fnn,iteration=5,isScreen=False):
  global zelda_level,zelda_game,now_zelda_game,red,blue,green,scorelimit,mapgenerator,nowlevel
  if __name__ == "__main__":
    from vgdl.core import VGDLParser
    TotalScore = 0.
    for i in range(iteration):
      redCount = 0
      greenCount = 0
      blueCount = 0
      thislevel = mapgenerator.generate()
      nowlevel = thislevel
      zelda_level_list = list(thislevel)
      #link
      for i in range(99999):
        if(thislevel.find(' ')):
          randIndex = int(random.uniform(0, len(zelda_level_list)))
          if(zelda_level_list[randIndex] == ' '):
            zelda_level_list[randIndex] = 'L'
            break
        else:
          break
      #red
      for i in range(99999):
        if(thislevel.find(' ')):
          randIndex = int(random.uniform(0, len(zelda_level_list)))
          if(zelda_level_list[randIndex] == ' '):
            zelda_level_list[randIndex] = 'R'
            redCount+=1
            if(redCount >= red):
              break
        else:
          break
      #green
      for i in range(99999):
        if(thislevel.find(' ')):
          randIndex = int(random.uniform(0, len(zelda_level_list)))
          if(zelda_level_list[randIndex] == ' '):
            zelda_level_list[randIndex] = 'G'
            greenCount+=1
            if(greenCount >= green):
              break
        else:
          break
      #blue
      for i in range(99999):
        if(thislevel.find(' ')):
          randIndex = int(random.uniform(0, len(zelda_level_list)))
          if(zelda_level_list[randIndex] == ' '):
            zelda_level_list[randIndex] = 'B'
            blueCount+=1
            if(blueCount >= blue):
              break
        else:
          break
      zelda_this_level = ''.join(zelda_level_list)
      print now_zelda_game
      os.system('read')
      game = VGDLParser.playGame(now_zelda_game, zelda_this_level, fnn = fnn , isScreen=True)
      TotalScore += (game.score/float(scorelimit))
    return TotalScore/float(iteration)
def planActLoop(rleCreateFunc,
                filename,
                max_actions_per_plan,
                planning_steps,
                defaultPolicyMaxSteps,
                playback=False):

    rle = rleCreateFunc(OBSERVATION_GLOBAL)
    game, level = defInputGame(filename)
    outdim = rle.outdim
    print rle.show()

    terminal = rle._isDone()[0]

    i = 0
    finalStates = [rle._game.getFullState()]
    while not terminal:
        mcts = Basic_MCTS(existing_rle=rle, game=game, level=level)
        mcts.startTrainingPhase(planning_steps, defaultPolicyMaxSteps, rle)
        # mcts.debug(mcts.rle, output=True, numActions=3)
        # break
        actions = mcts.getBestActionsForPlayout((1, 0, 0))

        # if len(actions)<max_actions_per_plan:
        # 	print "We only computed", len(actions), "actions."

        new_state = rle._getSensors()
        terminal = rle._isDone()[0]

        for j in range(min(len(actions), max_actions_per_plan)):
            if actions[j] is not None and not terminal:
                print ACTIONS[actions[j]]
                res = rle.step(actions[j])
                new_state = res["observation"]
                terminal = not res['pcontinue']
                print rle.show()
                finalStates.append(rle._game.getFullState())

        i += 1

    if playback:
        from vgdl.core import VGDLParser
        VGDLParser.playGame(game, level, finalStates)
        embed()
Esempio n. 3
0
def planActLoop(rleCreateFunc, max_actions_per_plan, planning_steps, defaultPolicyMaxSteps, playback=False):
	
	rle = rleCreateFunc(OBSERVATION_GLOBAL)

	outdim = rle.outdim

	rle.show()
	
	terminal = rle._isDone()[0]
	
	i=0
	finalStates = [rle._game.getFullState()]
	while not terminal:
		mcts = Basic_MCTS(existing_rle=rle)
		mcts.startTrainingPhase(planning_steps, defaultPolicyMaxSteps, rle)
		# mcts.debug(mcts.rle, output=True, numActions=3)
		# break
		actions = mcts.getBestActionsForPlayout()

		# if len(actions)<max_actions_per_plan:
		# 	print "We only computed", len(actions), "actions."

		new_state = rle._getSensors()
		terminal = rle._isDone()[0]

		for j in range(min(len(actions), max_actions_per_plan)):
			if actions[j] is not None and not terminal:
				# dist = mcts.getManhattanDistanceComponents(new_state)
				print ACTIONS[actions[j]]
				res = rle.step(actions[j])
				new_state = res["observation"]
				terminal = not res['pcontinue']
				print rle.show()
				finalStates.append(rle._game.getFullState())

		i+=1

	if playback:
		from vgdl.core import VGDLParser
		from examples.gridphysics.simpleGame_randomNPC import box_level, push_game
		game = push_game
		level = box_level
		VGDLParser.playGame(game, level, finalStates)
Esempio n. 4
0
def load_game(module_str, level_str):
   
    module  = importlib.import_module(module_str)

    game = None    
    level = None
    
    for key in module.__dict__.keys():
        #print key
        if(key.endswith("game")):
            game = module.__dict__[key]
        if(key.endswith("level") and key == level_str):
            level = module.__dict__[key]
            
    if(level is None):
        return None
    #print game, level
    g = VGDLParser.playGame(game, level, headless = True, persist_movie = True, movie_dir = "./tmp/")
    #g.startGameExternalPlayer(headless = True, persist_movie = True)
    return g
Esempio n. 5
0
def load_game(module_str, level_str):

    module = importlib.import_module(module_str)

    game = None
    level = None

    for key in module.__dict__.keys():
        #print key
        if (key.endswith("game")):
            game = module.__dict__[key]
        if (key.endswith("level") and key == level_str):
            level = module.__dict__[key]

    if (level is None):
        return None
    #print game, level
    g = VGDLParser.playGame(game,
                            level,
                            headless=True,
                            persist_movie=True,
                            movie_dir="./tmp/")
    #g.startGameExternalPlayer(headless = True, persist_movie = True)
    return g
Esempio n. 6
0
        = > ice
        G > goal
        < > tvleft
        ^ > tvup
        
    SpriteSet         
        structure > Immovable
            goal  > color=GREEN
            tv    > Conveyor color=RED
                tvup    > orientation=UP
                tvleft  > orientation=LEFT
            ice   > color=WHITE
            wind  > Conveyor orientation=RIGHT strength=1                                         
        avatar   > RotatingAvatar

    TerminationSet
        SpriteCounter stype=goal limit=0 win=True
        
    InteractionSet
        goal avatar  > killSprite
        avatar wind  > windGust
        avatar tv    > attractGaze prob=1
        avatar ice   > slipForward prob=0.3
        avatar wall  > stepBack        
"""


if __name__ == "__main__":
    from vgdl.core import VGDLParser
    VGDLParser.playGame(stoch_game, stoch_level)
Esempio n. 7
0
        goal   > Immovable color=GREEN
        mana   > Resource color=LIGHTBLUE limit=3
        bullet > Missile color=RED singleton=True
        fire   > Spreader color=ORANGE spreadprob=0.25
        avatar > ShootAvatar ammo=mana stype=bullet
            
    InteractionSet
        mana avatar  > collectResource scoreChange=5
        mana avatar  > killSprite
        avatar wall  > stepBack
        goal avatar  > killSprite scoreChange=100
        avatar fire  > killSprite
        wall bullet  > killSprite scoreChange=1
        bullet wall  > transformTo stype=fire
        fire   wall  > killSprite
        fire   fire  > killSprite
        mana   fire  > killSprite
        
    TerminationSet
        SpriteCounter stype=avatar limit=0 win=False
        SpriteCounter stype=goal   limit=0 win=True
    
    LevelMapping
        G > goal
        . > mana        
"""

if __name__ == "__main__":
    from vgdl.core import VGDLParser
    VGDLParser.playGame(caster_game, caster_level)    
Esempio n. 8
0
        wall bullet > killSprite
        bullet EOS > killSprite
        tank wall > stepBack
        tank EOS > stepBack
        tank lift  > conveySprite
        
    LevelMapping
        a > otheravatar
        + > liftup
        - > pushdown
"""

tankwars_level = """
w                w           w
w   w       w                w
w                     w      w
w               w            w
w                            w
w                            w
w       w                    w
w                   w        w
w          www               w
w         wwwwww             w
w       wwwwwwww             w
wA     wwwwwwwwwwwww        aw
"""

if __name__ == "__main__":
    from vgdl.core import VGDLParser
    VGDLParser.playGame(tankwars_game, tankwars_level)
        
Esempio n. 9
0
w.wwww.ww.wwwwwwww.ww.wwww.w
w.wwww.ww.wwwwwwww.ww.wwww.w
w......ww....ww....ww......w
wwwwww.wwwww ww wwwww.wwwwww
wwwwww.wwwww ww wwwww.wwwwww
wwwwww.ww          ww.wwwwww
wwwwww.ww          ww.wwwwww
wwwwww.ww www  www ww.wwwwww
      .   ww1234ww   .      
wwwwww.ww wwwwwwww ww.wwwwww
wwwwww.ww          ww.wwwwww
wwwwww.ww          ww.wwwwww
wwwwww.ww wwwwwwww ww.wwwwww
wwwwww.ww wwwwwwww ww.wwwwww
w............ww............w
w.wwww.wwwww.ww.wwwww.wwww.w
w0wwww.wwwww.ww.wwwww.wwww0w
w...ww.......A........ww...w
www.ww.ww.wwwwwwww.ww.ww.www
www.ww.ww.wwwwwwww.ww.ww.www
w......ww....ww....ww......w
w.wwwwwwwwww.ww.wwwwwwwwww.w
w.wwwwwwwwww.ww.wwwwwwwwww.w
w..........................w
wwwwwwwwwwwwwwwwwwwwwwwwwwww
"""

if __name__ == "__main__":
    from vgdl.core import VGDLParser
    VGDLParser.playGame(pacman_game, pacman_level)
Esempio n. 10
0
        carcass scared > killSprite
        scared avatar  > transformTo stype=carcass
        scared carcass > transformTo stype=angry

    LevelMapping
        0 > scared

    TerminationSet
        SpriteCounter stype=scared win=True
        SpriteCounter stype=avatar win=False

"""

chase_level = """
wwwwwwwwwwwwwwwwwwwwwwww
wwww    w0  ww      0www
w     w w       ww    ww
w   0   0 ww  A www    w
w wwww wwwww    ww   www
w        w         0  ww
ww   w0     ww   www   w
ww    ww   wwww    w   w
www              w     w
wwwwww   0  wwwwww    ww
wwwwwwwwwwwwwwwwwwwwwwww
"""

if __name__ == "__main__":
    from vgdl.core import VGDLParser
    VGDLParser.playGame(chase_game, chase_level)
Esempio n. 11
0
consistent_corridor = """
wwwwwwwwwwwwww
w        wwwww
w   ww   wwwww
w m ww m wwwww
w wwwwww wwwww
w   ww   wwwww
w  mww wwwwwww
w      w    Gw
wwwwwwAw  mwww
w      w   www
w  mww w wwwww
w   ww   wwwww
w wwwwww wwwww
w   ww m wwwww
w  mww   wwwww
w        wwwww
wwwwwwwwwwwwww
"""

if __name__ == "__main__":
    from vgdl.core import VGDLParser
    from vgdl.examples.gridphysics.mazes.mazegames import polarmaze_game, maze_game
    VGDLParser.playGame(maze_game, maze_level_1)
    VGDLParser.playGame(maze_game, maze_level_2)
    VGDLParser.playGame(maze_game, maze_level_3)
    VGDLParser.playGame(polarmaze_game, corridor2)
    VGDLParser.playGame(polarmaze_game, office_layout_2)
    VGDLParser.playGame(polarmaze_game, office_layout)
Esempio n. 12
0
        b > butterfly
    InteractionSet
        dirt avatar > killSprite
        dirt sword  > killSprite
        diamond avatar > collectResource scoreChange=5
        diamond avatar > killSprite
        moving wall > stepBack
        moving boulder > stepBack
        avatar boulder > killIfFromAbove
        avatar butterfly > killSprite
        avatar crab > killSprite
        boulder dirt > stepBack
        boulder wall > stepBack
        boulder boulder > stepBack
        boulder diamond > stepBack
        enemy dirt > stepBack
        enemy diamond > stepBack
        crab butterfly > killSprite
        butterfly crab > transformTo stype=diamond scoreChange=1
        exitdoor avatar > killIfOtherHasMore resource=diamond limit=9 scoreChange=100

    TerminationSet
        SpriteCounter stype=avatar limit=0 win=False
        SpriteCounter stype=exitdoor limit=0 win=True

"""

if __name__ == "__main__":
    from vgdl.core import VGDLParser
    VGDLParser.playGame(boulderdash_game, boulderdash_level)
Esempio n. 13
0
                rightslow >     orientation=RIGHT
            fastbullet > speed=0.2  color=RED
                rightfast >     orientation=RIGHT
                downfast  >     orientation=DOWN  
        wall      > Immovable
        goal      > Immovable  color=GREEN
        
    InteractionSet
        goal   avatar > killSprite
        avatar bullet > killSprite
        avatar wall   > stepBack
        bullet EOS    > wrapAround
    
    TerminationSet
        SpriteCounter stype=goal   limit=0 win=True
        SpriteCounter stype=avatar limit=0 win=False
    
    LevelMapping
        ^ > upslow
        < > leftslow
        v > downslow
        - > rightslow
        = > rightfast
        V > downfast
        G > goal
"""

if __name__ == "__main__":
    from vgdl.core import VGDLParser
    VGDLParser.playGame(bullet_game, bullet_level)    
Esempio n. 14
0
BasicGame
    SpriteSet    
        structure > Immovable            
            goal  > color=GREEN
            marsh > color=BROWN
        gold  > Resource color=GOLD limit=11 # this limit is only used for visualizing progress
        moving >
            avatar > MovingAvatar            
            random > RandomNPC speed=1 cooldown=8
    InteractionSet
        gold moving     > collectResource
        gold moving     > killSprite
        moving wall     > stepBack
        moving marsh    > killIfHasMore      resource=gold limit=11
        goal avatar     > killIfOtherHasMore resource=gold limit=10
        
    TerminationSet
        SpriteCounter stype=goal   limit=0 win=True
        SpriteCounter stype=avatar limit=0 win=False
    
    LevelMapping
        G > goal
        . > marsh
        0 > gold
        1 > random
"""

if __name__ == "__main__":
    from vgdl.core import VGDLParser
    VGDLParser.playGame(overload_game, overload_level)    
Esempio n. 15
0
'''
VGDL example: Same as frogs.py, but uploads video on youtube

@author: Tom Schaul, Spyridon Samothrakis
'''

from frogs import frog_level, frog_game

if __name__ == "__main__":
    from vgdl.core import VGDLParser
    from vgdl.youtube import upload
    game = VGDLParser.playGame(frog_game, frog_level, persist_movie=True)
    upload(game.video_file)
Esempio n. 16
0
        missile > Missile
            sam  > orientation=UP    color=BLUE singleton=True
            bomb > orientation=DOWN  color=RED  speed=0.5
        alien   > Bomber       stype=bomb   prob=0.01  cooldown=3 speed=0.75
        portal  > SpawnPoint   stype=alien  delay=16   total=20
    
    LevelMapping
        0 > base
        1 > portal

    TerminationSet
        SpriteCounter      stype=avatar               limit=0 win=False
        MultiSpriteCounter stype1=portal stype2=alien limit=0 win=True
        
    InteractionSet
        avatar  EOS  > stepBack
        alien   EOS  > turnAround        
        missile EOS  > killSprite
        missile base > killSprite
        base missile > killSprite
        base   alien > killSprite
        avatar alien > killSprite
        avatar bomb  > killSprite
        alien  sam   > killSprite         
"""

if __name__ == "__main__":
    from vgdl.core import VGDLParser
    # parse, run and play.
    VGDLParser.playGame(aliens_game, aliens_level)    
Esempio n. 17
0
@author: Tom Schaul
'''

from mazegames import commonmaze_game

polarTmaze_game = commonmaze_game +"""
        avatar   > RotatingAvatar
    TerminationSet
        SpriteCounter stype=goal limit=1 win=True
"""

Tmaze_game = commonmaze_game +"""
    TerminationSet
        SpriteCounter stype=goal limit=1 win=True
"""


def tmaze(length):
    s =      "wwwwwwwww\n"
    s +=     "wG 4w2 Gw\n"
    for _ in range(length-1):
        s += "ww www ww\n"
    s +=     "wm3www3mw\n"
    s +=     "wwwwwwwww\n"
    return s


if __name__ == "__main__":
    from vgdl.core import VGDLParser
    VGDLParser.playGame(polarTmaze_game, tmaze(4))    
Esempio n. 18
0
        wall bullet > killSprite 
        bullet wall > killSprite 
        pad bullet > killSprite
        avatar wall > stepBack
        avatar EOS > stepBack
        bullet EOS > killSprite

    LevelMapping
        G > pad
"""

artillery_level = """
wwwwwwwwwwwwwwwwwwwwww
w        w    w      w
w           www      w
w             w     ww
w           G        w
w   w                w
w    www          w  w
w      wwwwwww  www  w
w              ww    w
w  G            w    w
w  ww  G           G w
wA    wwwwww         w
wwwwwwwwwwwwwwwwwwwwww
"""

if __name__ == "__main__":
    from vgdl.core import VGDLParser
    VGDLParser.playGame(artillery_game, artillery_level)
        
Esempio n. 19
0
        SpriteCounter  stype=avatar  limit=0 win=False
        MultiSpriteCounter  stype1=goodies stype2=monster limit=0 win=True
        
    InteractionSet
        moving  EOS  > stepBack
        weapon  EOS  > stepBack
        moving  wall > stepBack
        avatar gold  > stepBack
        boulder wall > stepBack
        monster wall > flipDirection
        monster EOS  > flipDirection
        falling wall > killSprite
        wall shovel  > killSprite  
        gem  avatar  > killSprite        
        weapon avatar> killSprite    
        avatar monster  > killSprite        
        monster boulder > killSprite
        moving falling  > killSprite
        shovel shovel> transformTo stype=boulder      
        boulder wall > transformTo stype=resting
        gold shovel  > transformTo stype=falling
        gold boulder > transformTo stype=falling
         
"""



if __name__ == "__main__":
    from vgdl.core import VGDLParser
    VGDLParser.playGame(digdug_game, underground)    
Esempio n. 20
0
        G > goal
        
    SpriteSet         
        structure > Immovable
            goal         > color=GREEN
            wind  > Conveyor orientation=UP
                lowwind  > strength=1 color=LIGHTBLUE
                highwind > strength=2 
        
    TerminationSet
        SpriteCounter stype=goal limit=0 win=True
        
    InteractionSet
        goal avatar        > killSprite"""

windy_det_game = windymaze_game + """
        avatar wind        > conveySprite
        avatar wall        > stepBack
        
"""
windy_stoch_game = windymaze_game + """
        avatar wind        > windGust
        avatar wall        > stepBack
        
"""

if __name__ == "__main__":
    from vgdl.core import VGDLParser
    #VGDLParser.playGame(windy_det_game, windy_level)
    VGDLParser.playGame(windy_stoch_game, windy_level)
Esempio n. 21
0
    s += "wGw\n"
    for _ in range(length/2-2):
        s += "w w\n"
    s +=     "wAw\n"
    s +=     "w4w\n"
    s +=     "w1w\n"
    s +=     "www\n"
    return s


def ringworld(width):
    assert width > 1
    level = ["w"]*(width+2)+["\n"]
    level += ["w"]+[" "]*width+["w\n"]
    level += ["w"]*(width+2)+["\n"]
    level[int(width*1.5+3.5)] = 'G'    
    #level[-(width+5)] = 'A'    
    level_str = ''.join(level)
    return level_str
    

if __name__ == "__main__":
    print ringworld(9)    
    from vgdl.core import VGDLParser
    g = VGDLParser().parseGame(wrapmaze_game)
    g.buildLevel(ringworld(19))
    g.randomizeAvatar()
    g.startGame()
            
    VGDLParser.playGame(portalmaze_game, portalringworld(19))
Esempio n. 22
0
        - > wind
        = > ice
        G > goal
        < > tvleft
        ^ > tvup
        
    SpriteSet         
        structure > Immovable
            goal  > color=GREEN
            tv    > Conveyor color=RED
                tvup    > orientation=UP
                tvleft  > orientation=LEFT
            ice   > color=WHITE
            wind  > Conveyor orientation=RIGHT strength=1                                         
        avatar   > RotatingAvatar

    TerminationSet
        SpriteCounter stype=goal limit=0 win=True
        
    InteractionSet
        goal avatar  > killSprite
        avatar wind  > windGust
        avatar tv    > attractGaze prob=1
        avatar ice   > slipForward prob=0.3
        avatar wall  > stepBack        
"""

if __name__ == "__main__":
    from vgdl.core import VGDLParser
    VGDLParser.playGame(stoch_game, stoch_level)
Esempio n. 23
0
def playEpisode(rleCreateFunc,
                hypotheses=[],
                game_object=None,
                unknown_colors=False,
                goalColor=None,
                finalEventList=[],
                playback=False):

    rle = rleCreateFunc()  ## Initialize rle the agent behaves in.
    all_objects = rle._game.getObjects()

    # spriteInduction(rle._game, step=0)													## Initialize sprite induction

    noHypotheses = len(hypotheses) == 0

    print ""
    if unknown_colors == False:
        unknown_objects = [
            k for k in rle._game.sprite_groups.keys() if k != 'avatar'
        ]
        unknown_colors = [
            colorDict[str(rle._game.sprite_groups[k][0].color)]
            for k in unknown_objects
        ]
        print "unknown objects:", unknown_colors
    else:
        print "already know some objects. Unknown:"
        print unknown_colors

    ended, won = rle._isDone()

    total_states_encountered = [rle._game.getFullState()
                                ]  ## Start storing encountered states.

    Vrle = None
    g = game_object
    while not ended:
        if noHypotheses:  ## Observe a few frames, then initialize sprite hypotheses
            observe(rle, 5)
            sample = sampleFromDistribution(rle._game.spriteDistribution,
                                            all_objects)
            g = Game(spriteInductionResult=sample)
            t = g.buildGenericTheory(sample)
            hypotheses = [t]
            noHypotheses = False

        if not Vrle:  ## Initialize world in agent's head.
            symbolDict = generateSymbolDict(rle)
            # for k,v in symbolDict.items():
            # 	print k, v
            # print ""
            # print "Initializing mental theory."
            game, level, symbolDict, immovables = writeTheoryToTxt(rle, hypotheses[0], symbolDict,\
             "./examples/gridphysics/theorytest.py")

            Vrle = createMindEnv(game, level, output=False)
            Vrle.immovables = immovables
        if goalColor:  ## Select known goal if it's known, otherwise unkown object.
            key = [k for k in rle._game.sprite_groups.keys() if \
            colorDict[str(rle._game.sprite_groups[k][0].color)]==goalColor][0]
            actual_goal = rle._game.sprite_groups[key][0]
            object_goal = actual_goal
            object_goal_location = Vrle._rect2pos(object_goal.rect)
            object_goal_location = object_goal_location[
                1], object_goal_location[0]
            print "goal is known:", goalColor
            print ""
        else:
            try:
                object_goal = selectObjectGoal(Vrle,
                                               unknown_colors,
                                               method="random_then_nearest")
                object_goal_location = Vrle._rect2pos(object_goal.rect)
                object_goal_location = object_goal_location[
                    1], object_goal_location[0]
                print "object goal is", colorDict[str(
                    object_goal.color)], "at location", (rle._rect2pos(
                        object_goal.rect)[1], rle._rect2pos(
                            object_goal.rect)[0])
                print ""
            except:
                print "no unknown objects and no goal? Embedding so you can debug."
                embed()

        game, level, symbolDict, immovables = writeTheoryToTxt(rle, hypotheses[0], symbolDict,\
         "./examples/gridphysics/theorytest.py", object_goal_location)

        print "Initializing mental theory *with* object goal"
        # print "immovables", immovables
        Vrle = createMindEnv(
            game, level,
            output=True)  ## World in agent's head, including object goal
        Vrle.immovables = immovables
        ## Plan to get to object goal
        rle, hypotheses, finalEventList, candidate_new_colors, states_encountered, g = \
        getToObjectGoal(rle, Vrle, g, hypotheses[0], game, level, object_goal, all_objects, finalEventList, symbolDict=symbolDict)

        if len(unknown_colors) > 0:
            for col in candidate_new_colors:
                if col in unknown_colors:
                    unknown_colors.remove(col)

        ended, won = rle._isDone()
        # actions_taken.extend(actions_executed)
        total_states_encountered.extend(states_encountered)

        ## Hack to remember actual winning goal, until terminationSet is fixed.
        if won and not hypotheses[0].goalColor:
            # embed()
            goalColor = finalEventList[-1]['effectList'][0][
                1]  #fix. don't assume the second obj is the goal.
            hypotheses[0].goalColor = goalColor

    if playback:  ## TODO: Aritro cleans this up.
        print "in playback"
        from vgdl.core import VGDLParser
        from examples.gridphysics.simpleGame4 import level, game
        playbackGame = game
        playbackLevel = level
        VGDLParser.playGame(playbackGame, playbackLevel,
                            total_states_encountered)  #, persist_movie=True)

    return hypotheses, g, won, unknown_colors, goalColor, finalEventList, total_states_encountered
Esempio n. 24
0
        wall bullet > killSprite 
        bullet wall > killSprite 
        pad bullet > killSprite
        avatar wall > stepBack
        avatar EOS > stepBack
        bullet EOS > killSprite

    LevelMapping
        G > pad
"""

artillery_level = """
wwwwwwwwwwwwwwwwwwwwww
w        w    w      w
w           www      w
w             w     ww
w           G        w
w   w                w
w    www          w  w
w      wwwwwww  www  w
w              ww    w
w  G            w    w
w  ww  G           G w
wA    wwwwww         w
wwwwwwwwwwwwwwwwwwwwww
"""

if __name__ == "__main__":
    from vgdl.core import VGDLParser
    VGDLParser.playGame(artillery_game, artillery_level)
Esempio n. 25
0
        SpriteCounter stype=pad    win=True     
        SpriteCounter stype=avatar win=False     
           
    InteractionSet
        inertial wall > wallBounce 
        pad avatar    > killSprite
        
    LevelMapping
        G > pad
"""

ptsp_level = """
wwwwwwwwwwwwwwwwwwwwwwwwwwww
w        w    w    w       w
w    A    wwww    www      w
w                   w     ww
w             G     w  G   w
w   w                      w
w    www                w  w
w      wwwwwww        www  w
w                    ww    w
w  G                  w    w
w        ww  G           G w
w     wwwwwwwwww           w
wwwwwwwwwwwwwwwwwwwwwwwwwwww
"""

if __name__ == "__main__":
    from vgdl.core import VGDLParser
    VGDLParser.playGame(ptsp_game, ptsp_level)
Esempio n. 26
0
        moving >
            avatar > MovingAvatar            
            bee    > RandomNPC speed=1   cooldown=3  color=YELLOW
            zombie > Chaser stype=avatar cooldown=6 speed=0.5 color=BROWN
            
    InteractionSet
        honey avatar    > collectResource scoreChange=1
        honey avatar    > killSprite
        moving wall     > stepBack
        avatar zombie   > killIfHasLess resource=honey limit=1 scoreChange=-1
        avatar zombie   > changeResource resource=honey value=-1
        zombie avatar   > killSprite
        bee zombie      > transformTo stype=honey
        zombie bee      > killSprite
        avatar hell     > killSprite
        
    TerminationSet
        Timeout limit=1000 win=True
        SpriteCounter stype=avatar limit=0 win=False
    
    LevelMapping
        0 > flower
        1 > hell
        . > honey
        2 > zombie
"""

if __name__ == "__main__":
    from vgdl.core import VGDLParser
    VGDLParser.playGame(zombie_game, zombie_level)    
Esempio n. 27
0
        
    InteractionSet
        goal avatar  > killSprite
        avatar log   > changeResource resource=safety value=2
        avatar log   > pullWithIt   # note how one collision can have multiple effects
        avatar wall  > stepBack
        avatar water > killIfHasLess  resource=safety limit=0
        avatar water > changeResource resource=safety value=-1
        avatar truck > killSprite
        log    EOS   > killSprite
        truck  EOS   > wrapAround
    
    TerminationSet
        SpriteCounter stype=goal   limit=0 win=True
        SpriteCounter stype=avatar limit=0 win=False
    
    LevelMapping
        G > goal
        0 > water
        1 > forest water       # note how a single character can spawn multiple sprites
        2 > forest wall log
        - > slowtruck
        x > fasttruck
        = > log water
         
"""

if __name__ == "__main__":
    from vgdl.core import VGDLParser
    VGDLParser.playGame(frog_game, frog_level)
Esempio n. 28
0
"""
VGDL example: Same as frogs.py, but uploads video on youtube

@author: Tom Schaul, Spyridon Samothrakis
"""

from frogs import frog_level, frog_game

if __name__ == "__main__":
    from vgdl.core import VGDLParser
    from vgdl.youtube import upload

    game = VGDLParser.playGame(frog_game, frog_level, persist_movie=True)
    upload(game.video_file)
Esempio n. 29
0
@author: Tom Schaul
"""


def openmaze(size):
    res = ([' ']*size+['\n'])*size
    res[0] = 'A'
    res[size*size/2] = '0'
    return ''.join(res)


chasemaze_game = """
BasicGame 
    LevelMapping
        0 > prey        
    InteractionSet
        moving EOS  > wrapAround
        prey avatar > killSprite        
    SpriteSet         
        moving   >
            prey     > Missile speed=1 color=GREEN
            avatar   > OrientedAvatar draw_arrow=False                
    TerminationSet
        SpriteCounter stype=prey limit=0 win=True
"""


if __name__ == "__main__":
    from vgdl.core import VGDLParser
    VGDLParser.playGame(chasemaze_game, openmaze(8))   
Esempio n. 30
0
www w1  wwwww
w       w 0 w
w 1        ww
w          ww
wwwwwwwwwwwww
"""

push_game = """
BasicGame frame_rate=30
    SpriteSet        
        hole   > Immovable color=DARKBLUE
        movable >
            avatar > MovingAvatar cooldown=4
            box    > Passive                
    LevelMapping
        0 > hole
        1 > box            
    InteractionSet
        avatar wall > stepBack        
        box avatar  > bounceForward
        box wall    > undoAll        
        box box     > undoAll
        box hole    > killSprite        
    TerminationSet
        SpriteCounter stype=box    limit=0 win=True          
"""

if __name__ == "__main__":
    from vgdl.core import VGDLParser
    VGDLParser.playGame(push_game, box_level)
Esempio n. 31
0
        normal infected   > transformTo stype=carrier
        host infected     > transformTo stype=infected
        normal virus      > transformTo stype=carrier        
        host virus        > transformTo stype=infected
        guardian virus    > killSprite 
        
    LevelMapping
        1 > guardian
        0 > host
        X > virus
        A > normal
"""

chase_level = """
wwwwwwwwwwwwwwwwwwwwwwwwwwww
www  0  w   w   0 www 0w0  w
w       1   w        X w  0w
w 0     0 w   A        w0  w
w   wwwwwwww             0 w
w0                  ww  wwww
w    0  1 w        w    X  w
w0  w      wwwww   wX w  10w
wwww                wwX 1 Xw
wwww     0   0   0 www 0 Xww
wwwwwwwwwwwwwwwwwwwwwwwwwwww
"""

if __name__ == "__main__":
    from vgdl.core import VGDLParser
    VGDLParser.playGame(infection_game, chase_level)    
Esempio n. 32
0
        SpriteCounter stype=cocoon    win=False     
           
    InteractionSet
        butterfly avatar > killSprite 
        butterfly cocoon > cloneSprite
        cocoon butterfly > killSprite
        animal    wall   > stepBack        
        
    LevelMapping
        1 > butterfly
        0 > cocoon
"""

chase_level = """
wwwwwwwwwwwwwwwwwwwwwwwwwwww
w  1     1  w   0 0 0 0w000w
w 1                    w000w
w   1         A        w000w
wwwwwwwwwwww             00w
w0                  w     ww
w0      1                  w
w0         wwwww    1     0w
wwwww                w     w
w        0 0 0 0 0   w0   0w
wwwwwwwwwwwwwwwwwwwwwwwwwwww
"""

if __name__ == "__main__":
    from vgdl.core import VGDLParser
    VGDLParser.playGame(chase_game, chase_level)
Esempio n. 33
0
        wall > Immovable                       
        
    InteractionSet
        goal avatar  > killSprite
        avatar log   > drownSafe
        avatar log   > pullWithIt   # note how one collision can have multiple effects
        avatar wall  > stepBack
        avatar water > drownSprite
        avatar truck > killSprite
        log    EOS   > killSprite
        truck  EOS   > wrapAround
    
    TerminationSet
        SpriteCounter stype=goal   limit=0 win=True
        SpriteCounter stype=avatar limit=0 win=False
    
    LevelMapping
        G > goal
        0 > water
        1 > forest water       # note how a single character can spawn multiple sprites
        2 > forest wall log
        - > slowtruck
        x > fasttruck
        = > log water
         
"""

if __name__ == "__main__":
    from vgdl.core import VGDLParser
    VGDLParser.playGame(frog_game, frog_level)    
Esempio n. 34
0
                exit2  > 
    InteractionSet
        goal   avatar    > killSprite
        avatar bullet    > killSprite
        avatar wall      > stepBack
        random structure > stepBack
        random wall      > stepBack
        straight wall    > reverseDirection
        avatar portalentry > teleportToExit
        
    TerminationSet
        SpriteCounter stype=goal   limit=0 win=True
        SpriteCounter stype=avatar limit=0 win=False
    
    LevelMapping
        < > horizontal
        v > vertical
        x > sitting
        r > random
        G > goal
        i > entry1
        I > entry2
        o > exit1
        O > exit2
        
"""

if __name__ == "__main__":
    from vgdl.core import VGDLParser
    VGDLParser.playGame(portal_game, portal_level)    
Esempio n. 35
0
consistent_corridor = """
wwwwwwwwwwwwww
w        wwwww
w   ww   wwwww
w m ww m wwwww
w wwwwww wwwww
w   ww   wwwww
w  mww wwwwwww
w      w    Gw
wwwwwwAw  mwww
w      w   www
w  mww w wwwww
w   ww   wwwww
w wwwwww wwwww
w   ww m wwwww
w  mww   wwwww
w        wwwww
wwwwwwwwwwwwww
"""
        

if __name__ == "__main__":
    from vgdl.core import VGDLParser
    from vgdl.examples.gridphysics.mazes.mazegames import polarmaze_game, maze_game
    VGDLParser.playGame(maze_game, maze_level_1)
    VGDLParser.playGame(maze_game, maze_level_2)
    VGDLParser.playGame(maze_game, maze_level_3)
    VGDLParser.playGame(polarmaze_game, corridor2)
    VGDLParser.playGame(polarmaze_game, office_layout_2)
    VGDLParser.playGame(polarmaze_game, office_layout)
        
Esempio n. 36
0
w       w 0 w
w 1        ww
w          ww
wwwwwwwwwwwww
"""

        
push_game = """
BasicGame frame_rate=30
    SpriteSet        
        hole   > Immovable color=DARKBLUE
        movable >
            avatar > MovingAvatar cooldown=4
            box    > Passive                
    LevelMapping
        0 > hole
        1 > box            
    InteractionSet
        avatar wall > stepBack        
        box avatar  > bounceForward
        box wall    > undoAll        
        box box     > undoAll
        box hole    > killSprite        
    TerminationSet
        SpriteCounter stype=box    limit=0 win=True          
"""

if __name__ == "__main__":
    from vgdl.core import VGDLParser
    VGDLParser.playGame(push_game, box_level)    
Esempio n. 37
0
        
    SpriteSet         
        structure > Immovable
            goal         > color=GREEN
            wind  > Conveyor orientation=UP
                lowwind  > strength=1 color=LIGHTBLUE
                highwind > strength=2 
        
    TerminationSet
        SpriteCounter stype=goal limit=0 win=True
        
    InteractionSet
        goal avatar        > killSprite"""

windy_det_game = windymaze_game+"""
        avatar wind        > conveySprite
        avatar wall        > stepBack
        
"""
windy_stoch_game = windymaze_game+"""
        avatar wind        > windGust
        avatar wall        > stepBack
        
"""


if __name__ == "__main__":
    from vgdl.core import VGDLParser
    #VGDLParser.playGame(windy_det_game, windy_level)
    VGDLParser.playGame(windy_stoch_game, windy_level)
Esempio n. 38
0
           
    InteractionSet
        inertial wall > wallBounce 
        avatar bullet > killSprite
        pad avatar    > killSprite
        
    LevelMapping
        G > pad
        1 > bullet
"""

ptsp_level = """
wwwwwwwwwwwwwwwwwwwwwwwwwwww
w        w    w    w       w
w    A    wwww    www      w
w                   w     ww
w             G     w  G   w
w   w                      w
w    www   1            w  w
w      wwwwwww        www  w
w                    ww    w
w  G                  w    w
w        ww  G           G w
w     wwwwwwwwww           w
wwwwwwwwwwwwwwwwwwwwwwwwwwww
"""

if __name__ == "__main__":
    from vgdl.core import VGDLParser
    VGDLParser.playGame(ptsp_game, ptsp_level)
        
Esempio n. 39
0
             zelda_level_list[randIndex] = 'R'
             redCount += 1
             if (redCount >= red):
                 break
     else:
         break
 #green
 for i in range(99999):
     if (zelda_level.find(' ')):
         randIndex = int(random.uniform(0, len(zelda_level)))
         if (zelda_level_list[randIndex] == ' '):
             zelda_level_list[randIndex] = 'G'
             greenCount += 1
             if (greenCount >= green):
                 break
     else:
         break
 #blue
 for i in range(99999):
     if (zelda_level.find(' ')):
         randIndex = int(random.uniform(0, len(zelda_level)))
         if (zelda_level_list[randIndex] == ' '):
             zelda_level_list[randIndex] = 'B'
             blueCount += 1
             if (blueCount >= blue):
                 break
     else:
         break
 zelda_this_level = ''.join(zelda_level_list)
 VGDLParser.playGame(zelda_game, zelda_this_level, fnn=net, isScreen=True)
Esempio n. 40
0
        SpriteCounter stype=pad limit=4 win=True     
        SpriteCounter stype=avatar      win=False     
           
    InteractionSet
        avatar wall > killSprite 
        avatar EOS > killSprite 
        pad avatar  > killIfSlow    # relative velocity
        
    LevelMapping
        G > pad
"""

lander_level = """
wwwwwwwwwwwwwwwwwwwwwwwwwwww
         w    w            w
     A    wwww              
                            
                            
                            
                      www   
                     wwww  w
        w        wwwwwwwwGGw
       wwwwwGGGwwwwwwwwwwwww
     wwwwwwwwwwwwwwwwwwwwwww
wwwwwwwwwwwwwwwwwwwwwwwwwwww
"""

if __name__ == "__main__":
    from vgdl.core import VGDLParser
    VGDLParser.playGame(lander_game, lander_level)
Esempio n. 41
0
           
    InteractionSet
        goal ball   > killSprite
        ball racket > bounceDirection
        ball wall   > wallBounce
        racket wall > stepBack
        
    LevelMapping
        - > mygoal
        + > othergoal
        a > otheravatar
        o > ball
"""

pong_level = """
wwwwwwwwwwwwwwwwwwwwww
w+                  -w
w+                  -w
w+                  -w
w+A        o       a-w
w+                  -w
w+                  -w
w+                  -w
wwwwwwwwwwwwwwwwwwwwww
"""


if __name__ == "__main__":
    from vgdl.core import VGDLParser
    VGDLParser.playGame(pong_game, pong_level)
Esempio n. 42
0
w.wwww.ww.wwwwwwww.ww.wwww.w
w.wwww.ww.wwwwwwww.ww.wwww.w
w......ww....ww....ww......w
wwwwww.wwwww ww wwwww.wwwwww
wwwwww.wwwww ww wwwww.wwwwww
wwwwww.ww          ww.wwwwww
wwwwww.ww          ww.wwwwww
wwwwww.ww www  www ww.wwwwww
      .   ww1234ww   .      
wwwwww.ww wwwwwwww ww.wwwwww
wwwwww.ww          ww.wwwwww
wwwwww.ww          ww.wwwwww
wwwwww.ww wwwwwwww ww.wwwwww
wwwwww.ww wwwwwwww ww.wwwwww
w............ww............w
w.wwww.wwwww.ww.wwwww.wwww.w
w0wwww.wwwww.ww.wwwww.wwww0w
w...ww.......A........ww...w
www.ww.ww.wwwwwwww.ww.ww.www
www.ww.ww.wwwwwwww.ww.ww.www
w......ww....ww....ww......w
w.wwwwwwwwww.ww.wwwwwwwwww.w
w.wwwwwwwwww.ww.wwwwwwwwww.w
w..........................w
wwwwwwwwwwwwwwwwwwwwwwwwwwww
"""

if __name__ == "__main__":
    from vgdl.core import VGDLParser
    VGDLParser.playGame(pacman_game, pacman_level)    
Esempio n. 43
0
        SpriteCounter stype=mygoal    limit=6 win=True     
           
    InteractionSet
        goal ball   > killSprite
        ball racket > bounceDirection
        ball wall   > wallBounce
        racket wall > stepBack
        
    LevelMapping
        - > mygoal
        + > othergoal
        a > otheravatar
        o > ball
"""

pong_level = """
wwwwwwwwwwwwwwwwwwwwww
w+                  -w
w+                  -w
w+                  -w
w+A        o       a-w
w+                  -w
w+                  -w
w+                  -w
wwwwwwwwwwwwwwwwwwwwww
"""

if __name__ == "__main__":
    from vgdl.core import VGDLParser
    VGDLParser.playGame(pong_game, pong_level)
Esempio n. 44
0
           
    InteractionSet
        escape avatar > killSprite 
        avatar fire   > killSprite
        fire   wall   > killSprite
        fire   fire   > killSprite
        avatar wall   > stepBack        
        
    LevelMapping
        1 > escape 
        0 > seed
"""

fire_level = """
wwwwwwwwwwwwwwwwwwwwwwwwwwww
wA w   w   w           w 0 w
w  w w     w  w    0   w   w
w    w  w       w      w   w
wwwwwwwwwww        ww      w
w 0                  w     w
w        ww             w  w
w          www w    ww     w
www    0           w       w
w0              w     w   1w
wwwwwwwwwwwwwwwwwwwwwwwwwwww
"""

if __name__ == "__main__":
    from vgdl.core import VGDLParser
    VGDLParser.playGame(fire_game, fire_level)
Esempio n. 45
0
w                      w
w                      w
w                      w
w     c     c      c   w
wwwwwwwwwwwwwwwwwwwwwwww
"""

missilecommand_game = """
BasicGame
  SpriteSet         
    city  > Immovable color=GREEN
    incoming > Chaser stype=city color=ORANGE speed=0.1
    explosion > Flicker limit=5 
    avatar  > ShootAvatar stype=explosion 
  LevelMapping
    c > city
    m > incoming           
  InteractionSet
    movable wall  > stepBack
    incoming city > killSprite
    city incoming > killSprite
    incoming explosion > killSprite             
  TerminationSet
    SpriteCounter stype=city   win=False
    SpriteCounter stype=incoming win=True
"""

if __name__ == "__main__":
    from vgdl.core import VGDLParser
    VGDLParser.playGame(missilecommand_game, missilecommand_level)  
Esempio n. 46
0
		b > butterfly
	InteractionSet
		dirt avatar > killSprite
		dirt sword  > killSprite
		diamond avatar > collectResource scoreChange=5
		diamond avatar > killSprite
		moving wall > stepBack
		moving boulder > stepBack
		avatar boulder > killIfFromAbove
		avatar butterfly > killSprite
		avatar crab > killSprite
		boulder dirt > stepBack
		boulder wall > stepBack
		boulder boulder > stepBack
		boulder diamond > stepBack
		enemy dirt > stepBack
		enemy diamond > stepBack
		crab butterfly > killSprite
		butterfly crab > transformTo stype=diamond scoreChange=1
		exitdoor avatar > killIfOtherHasMore resource=diamond limit=9 scoreChange=100

	TerminationSet
		SpriteCounter stype=avatar limit=0 win=False
		SpriteCounter stype=exitdoor limit=0 win=True

"""

if __name__ == "__main__":
    from vgdl.core import VGDLParser
    VGDLParser.playGame(boulderdash_game, boulderdash_level)
Esempio n. 47
0
def playEpisode(rleCreateFunc, hypotheses=[], unknown_objects=False, goalColor=None, finalEventList=[], playback=False):

																						## Initialize rle the agent behaves in.
	rle = rleCreateFunc()
	rle._game.unknown_objects = rle._game.sprite_groups.keys()
	rle._game.unknown_objects.remove('avatar') 											## For now we're asumming agent knows self.
	rle.agentStatePrev = {}
	all_objects = rle._game.getObjects()

	spriteInduction(rle._game, step=0)													## Initialize sprite induction


	noHypotheses = len(hypotheses)==0

		# sample = sampleFromDistribution(rle._game.spriteDistribution, all_objects)		## Initialize mental theory
		# g = Game(spriteInductionResult=sample)
		# t = g.buildGenericTheory(sample)
		# hypotheses = [t]



	## Fix this mess. Store the unknown categories. Select among those for a goal, and then provide that to selectToken.
	if unknown_categories==False:
		print "initializing unknown objects:"
		unknown_categories = [k for k in rle._game.sprite_groups.keys() if k!='avatar']
		print [colorDict[str(rle._game.sprite_groups[k][0].color)] for k in unknown_categories]
	else:
		print "already know some objects. Unknown:"
		print [colorDict[str(rle._game.sprite_groups[k][0].color)] for k in unknown_categories]


	# if unknown_objects==False: ##uninitialized
	# 	print "initializing unknown objects:"
	# 	unknown_objects=[rle._game.sprite_groups[k] for k in rle._game.sprite_groups.keys() if k!='avatar'] 	## Store instances of unknown objects
	# 	print [colorDict[str(o[0].color)] for o in unknown_objects]
	# else:
	# 	print "already know some objects. Unknown:"
	# 	print [colorDict[str(o[0].color)] for o in unknown_objects]
	

	##working hypothesis is hypotheses[0] for now.
	# unknown_objects= []
	# print [r.generic for r in hypotheses[0].interactionSet]
	# for rule in hypotheses[0].interactionSet:
	# 	##right now this only tries to learn about avatar touching things
	# 	##not things touching things
	# 	##Also sometimes you're going to randomly choose an unreachable object!
	# 	if rule.generic:
	# 		## make sure this is right if you have multiple objects in the class.
	# 		## e.g., review induction assumptions.

	# 		## you're assuming that generic rules always have avatar in slot2
	# 		col = hypotheses[0].classes[rule.slot1][0].color
	# 		key = [k for k in rle._game.sprite_groups.keys() if \
	# 		colorDict[str(rle._game.sprite_groups[k][0].color)]==col][0]
	# 		unknown_objects.append(rle._game.sprite_groups[key])
	

	ended, won = rle._isDone()
	
	total_states_encountered = [rle._game.getFullState()]

	Vrle=None


	while not ended:																	## Select known goal if it's known, otherwise unkown object.
		if noHypotheses:																	## Observe a few frames, then initialize sprite hypotheses
			observe(rle, 5)
			sample = sampleFromDistribution(rle._game.spriteDistribution, all_objects)
			g = Game(spriteInductionResult=sample)
			t = g.buildGenericTheory(sample)
			hypotheses = [t]

																							## Initialize world in agent's head.
		if not Vrle:
			game, level, symbolDict, immovables = writeTheoryToTxt(rle, hypotheses[0],\
			 "./examples/gridphysics/theorytest.py")#, rle._rect2pos(subgoal.rect))

			Vrle = createMindEnv(game, level, OBSERVATION_GLOBAL)
			Vrle.immovables = immovables

		if goalColor:
			key = [k for k in rle._game.sprite_groups.keys() if \
			colorDict[str(rle._game.sprite_groups[k][0].color)]==goalColor][0]
			actual_goal = rle._game.sprite_groups[key][0]
			object_goal = actual_goal
			print "goal is known:", goalColor
		else:
			try:
				object_goal = random.choice(unknown_objects)
				embed()
				subgoalLocation = selectSubgoalToken(Vrle, 'wall', unknown_objects)
			except:
				print "no unknown objects and no goal? Embedding so you can debug."
				embed()


		# embed() 
		# subgoal = random.choice(rle._game.sprite_groups[object_goal.name])
		

		

		game, level, symbolDict, immovables = writeTheoryToTxt(rle, hypotheses[0],\
		 "./examples/gridphysics/theorytest.py", subgoalLocation)
		Vrle = createMindEnv(game, level, OBSERVATION_GLOBAL)							## World in agent's head.
		Vrle.immovables = immovables
		embed()

																						## Plan to get to subgoal
		rle, hypotheses, finalEventList, candidate_new_colors, states_encountered = \
		getToSubgoal(rle, Vrle, subgoal, all_objects, finalEventList, symbolDict=symbolDict)
		

		if len(unknown_objects)>0:
			for col in candidate_new_colors:
				obj = [o for o in unknown_objects if colorDict[str(o[0].color)]==col]
				if len(obj)>0:
					obj=obj[0]
					unknown_objects.remove(obj)
			
		ended, won = rle._isDone()
		# actions_taken.extend(actions_executed)
		total_states_encountered.extend(states_encountered)
																						## Hack to remember actual winning goal, until terminationSet is fixed.
		if won and not hypotheses[0].goalColor:
			# embed()
			goalColor = finalEventList[-1]['effectList'][0][1]		#fix. don't assume the second obj is the goal.
			hypotheses[0].goalColor=goalColor

	if playback:			## TODO: Aritro cleans this up.
		print "in playback"
		from vgdl.core import VGDLParser
		from examples.gridphysics.simpleGame4 import level, game
		playbackGame = push_game
		playbackLevel = box_level
		embed()
		VGDLParser.playGame(playbackGame, playbackLevel, total_states_encountered)

	return hypotheses, won, unknown_objects, goalColor, finalEventList, total_states_encountered
Esempio n. 48
0
        moving elevator > pullWithIt        
        elevator EOS    > wrapAround
        
    LevelMapping
        G > goal
        1 > goomba
        2 > paratroopa
        = > elevator
"""

mario_level = """
wwwwwwwwwwwwwwwwwwwwwwwwwwww
w                          w
w                        G1w
w             ===       wwww
w                     1    w
w                w  2 ww   w
w                wwwwwww   w
w                          w
w                          w
w          2        2      w
w        www      wwwwww   w
w A      1   ===           w
wwww   wwww        2       w
wwwwwwwwww      wwww       w
"""

if __name__ == "__main__":
    from vgdl.core import VGDLParser
    VGDLParser.playGame(mario_game, mario_level)
Esempio n. 49
0
        SpriteCounter stype=avatar      win=False     
           
    InteractionSet
        avatar wall > killSprite 
        avatar EOS > killSprite 
        pad avatar  > killIfSlow    # relative velocity
        
    LevelMapping
        G > pad
"""

lander_level = """
wwwwwwwwwwwwwwwwwwwwwwwwwwww
         w    w            w
     A    wwww              
                            
                            
                            
                      www   
                     wwww  w
        w        wwwwwwwwGGw
       wwwwwGGGwwwwwwwwwwwww
     wwwwwwwwwwwwwwwwwwwwwww
wwwwwwwwwwwwwwwwwwwwwwwwwwww
"""

if __name__ == "__main__":
    from vgdl.core import VGDLParser

    VGDLParser.playGame(lander_game, lander_level)
Esempio n. 50
0
        missile > Missile
            sam  > orientation=UP    color=BLUE singleton=True
            bomb > orientation=DOWN  color=RED  speed=0.5
        alien   > Bomber       stype=bomb   prob=0.01  cooldown=3 speed=0.75
        portal  > SpawnPoint   stype=alien  delay=16   total=20
    
    LevelMapping
        0 > base
        1 > portal

    TerminationSet
        SpriteCounter      stype=avatar               limit=0 win=False
        MultiSpriteCounter stype1=portal stype2=alien limit=0 win=True
        
    InteractionSet
        avatar  EOS  > stepBack
        alien   EOS  > turnAround        
        missile EOS  > killSprite
        missile base > killSprite
        base missile > killSprite
        base   alien > killSprite
        avatar alien > killSprite
        avatar bomb  > killSprite
        alien  sam   > killSprite         
"""

if __name__ == "__main__":
    from vgdl.core import VGDLParser
    # parse, run and play.
    VGDLParser.playGame(aliens_game, aliens_level)
Esempio n. 51
0
@author: Tom Schaul
'''

from vgdl.examples.gridphysics.mazes.mazegames import commonmaze_game

polarTmaze_game = commonmaze_game + """
        avatar   > RotatingAvatar
    TerminationSet
        SpriteCounter stype=goal limit=1 win=True
"""

Tmaze_game = commonmaze_game + """
    TerminationSet
        SpriteCounter stype=goal limit=1 win=True
"""


def tmaze(length):
    s = "wwwwwwwww\n"
    s += "wG 4w2 Gw\n"
    for _ in range(length - 1):
        s += "ww www ww\n"
    s += "wm3www3mw\n"
    s += "wwwwwwwww\n"
    return s


if __name__ == "__main__":
    from vgdl.core import VGDLParser
    VGDLParser.playGame(polarTmaze_game, tmaze(4))
Esempio n. 52
0
        avatar  > MovingAvatar 
            naked   > 
            nokey   > color=RED
            withkey > color=YELLOW
    LevelMapping
        G > goal
        k > key        
        + > sword
        A > naked
        0 > door
        1 > monster            
    InteractionSet
        avatar wall    > stepBack
        nokey door     > stepBack
        nokey key      > transformTo stype=withkey
        naked sword    > transformTo stype=nokey                
        goal avatar    > killSprite        
        monster nokey  > killSprite        
        naked monster  > killSprite
        withkey monster> killSprite
        key  avatar    > killSprite
        sword avatar   > killSprite
    TerminationSet
        SpriteCounter stype=goal   limit=0 win=True
        SpriteCounter stype=avatar limit=0 win=False              
"""

if __name__ == "__main__":
    from vgdl.core import VGDLParser
    VGDLParser.playGame(rigidzelda_game, zelda_level)    
Esempio n. 53
0
            floortile    > color=BLUE
            goal         > color=GREEN
    TerminationSet
        SpriteCounter stype=goal limit=4 win=True
"""

fovea_floor = """
wwwwwwwwwwwwwwwww
w..    ..     . w
w   ..      ..  w
w..G .A  . G . .w
w ... .. .    ..w
w. . . . . .   .w
w    .  . .     w
w    . G.  . .. w
w.  .   . . . ..w
w . .. .... ... w
w .... .....  ..w
w  G.. ..  G    w
w.  .  . . .  ..w
w ....   ...... w
w   .    . ... .w
w.  . .. ...... w
wwwwwwwwwwwwwwwww
"""


if __name__ == "__main__":
    from vgdl.core import VGDLParser
    VGDLParser.playGame(maze_game, fovea_floor)