<jupyter_start><jupyter_text>INM707 Coursework - Task 1<NAME> / 200056225 & <NAME> / 200036364  Rooms EnvironmentThe game is played on a square grid where the length of one side is parameterizable. The aim of the game is to challenge the agent to find the quickest route to the goal from a random starting point. The Agent will have several obstacles in its way of reaching the optimal solution including walls, tornados and limited number of moves, defined by time limit.The grid is divided into 4 rooms in the middle, with connecting doors. The door positions are initialised randomly when the grid is created.There are 2 goals, a sub-optimal goal with a positive reward and an optimal goal more reward. These are placed randomly around the grid if "testing" argument is set to "False" during the initialisation. If testing is set to "True", then sub-optimal goal starts in the upper left room (room 1) and optimal-goal starts in the upper right room (room 2), placed in a random position within the room.There are also tornados, their number depending on the grid size, placed randomly within the grid. At every step of time, they move randomly within the grid. If the agent goes to a cell with a tornado, the episode terminates. Episode also terminates when the time limit is reached or if the agent reaches one of the goals. The agent receives negative rewards for bumping the walls or getting caught by a tornado.<jupyter_code>from rooms import Rooms
grid = Rooms(11, testing=False)
grid.reset()
grid.display()<jupyter_output>X X X X X X X X X X X
X . . . . X . . . . X
X g . . . X . G . A X
X . . . . . . . . . X
X . . . . X . . . . X
X X X T X X X X X . X
X . . . . . . . . . X
X . . . . X . . . . X
X . . . . X . . . . X
X . . . . X . . . . X
X X X X X X X X X X X<jupyter_text>g: Sub-optimal GoalG: Optimal GoalA: AgentX: Wall/obstacleT: Tornado.: Empty cell<jupyter_code>grid = Rooms(11, testing=True)
grid.reset(agent_start_pos='middle')
grid.display()
grid.reset(agent_start_pos='close_to_sub')
grid.display()
grid.reset(agent_start_pos='close_to_opt')
grid.display()
next_cell = grid.move(grid.agent_position, action="right")
state, reward, done = grid.step(next_cell)
grid.display()<jupyter_output>X X X X X X X X X X X
X . . . . X . . . . X
X . . . . X . . . . X
X . . . . . . . . G X
X . . . g X . . . . X
X . X X X X . X X X X
X . . . . . . . . . X
X . . . . X . . . . X
X . . . . X . . . A X
X . . T . X . . . . X
X X X X X X X X X X X<jupyter_text>We have seperated move() and step() functions because move() function is also being used to move the tornados.<jupyter_code>print(f"State: {state}, Reward: {reward}, Done: {done}")
next_cell = grid.move(grid.agent_position, action="up")
state, reward, done = grid.step(next_cell)
grid.display()
print(f"State: {state}, Reward: {reward}, Done: {done}")<jupyter_output>State: 10507, Reward: -1, Done: False
{'fraction_non_alphanumeric': 0.11246518105849582, 'fraction_numerical': 0.012534818941504178, 'mean_word_length': 2.9410150891632374, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 23, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '518536', 'license': 'MIT', 'n_tokens_mistral': 973, 'n_tokens_neox': 936, 'n_words': 422, 'path': 'Task_1/Task_1.ipynb', 'repo_name': 'scbayrak/inm707', 'size': '2889'}