Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import random2 # learn more: https://python.org/pypi/random2
import gym # learn more: https://python.org/pypi/gym
import numpy # learn more: https://python.org/pypi/numpy
import universe # learn more: https://python.org/pypi/universe

def main():
  #init enviroment
  env = gym.make('flashgames.CoasterRacer-v0')
  observation_n = env.reset()
  
  #init variables
  #num of game iterations
  n = 0
  j = 0
  #sum of observations
  total_sum = 0
  prev_total_sum = 0
  turn = False
  
  # define turns or keyactions
  left = [('KeyEvent', 'ArrowUp', True), ('KeyEvent', 'ArrowLeft', True), ('KeyEvent', 'ArrowRight', False)]
  right = [('KeyEvent', 'ArrowUp', True), ('KeyEvent', 'ArrowLeft', False), ('KeyEvent', 'ArrowRight', True)]
  forward = [('KeyEvent', 'ArrowUp', True), ('KeyEvent', 'ArrowLeft', False), ('KeyEvent', 'ArrowRight', False)]
  
  #main logic
  while True:
    #increment a counter for # of iterations
    n+=1
    
    #if at least one iteration, check if a turn
    if (observation_n[0] != None):
      #restorestore the reward in the previous score
      prev_score = reward_n[0]
      
      if (turn):
        #pick a random event