gym-super-mario
gym-super-mario copied to clipboard
How can I reset the game without making fceux close and open again ?
Sometimes the agent gets stuck. So if the agent does not make any improvement in say 200 frames, I want to reset the game. But doing so closes the fceux and opens it again. This reduces the speed. I am using the gabegrand branch.
Thank you
dont use the reset when an agent is stuck, use env.change_level(new_level=LVint). feel free to ask more questions
But I should reach enough score to change level, or it would say env has no attribution:change_level. How to solve it ?
I had these same issues, I am using this for a genetic algorithm and specifically need to train on each level, getting to a base score as this env does now is of no use to me. I have a branch on my repo that has as few changes as I could to achieve the functionality I needed. The only reset indicator I use is if the distance increase in a number of steps.
maxDistance = 0
oldDistance = 0
bonus = 0
bonusOffset = 0
staleness = 0
done = False
env.change_level(new_level=LVint)
while not done:
ob = env.tiles.flatten()
o = genome.evaluateNetwork(ob.tolist(),discrete=True)
ob, reward, done, _ = env.step(o)
if 'ignore' in _:
done = False
env = gym.make('meta-SuperMarioBros-Tiles-v0')
env.lock.acquire()
env.reset()
env.locked_levels = [False] * 32
env.change_level(new_level=LVint)
env.lock.release()
distance = env._get_info()["distance"]
if oldDistance - distance < -100 :
bonus = maxDistance
bonusOffset = distance
if maxDistance - distance > 50 and distance != 0:
maxDistance = distance
if distance > maxDistance:
maxDistance = distance
staleness = 0
if maxDistance >= distance:
staleness += 1
if staleness > 80 or done:
scores.append(maxDistance-bonusOffset+bonus)
if not done:
done = True
oldDistance = distance
I use this is a chunk of code from my current project (you can find this code in my jobtrainer function) to reset and change levels through all 32 levels as well as save scores through pipes, it is rather complicated because the only way to tell if mario has warped through a pipe is checking if his distance jumps more that 50 units, there might be a better unit but this works in practice. again this is using the env branched on my repo, it is hacky and gross but it works. In the future I would like to rewrite this to not have a base score needed to move to the next level and have windows support... big dreams here.
@koltafrickenfer I have tried your branch and solve this problem perfectly, but there are some little issues:
- It seems like your branch also use 'Tiles' version, but the running speed is much slower than original version, is there any way to improve it?
- Can I remove the mainmenu and just give mario one life to speed up my game?
- Could you please share the main points you modified from original version?
I believe only my instructions in my readMe specify to use the tiles version, just remove "-tiles-" from the env string.
If it is running slower than the original I have not noticed??? I run this in a 12 core opteron server with a gtx 1080 and if there is some issue with my branch causing a drop in performance I would love to resolve that.
In ppaquette_gym_super_mario/nes_env.py
look for line 51, self.cmd_args = ['--xscale 1.5', '--yscale 1.45', '-f 0','--opengl 1.5','--sound 0','--nogui']
, you can set the cmd line arguments for fceux here. maybe enable your gui / change openGL settings.
I merge the original NesEnv class and your MetaNesEnv class and solve the speed issue. And is there no way to change the source code of the game, such as set mario in a specified position? Or I can implement this via lua script?
you could implement that in the lua script.
Are you familiar with this lua script? I tried to modified its curr_page
and curr_x_position
, but I can only move mario in current screen, namely from 0 to 256.
I am familiar with the script but I have almost zero knowledge of the inner workings of the emulator/nes hardware.
Oh, I have solved this problem by reading fceux help files. Thank you very much!
How did you solve it? @shinshiner
A code snippet would be very appreciated!