Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def main():
# parse arguments
parser = argparse.ArgumentParser()
parser.add_argument('--agent', type=str, default='GAMBLER', help='Which agent to use')
parser.add_argument('--learning_rate', type=float, default=0.5, help='How quickly the algorithm tries to learn')
parser.add_argument('--discount', type=float, default=0.98, help='Discount for estimated future action')
parser.add_argument('--iterations', type=int, default=2000, help='Iteration count')
ARGS, unparsed = parser.parse_known_args()
# select agent
if ARGS.agent == 'GAMBLER':
agent = Gambler(learning_rate=ARGS.learning_rate, discount=ARGS.discount, iterations=ARGS.iterations)
elif ARGS.agent == 'ACCOUNTANT':
agent = Accountant()
elif ARGS.agent == 'DEEPGAMBLER':
agent = DeepGambler(learning_rate=ARGS.learning_rate, discount=ARGS.discount, iterations=ARGS.iterations)
else:
agent = Drunkard()
# setup simulation
dungeon = DungeonSimulator()
dungeon.reset()
total_reward = 0 # Score keeping
last_total = 0
# main loop
for step in range(ARGS.iterations):
old_state = dungeon.state # Store current state
action = agent.get_next_action(old_state) # Query agent for the next action
new_state, reward = dungeon.take_action(action) # Take action, get new state and reward