You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
3.1 KiB

  1. """
  2. velocity_set = False
  3. for episode in range(10):
  4. total_reward = 0
  5. j = 0
  6. while not ale.game_over():
  7. if not velocity_set: ale.setRAM(14,0)
  8. j += 1
  9. a = input_to_action(repr(readchar.readchar())[1])
  10. #a = Action.NOOP
  11. if a == "w":
  12. y_ram_setting -= 1
  13. if y_ram_setting <= 61:
  14. y_ram_setting = 61
  15. for i, r in enumerate(ramDICT[y_ram_setting]):
  16. ale.setRAM(i,r)
  17. ale.setRAM(25,x)
  18. ale.act(Action.NOOP)
  19. elif a == "s":
  20. y_ram_setting += 1
  21. if y_ram_setting >= 1950:
  22. y_ram_setting = 1945
  23. for i, r in enumerate(ramDICT[y_ram_setting]):
  24. ale.setRAM(i,r)
  25. ale.setRAM(25,x)
  26. ale.act(Action.NOOP)
  27. elif a == "a":
  28. x -= 1
  29. if x <= 0:
  30. x = 0
  31. ale.setRAM(25,x)
  32. ale.act(Action.NOOP)
  33. elif a == "d":
  34. x += 1
  35. if x >= 144:
  36. x = 144
  37. ale.setRAM(25,x)
  38. ale.act(Action.NOOP)
  39. elif a == "reset":
  40. ram_pos = input("Ram Position:")
  41. for i, r in enumerate(ramDICT[int(ram_pos)]):
  42. ale.setRAM(i,r)
  43. ale.act(Action.NOOP)
  44. # Apply an action and get the resulting reward
  45. elif a == "set_x":
  46. x = int(input("X:"))
  47. ale.setRAM(25, x)
  48. ale.act(Action.NOOP)
  49. elif a == "set_vel":
  50. vel = input("Velocity:")
  51. ale.setRAM(14, int(vel))
  52. ale.act(Action.NOOP)
  53. velocity_set = True
  54. else:
  55. reward = ale.act(a)
  56. ram = ale.getRAM()
  57. #if j % 2 == 0:
  58. # y_pixel = int(j*1/2) + 55
  59. # ramDICT[y_pixel] = ram
  60. # print(f"saving to {y_pixel:04}")
  61. # if y_pixel == 126 or y_pixel == 235:
  62. # input("")
  63. int_old_ram = list(map(int, oldram))
  64. int_ram = list(map(int, ram))
  65. difference = list()
  66. for o, r in zip(int_old_ram, int_ram):
  67. difference.append(r-o)
  68. oldram = deepcopy(ram)
  69. #print(f"player_x: {ram[25]},\tclock_m: {ram[104]},\tclock_s: {ram[105]},\tclock_ms: {ram[106]},\tscore: {ram[107]}")
  70. print(f"player_x: {ram[25]},\tplayer_y: {y_ram_setting}")
  71. #print(f"y_0: {ram[86]}, y_1: {ram[87]}, y_2: {ram[88]}, y_3: {ram[89]}, y_4: {ram[90]}, y_5: {ram[91]}, y_6: {ram[92]}, y_7: {ram[93]}, y_8: {ram[94]}")
  72. #for i, r in enumerate(ram):
  73. # print('{:03}:{:02x} '.format(i,r), end="")
  74. # if i % 16 == 15: print("")
  75. #print("")
  76. #for i, r in enumerate(difference):
  77. # string = '{:02}:{:03} '.format(i%100,r)
  78. # if r != 0:
  79. # print(color(string, fg='red'), end="")
  80. # else:
  81. # print(string, end="")
  82. # if i % 16 == 15: print("")
  83. print("Episode %d ended with score: %d" % (episode, total_reward))
  84. input("")
  85. with open('all_positions_v2.pickle', 'wb') as handle:
  86. pickle.dump(ramDICT, handle, protocol=pickle.HIGHEST_PROTOCOL)
  87. ale.reset_game()
  88. """