def __init__(self, width=610, height=610): pygame.init() hr = 48 print(" " + "-" * hr + " ") print("|" + " " * 15 + "Welcome to aiRPG" + " " * 15 + " |") print("|" + " COS30002-Artificial Intelligence for Games" + " |") print("|" + " " * 17 + "Created By " + " " * 17 + " |") print("|" + " " * 10 + "Kaelob Smythe ( 100597078 ) " + " " * 7 + " | ") print(" " + "-" * hr + " ") self.width, self.height = width, height self.clock = pygame.time.Clock() self.screen = pygame.display.set_mode((self.width, self.height)) self.done = False pygame.display.set_caption("aiRPG") ## Create the Hero, and set variables for GOAP self.hero = character(0, 9) self.hero.setHP(20) self.hero.setDamage(4) self.hero.setHeal(10) ## Create the Enemy, and set variables for GOAP self.enemy = character(9, 3) self.enemy.setHP(20) self.enemy.setDamage(6) self.enemy.setHeal(6) self.grid = Grid_World(self)
parser.add_argument('-model_path', '--model_path', nargs='?', default='model/') parser.add_argument('-model_load', '--model_load', nargs='?', default=True) parser.add_argument('-old_model_name', '--o_model_name', nargs='?', \ default='0706020520.pt') parser.add_argument('-r_memory_Fname', '--r_memory_Fname', nargs='?', \ default='r_memory.pkl') parser.add_argument('-gamma', '--gamma', nargs='?', default=0.999) parser.add_argument('-learning_rate', '--lr', nargs='?', default=0.001) parser.add_argument('-game', '--game_name', nargs='?', default="FFAI-3-v1") args = parser.parse_args() """ switch the board size """ board_size_dict = {'FFAI-3-v1': (7, 14)} """ Smaller variants """ step_now = 0 # record the global steps reward_num = 0 env = Grid_World(7, 14) agent = RL_AGENT_A3C(args.lr, args.gamma, board_size_dict[args.game_name], args.device, args.model_path, args.r_memory_Fname, args.o_model_name, args.model_load) """ Set seed for reproducibility """ seed = 0 """ Play 10 games """ for i in range(args.game_num): """ Reset environment """ obs = env.reset() episode_steps_cnt = 0 done = False """ Take actions as long as game is not done """ while (1): episode_steps_cnt += 1 step_now += 1 # update the steps
default=None) parser.add_argument('-r_memory_Fname', '--r_memory_Fname', nargs='?', default='None') parser.add_argument('-model_load', '--model_load', nargs='?', default=False) parser.add_argument('-gamma', '--gamma', nargs='?', default=0.99) parser.add_argument('-game', '--game_name', nargs='?', default="grid_world") args = parser.parse_args() #print(args.update_period) """ switch the board size """ board_size_dict = {'grid_world': (7, 14)} """ Smaller variants """ step_now = 0 # record the global steps reward_num = 0 env = Grid_World(7, 14) agent = RL_AGENT_A3C(args.lr, args.gamma, board_size_dict[args.game_name], args.device, args.model_path, args.r_memory_Fname, args.o_model_name, args.model_load) """ Set seed for reproducibility """ model_store_set = [ args.step_stop - 4000000, args.step_stop - 2000000, args.step_stop - 1000000, args.step_stop - 10000 ] """ Play 10 games """ for i in range(args.game_num): """ print the record """ if i % 10 == 0: print('____________________________') print('the step now is ', step_now) print('the time is', time.strftime('%m%d%H%M%S'))
class Game(): done = False x = 510 y = 40 os.environ['SDL_VIDEO_WINDOW_POS'] = "%d,%d" % (x, y) STDOUT = -11 hdl = windll.kernel32.GetStdHandle(STDOUT) rect = wintypes.SMALL_RECT(0, 50, 50, 79) # (left, top, right, bottom) windll.kernel32.SetConsoleWindowInfo(hdl, True, byref(rect)) windll.kernel32.SetConsoleCursorPosition(hdl, 0, 0) def __init__(self, width=610, height=610): pygame.init() hr = 48 print(" " + "-" * hr + " ") print("|" + " " * 15 + "Welcome to aiRPG" + " " * 15 + " |") print("|" + " COS30002-Artificial Intelligence for Games" + " |") print("|" + " " * 17 + "Created By " + " " * 17 + " |") print("|" + " " * 10 + "Kaelob Smythe ( 100597078 ) " + " " * 7 + " | ") print(" " + "-" * hr + " ") self.width, self.height = width, height self.clock = pygame.time.Clock() self.screen = pygame.display.set_mode((self.width, self.height)) self.done = False pygame.display.set_caption("aiRPG") ## Create the Hero, and set variables for GOAP self.hero = character(0, 9) self.hero.setHP(20) self.hero.setDamage(4) self.hero.setHeal(10) ## Create the Enemy, and set variables for GOAP self.enemy = character(9, 3) self.enemy.setHP(20) self.enemy.setDamage(6) self.enemy.setHeal(6) self.grid = Grid_World(self) def main_loop(self): while not self.done: for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: done = True break # break out of the for loop if self.done: break # to break out of the while loop self.draw() self.update() def draw(self): self.screen.fill(Color("black")) self.grid.draw() pygame.display.flip() def update(self): self.grid.updateChar(self.hero) self.grid.updateChar(self.enemy)