0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

gym-super-mario-brosをインストールして動かした際の備忘録

Last updated at Posted at 2021-05-05

gym-super-mario-brosのURL

https://pypi.org/project/gym-super-mario-bros/

インストール

pip3 install gym-super-mario-bros

ユーザ操作による実行

gym_super_mario_bros -m human

ユーザ操作時のコマンド

A 左
D 右
S しゃがむ
O ジャンプ
P ファイヤー(ファイヤマリオの時だけ)

ランダム移動

gym_super_mario_bros -m random

ステージ指定(4-2の場合)

gym_super_mario_bros -e SuperMarioBros-4-2-v1 -m human

引数の意味は以下参照

Individual Stages
These environments allow a single attempt (life) to make it through a single stage of the game.
Use the template
SuperMarioBros---v
where:
is a number in {1, 2, 3, 4, 5, 6, 7, 8} indicating the world
is a number in {1, 2, 3, 4} indicating the stage within a world
is a number in {0, 1, 2, 3} specifying the ROM mode to use
0: standard ROM
1: downsampled ROM
2: pixel ROM
3: rectangle ROM
For example, to play 4-2 on the downsampled ROM, you would use the environment id SuperMarioBros-4-2-v1.

コマンドラインから実行

以下を参考にさせていただきました

9-3. vcoptでスーパーマリオ1-1をクリアする

sudo apt update
sudo apt install xvfb
pip3 install pyvirtualdisplay
pip3 install matplotlib
sudo apt install imagemagick # gif用
sudo apt install ffmpeg 
sample.py
# マリオ関連のimport
import gym_super_mario_bros
from nes_py.wrappers import JoypadSpace
from gym_super_mario_bros.actions import SIMPLE_MOVEMENT
env = gym_super_mario_bros.make('SuperMarioBros-1-1-v0')
env = JoypadSpace(env, SIMPLE_MOVEMENT)

# プロット関連のimport
import matplotlib.pyplot as plt
from matplotlib import animation, rc

# vcopt関連のimport
import numpy as np
import numpy.random as nr
from vcopt import vcopt

# ゲーム環境のリセット
env.reset()

# 画像の準備
fig = plt.figure()
ims = []

# 繰り返し操作して画面を表示
for i in range(100):
    #0:
    #1:→
    #2:→+ジャンプ
    #3:→→
    #4:→→+ジャンプ
    #5:ジャンプ
    #6:←
    command = nr.randint(1, 7)
    state, reward, done, info = env.step(command)

    plt.imshow(env.render(mode='rgb_array'))
    plt.show()
    
    if done == True:
        break

実行してマリオがランダムに動いているようにみえればOK

python3 sample.py

参考

https://qiita.com/hrs1985/items/871ca5d037d73558bfca
Stable Baselinesを使ってスーパーマリオブラザーズ1-1をクリアするまで
9-3. vcoptでスーパーマリオ1-1をクリアする

0
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?