Skip to content

Instantly share code, notes, and snippets.

@RicherMans
Created May 29, 2015 13:59
Show Gist options
  • Save RicherMans/04b4cbb3d21889518973 to your computer and use it in GitHub Desktop.
Save RicherMans/04b4cbb3d21889518973 to your computer and use it in GitHub Desktop.
Custom MArioEmu
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
from __future__ import (print_function, unicode_literals,
absolute_import, division)
from emulator import MarioEmulator
from packages.states.state import State
from packages.states.simplestate import SimpleState
from packages.actions.action import Action
import datetime
import time
import os
from packages.gamers.gamer import Gamer
import datetime
import numpy as np
training_folder = 'trained_models'
def mkdir_p(path):
try:
os.makedirs(path)
except OSError as exc: # Python >2.5
if exc.errno == errno.EEXIST and os.path.isdir(path):
pass
else:
raise
class CustomGamer(Gamer, MarioEmulator):
def __init__(self):
self._readScreen = None
self._readExtra = None
self._pressbutton = None
Gamer.__init__(self)
MarioEmulator.__init__(self, self)
self._startEmulator()
def eval(self, learner, matpath):
pass
def train(self):
try:
while True:
actions = []
actions.append(Action.jump_actions[2])
actions.append(Action.direction_actions[1])
action = reduce(lambda x, y: (x[0] | y[0], x[1] | y[1]), actions)
self._pressbutton(*action)
self._readScreen()
self._readExtra()
print('foo')
time.sleep(0.1)
except KeyboardInterrupt:
MarioEmulator.__del__(self)
def timesup(self):
print('time is up')
def gameStarted(self):
print("game started!")
def __del__(self):
self.stop = True
MarioEmulator.__del__(self)
if __name__ == '__main__':
gamer = CustomGamer()
gamer.train()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment