File size: 47,700 Bytes
7248ace
 
 
 
 
1
2
3
4
5
6
{"name": "space_invaders", "split": "test", "game": "space_invaders", "source": "original", "prompt": "Write from scratch the weights of a policy network that plays Space Invaders as well as possible.\n\nThere is no training, data, loss, gradients, fine-tuning, code execution, calculator, or environment feedback. This is one response. Briefly describe the strategy and hidden units, then provide the weights in the final `edits` code block.\n\nMove the cannon, shoot alien waves, and avoid aliens and enemy bullets.\n\nActions are sampled from softmax logits and have sticky-action probability 0.1.\n\nExact MinAtar 1.0.15 source (`minatar/environments/space_invaders.py`):\n```python\n################################################################################################################\n# Authors:                                                                                                     #\n# Kenny Young (kjyoung@ualberta.ca)                                                                            #\n# Tian Tian (ttian@ualberta.ca)                                                                                #\n################################################################################################################\nimport numpy as np\n\n\n#####################################################################################################################\n# Constants\n#\n#####################################################################################################################\nshot_cool_down = 5\nenemy_move_interval = 12\nenemy_shot_interval = 10\n\n\n#####################################################################################################################\n# Env\n#\n# The player controls a cannon at the bottom of the screen and can shoot bullets upward at a cluster of aliens above.\n# The aliens move across the screen until one of them hits the edge, at which point they all move down and switch\n# directions. The current alien direction is indicated by 2 channels (one for left and one for right) one of which is\n# active at the location of each alien. A reward of +1 is given each time an alien is shot, and that alien is also\n# removed. The aliens will also shoot bullets back at the player. When few aliens are left, alien speed will begin to\n# increase. When only one alien is left, it will move at one cell per frame. When a wave of aliens is fully cleared a\n# new one will spawn which moves at a slightly faster speed than the last. Termination occurs when an alien or bullet\n# hits the player.\n#\n#####################################################################################################################\nclass Env:\n    def __init__(self, ramping=True):\n        self.channels ={\n            'cannon':0,\n            'alien':1,\n            'alien_left':2,\n            'alien_right':3,\n            'friendly_bullet':4,\n            'enemy_bullet':5\n        }\n        self.action_map = ['n','l','u','r','d','f']\n        self.ramping = ramping\n        self.random = np.random.RandomState()\n        self.reset()\n\n    # Update environment according to agent action\n    def act(self, a):\n        r = 0\n        if(self.terminal):\n            return r, self.terminal\n\n        a = self.action_map[a]\n\n        # Resolve player action\n        if(a=='f' and self.shot_timer == 0):\n            self.f_bullet_map[9,self.pos]=1\n            self.shot_timer = shot_cool_down\n        elif(a=='l'):\n            self.pos = max(0, self.pos-1)\n        elif(a=='r'):\n            self.pos = min(9, self.pos+1)\n\n        # Update Friendly Bullets\n        self.f_bullet_map = np.roll(self.f_bullet_map, -1, axis=0)\n        self.f_bullet_map[9,:] = 0\n\n        # Update Enemy Bullets\n        self.e_bullet_map = np.roll(self.e_bullet_map, 1, axis=0)\n        self.e_bullet_map[0,:] = 0\n        if(self.e_bullet_map[9,self.pos]):\n            self.terminal = True\n\n        # Update aliens\n        if(self.alien_map[9,self.pos]):\n            self.terminal = True\n        if(self.alien_move_timer==0):\n            self.alien_move_timer = min(np.count_nonzero(self.alien_map),self.enemy_move_interval)\n            if((np.sum(self.alien_map[:,0])>0 and self.alien_dir<0) or (np.sum(self.alien_map[:,9])>0 and self.alien_dir>0)):\n                self.alien_dir = -self.alien_dir\n                if(np.sum(self.alien_map[9,:])>0):\n                    self.terminal = True\n                self.alien_map = np.roll(self.alien_map, 1, axis=0)\n            else:\n                self.alien_map = np.roll(self.alien_map, self.alien_dir, axis=1)\n            if(self.alien_map[9,self.pos]):\n                self.terminal = True\n        if(self.alien_shot_timer==0):\n            self.alien_shot_timer = enemy_shot_interval\n            nearest_alien = self._nearest_alien(self.pos)\n            self.e_bullet_map[nearest_alien[0], nearest_alien[1]] = 1\n\n        kill_locations = np.logical_and(self.alien_map,self.alien_map==self.f_bullet_map)\n\n        r+=np.sum(kill_locations)\n        self.alien_map[kill_locations] = self.f_bullet_map[kill_locations] = 0\n\n\n        # Update various timers\n        self.shot_timer -= self.shot_timer>0\n        self.alien_move_timer-=1\n        self.alien_shot_timer-=1\n        if(np.count_nonzero(self.alien_map)==0):\n            if(self.enemy_move_interval>6 and self.ramping):\n                self.enemy_move_interval-=1\n                self.ramp_index+=1\n            self.alien_map[0:4,2:8] = 1\n        return r, self.terminal\n\n    # Find the alien closest to player in manhattan distance, currently used to decide which alien shoots\n    def _nearest_alien(self, pos):\n        search_order = [i for i in range(10)]\n        search_order.sort(key=lambda x: abs(x-pos))\n        for i in search_order:\n            if(np.sum(self.alien_map[:,i])>0):\n                return [np.max(np.where(self.alien_map[:,i]==1)),i]\n        return None\n\n    # Query the current level of the difficulty ramp, could be used as additional input to agent for example\n    def difficulty_ramp(self):\n        return self.ramp_index\n\n    # Process the game-state into the 10x10xn state provided to the agent and return\n    def state(self):\n        state = np.zeros((10,10,len(self.channels)),dtype=bool)\n        state[9,self.pos,self.channels['cannon']] = 1\n        state[:,:, self.channels['alien']] = self.alien_map\n        if(self.alien_dir<0):\n            state[:,:, self.channels['alien_left']] = self.alien_map\n        else:\n            state[:,:, self.channels['alien_right']] = self.alien_map\n        state[:,:, self.channels['friendly_bullet']] = self.f_bullet_map\n        state[:,:, self.channels['enemy_bullet']] = self.e_bullet_map\n        return state\n\n    # Reset to start state for new episode\n    def reset(self):\n        self.pos = 5\n        self.f_bullet_map = np.zeros((10,10))\n        self.e_bullet_map = np.zeros((10,10))\n        self.alien_map = np.zeros((10,10))\n        self.alien_map[0:4,2:8] = 1\n        self.alien_dir = -1\n        self.enemy_move_interval = enemy_move_interval\n        self.alien_move_timer = self.enemy_move_interval\n        self.alien_shot_timer = enemy_shot_interval\n        self.ramp_index = 0\n        self.shot_timer = 0\n        self.terminal = False\n\n    # Dimensionality of the game-state (10x10xn)\n    def state_shape(self):\n        return [10,10,len(self.channels)]\n\n    # Subset of actions that actually have a unique impact in this environment\n    def minimal_action_set(self):\n        minimal_actions = ['n','l','r','f']\n        return [self.action_map.index(x) for x in minimal_actions]\n\n```\n\nInput: a row-major 10x10x6 binary grid. Index `(row * 10 + column) * 6 + channel`. Channels: player=cannon; danger=alien|enemy_bullet; reward=alien; projectile=friendly_bullet; trail=alien_left|alien_right; gauge=empty.\n\nNetwork: `h1=tanh(x@W1+b1)`, `h2=tanh(h1@W2+b2)`, `logits=h2@W3+b3`. Shapes are W1 600x32, b1 32, W2 32x32, b2 32, W3 32x6, b3 6. All 20,486 values start at zero.\n\nThe hidden evaluator runs 1,000 fixed-seed episodes, stopping each after 10,000 steps. It divides mean game score by the game's fixed cap and clips the result to [0, 1].\n\nThe final fenced block must start with `edits`. It may contain numeric assignments to indexed entries or slices of W1, b1, W2, b2, W3, and b3. Half-open Python slices and numeric lists are supported, as are `*=`, `+=`, and `-=`. Values must be finite and have absolute value at most 1e6. Example:\n```edits\nW1[12, 0] = 2.5\nb1[0:4] = -1\nW2[0:2, 0:3] = [[1, -1, 0.5], [0, 2, 0]]\nW3[:, 2] *= 2\n```\n", "system_prompt": "You directly program neural-network weights. Follow the task constraints exactly.", "episodes": 1000, "task_id": 185, "family": "minatar_original", "upstream_source_url": "https://pypi.org/project/MinAtar/1.0.15/", "upstream_revision": "MinAtar==1.0.15", "native_source_url": null}
{"name": "breakout", "split": "test", "game": "breakout", "source": "original", "prompt": "Write from scratch the weights of a policy network that plays Breakout as well as possible.\n\nThere is no training, data, loss, gradients, fine-tuning, code execution, calculator, or environment feedback. This is one response. Briefly describe the strategy and hidden units, then provide the weights in the final `edits` code block.\n\nMove the bottom-row paddle left or right to bounce the diagonal ball and break bricks.\n\nActions are sampled from softmax logits and have sticky-action probability 0.1.\n\nExact MinAtar 1.0.15 source (`minatar/environments/breakout.py`):\n```python\n################################################################################################################\n# Authors:                                                                                                     #\n# Kenny Young (kjyoung@ualberta.ca)                                                                            #\n# Tian Tian (ttian@ualberta.ca)                                                                                #\n################################################################################################################\nimport numpy as np\n\n\n#####################################################################################################################\n# Env\n#\n# The player controls a paddle on the bottom of the screen and must bounce a ball tobreak 3 rows of bricks along the\n# top of the screen. A reward of +1 is given for each brick broken by the ball.  When all bricks are cleared another 3\n# rows are added. The ball travels only along diagonals, when it hits the paddle it is bounced either to the left or\n# right depending on the side of the paddle hit, when it hits a wall or brick it is reflected. Termination occurs when\n# the ball hits the bottom of the screen. The balls direction is indicated by a trail channel.\n#\n#####################################################################################################################\nclass Env:\n    def __init__(self, ramping=None):\n        self.channels ={\n            'paddle':0,\n            'ball':1,\n            'trail':2,\n            'brick':3,\n        }\n        self.action_map = ['n','l','u','r','d','f']\n        self.random = np.random.RandomState()\n        self.reset()\n\n    # Update environment according to agent action\n    def act(self, a):\n        r = 0\n        if(self.terminal):\n            return r, self.terminal\n\n        a = self.action_map[a]\n\n        # Resolve player action\n        if(a=='l'):\n            self.pos = max(0, self.pos-1)\n        elif(a=='r'):\n            self.pos = min(9,self.pos+1)\n\n        # Update ball position\n        self.last_x = self.ball_x\n        self.last_y = self.ball_y\n        if(self.ball_dir == 0):\n            new_x = self.ball_x-1\n            new_y = self.ball_y-1\n        elif(self.ball_dir == 1):\n            new_x = self.ball_x+1\n            new_y = self.ball_y-1\n        elif(self.ball_dir == 2):\n            new_x = self.ball_x+1\n            new_y = self.ball_y+1\n        elif(self.ball_dir == 3):\n            new_x = self.ball_x-1\n            new_y = self.ball_y+1\n\n        strike_toggle = False\n        if(new_x<0 or new_x>9):\n            if(new_x<0):\n                new_x = 0\n            if(new_x>9):\n                new_x=9\n            self.ball_dir=[1,0,3,2][self.ball_dir]\n        if(new_y<0):\n            new_y = 0\n            self.ball_dir=[3,2,1,0][self.ball_dir]\n        elif(self.brick_map[new_y,new_x]==1):\n            strike_toggle = True\n            if(not self.strike):\n                r+=1\n                self.strike = True\n                self.brick_map[new_y,new_x]=0\n                new_y = self.last_y\n                self.ball_dir=[3,2,1,0][self.ball_dir]\n        elif(new_y == 9):\n            if(np.count_nonzero(self.brick_map)==0):\n                self.brick_map[1:4,:] = 1\n            if(self.ball_x == self.pos):\n                self.ball_dir=[3,2,1,0][self.ball_dir]\n                new_y = self.last_y\n            elif(new_x == self.pos):\n                self.ball_dir=[2,3,0,1][self.ball_dir]\n                new_y = self.last_y\n            else:\n                self.terminal = True\n\n        if(not strike_toggle):\n            self.strike = False\n\n        self.ball_x = new_x\n        self.ball_y = new_y\n        return r, self.terminal\n\n    # Query the current level of the difficulty ramp, difficulty does not ramp in this game, so return None\n    def difficulty_ramp(self):\n        return None\n\n    # Process the game-state into the 10x10xn state provided to the agent and return\n    def state(self):\n        state = np.zeros((10,10,len(self.channels)),dtype=bool)\n        state[self.ball_y,self.ball_x,self.channels['ball']] = 1\n        state[9,self.pos, self.channels['paddle']] = 1\n        state[self.last_y,self.last_x,self.channels['trail']] = 1\n        state[:,:,self.channels['brick']] = self.brick_map\n        return state\n\n    # Reset to start state for new episode\n    def reset(self):\n        self.ball_y = 3\n        ball_start = self.random.randint(2)\n        self.ball_x, self.ball_dir = [(0,2),(9,3)][ball_start]\n        self.pos = 4\n        self.brick_map = np.zeros((10,10))\n        self.brick_map[1:4,:] = 1\n        self.strike = False\n        self.last_x = self.ball_x\n        self.last_y = self.ball_y\n        self.terminal = False\n\n    # Dimensionality of the game-state (10x10xn)\n    def state_shape(self):\n        return [10,10,len(self.channels)]\n\n    # Subset of actions that actually have a unique impact in this environment\n    def minimal_action_set(self):\n        minimal_actions = ['n','l','r']\n        return [self.action_map.index(x) for x in minimal_actions]\n\n```\n\nInput: a row-major 10x10x6 binary grid. Index `(row * 10 + column) * 6 + channel`. Channels: player=paddle; danger=empty; reward=brick; projectile=ball; trail=trail; gauge=empty.\n\nNetwork: `h1=tanh(x@W1+b1)`, `h2=tanh(h1@W2+b2)`, `logits=h2@W3+b3`. Shapes are W1 600x32, b1 32, W2 32x32, b2 32, W3 32x6, b3 6. All 20,486 values start at zero.\n\nThe hidden evaluator runs 1,000 fixed-seed episodes, stopping each after 10,000 steps. It divides mean game score by the game's fixed cap and clips the result to [0, 1].\n\nThe final fenced block must start with `edits`. It may contain numeric assignments to indexed entries or slices of W1, b1, W2, b2, W3, and b3. Half-open Python slices and numeric lists are supported, as are `*=`, `+=`, and `-=`. Values must be finite and have absolute value at most 1e6. Example:\n```edits\nW1[12, 0] = 2.5\nb1[0:4] = -1\nW2[0:2, 0:3] = [[1, -1, 0.5], [0, 2, 0]]\nW3[:, 2] *= 2\n```\n", "system_prompt": "You directly program neural-network weights. Follow the task constraints exactly.", "episodes": 1000, "task_id": 241, "family": "minatar_original", "upstream_source_url": "https://pypi.org/project/MinAtar/1.0.15/", "upstream_revision": "MinAtar==1.0.15", "native_source_url": null}
{"name": "freeway", "split": "test", "game": "freeway", "source": "original", "prompt": "Write from scratch the weights of a policy network that plays Freeway as well as possible.\n\nThere is no training, data, loss, gradients, fine-tuning, code execution, calculator, or environment feedback. This is one response. Briefly describe the strategy and hidden units, then provide the weights in the final `edits` code block.\n\nMove the chicken upward through traffic and score each time it reaches the top.\n\nActions are sampled from softmax logits and have sticky-action probability 0.1.\n\nExact MinAtar 1.0.15 source (`minatar/environments/freeway.py`):\n```python\n################################################################################################################\n# Authors:                                                                                                     #\n# Kenny Young (kjyoung@ualberta.ca)                                                                            #\n# Tian Tian (ttian@ualberta.ca)                                                                                #\n################################################################################################################\nimport numpy as np\n\n\n#####################################################################################################################\n# Constants\n#\n#####################################################################################################################\nplayer_speed = 3\ntime_limit = 2500\n\n\n#####################################################################################################################\n# Env\n#\n# The player begins at the bottom of the screen and motion is restricted to traveling up and down. Player speed is\n# also restricted such that the player can only move every 3 frames. A reward of +1 is given when the player reaches\n# the top of the screen, at which point the player is returned to the bottom. Cars travel horizontally on the screen\n# and teleport to the other side when the edge is reached. When hit by a car, the player is returned to the bottom of\n# the screen. Car direction and speed is indicated by 5 trail channels, the location of the trail gives direction\n# while the specific channel indicates how frequently the car moves (from once every frame to once every 5 frames).\n# Each time the player successfully reaches the top of the screen, the car speeds are randomized. Termination occurs\n# after 2500 frames have elapsed.\n#\n#####################################################################################################################\nclass Env:\n    def __init__(self, ramping=None):\n        self.channels ={\n            'chicken':0,\n            'car':1,\n            'speed1':2,\n            'speed2':3,\n            'speed3':4,\n            'speed4':5,\n            'speed5':6,\n        }\n        self.action_map = ['n','l','u','r','d','f']\n        self.random = np.random.RandomState()\n        self.reset()\n\n    # Update environment according to agent action\n    def act(self, a):\n        r = 0\n        if(self.terminal):\n            return r, self.terminal\n\n        a = self.action_map[a]\n\n        if(a=='u' and self.move_timer==0):\n            self.move_timer = player_speed\n            self.pos = max(0, self.pos-1)\n        elif(a=='d' and self.move_timer==0):\n            self.move_timer = player_speed\n            self.pos = min(9, self.pos+1)\n\n        # Win condition\n        if(self.pos==0):\n            r+=1\n            self._randomize_cars(initialize=False)\n            self.pos = 9\n\n        # Update cars\n        for car in self.cars:\n            if(car[0:2]==[4,self.pos]):\n                self.pos = 9\n            if(car[2]==0):\n                car[2]=abs(car[3])\n                car[0]+=1 if car[3]>0 else -1\n                if(car[0]<0):\n                    car[0]=9\n                elif(car[0]>9):\n                    car[0]=0\n                if(car[0:2]==[4,self.pos]):\n                    self.pos = 9\n            else:\n                car[2]-=1\n\n        # Update various timers\n        self.move_timer-=self.move_timer>0\n        self.terminate_timer-=1\n        if(self.terminate_timer<0):\n            self.terminal = True\n        return r, self.terminal\n\n    # Query the current level of the difficulty ramp, difficulty does not ramp in this game, so return None\n    def difficulty_ramp(self):\n        return None\n\n    # Process the game-state into the 10x10xn state provided to the agent and return\n    def state(self):\n        state = np.zeros((10,10,len(self.channels)),dtype=bool)\n        state[self.pos,4,self.channels['chicken']] = 1\n        for car in self.cars:\n            state[car[1],car[0], self.channels['car']] = 1\n            back_x = car[0]-1 if car[3]>0 else car[0]+1\n            if(back_x<0):\n                back_x=9\n            elif(back_x>9):\n                back_x=0\n            if(abs(car[3])==1):\n                trail = self.channels['speed1']\n            elif(abs(car[3])==2):\n                trail = self.channels['speed2']\n            elif(abs(car[3])==3):\n                trail = self.channels['speed3']\n            elif(abs(car[3])==4):\n                trail = self.channels['speed4']\n            elif(abs(car[3])==5):\n                trail = self.channels['speed5']\n            state[car[1],back_x, trail] = 1\n        return state\n\n    # Randomize car speeds and directions, also reset their position if initialize=True\n    def _randomize_cars(self, initialize=False):\n        speeds = self.random.randint(1,6,8)\n        directions = np.sign(self.random.rand(8) - 0.5).astype(int)\n        speeds*=directions\n        if(initialize):\n            self.cars = []\n            for i in range(8):\n                self.cars+=[[0,i+1,abs(speeds[i]),speeds[i]]]\n        else:\n            for i in range(8):\n                self.cars[i][2:4]=[abs(speeds[i]),speeds[i]]\n\n    # Reset to start state for new episode\n    def reset(self):\n        self._randomize_cars(initialize=True)\n        self.pos = 9\n        self.move_timer = player_speed\n        self.terminate_timer = time_limit\n        self.terminal = False\n\n    # Dimensionality of the game-state (10x10xn)\n    def state_shape(self):\n        return [10,10,len(self.channels)]\n\n    # Subset of actions that actually have a unique impact in this environment\n    def minimal_action_set(self):\n        minimal_actions = ['n','u','d']\n        return [self.action_map.index(x) for x in minimal_actions]\n\n```\n\nInput: a row-major 10x10x6 binary grid. Index `(row * 10 + column) * 6 + channel`. Channels: player=chicken; danger=car; reward=empty; projectile=empty; trail=speed1|speed2|speed3|speed4|speed5; gauge=empty.\n\nNetwork: `h1=tanh(x@W1+b1)`, `h2=tanh(h1@W2+b2)`, `logits=h2@W3+b3`. Shapes are W1 600x32, b1 32, W2 32x32, b2 32, W3 32x6, b3 6. All 20,486 values start at zero.\n\nThe hidden evaluator runs 1,000 fixed-seed episodes, stopping each after 10,000 steps. It divides mean game score by the game's fixed cap and clips the result to [0, 1].\n\nThe final fenced block must start with `edits`. It may contain numeric assignments to indexed entries or slices of W1, b1, W2, b2, W3, and b3. Half-open Python slices and numeric lists are supported, as are `*=`, `+=`, and `-=`. Values must be finite and have absolute value at most 1e6. Example:\n```edits\nW1[12, 0] = 2.5\nb1[0:4] = -1\nW2[0:2, 0:3] = [[1, -1, 0.5], [0, 2, 0]]\nW3[:, 2] *= 2\n```\n", "system_prompt": "You directly program neural-network weights. Follow the task constraints exactly.", "episodes": 1000, "task_id": 251, "family": "minatar_original", "upstream_source_url": "https://pypi.org/project/MinAtar/1.0.15/", "upstream_revision": "MinAtar==1.0.15", "native_source_url": null}
{"name": "seaquest", "split": "test", "game": "seaquest", "source": "original", "prompt": "Write from scratch the weights of a policy network that plays Seaquest as well as possible.\n\nThere is no training, data, loss, gradients, fine-tuning, code execution, calculator, or environment feedback. This is one response. Briefly describe the strategy and hidden units, then provide the weights in the final `edits` code block.\n\nControl the submarine, shoot enemies, rescue divers, surface with divers, and manage oxygen.\n\nActions are sampled from softmax logits and have sticky-action probability 0.1.\n\nExact MinAtar 1.0.15 source (`minatar/environments/seaquest.py`):\n```python\n################################################################################################################\n# Authors:                                                                                                     #\n# Kenny Young (kjyoung@ualberta.ca)                                                                            #\n# Tian Tian (ttian@ualberta.ca)                                                                                #\n################################################################################################################\nimport numpy as np\n\n\n#####################################################################################################################\n# Constants\n#\n#####################################################################################################################\nramp_interval = 100\nmax_oxygen = 200\ninit_spawn_speed = 20\ndiver_spawn_speed = 30\ninit_move_interval = 5\nshot_cool_down = 5\nenemy_shot_interval = 10\nenemy_move_interval = 5\ndiver_move_interval = 5\n\n\n#####################################################################################################################\n# Env\n#\n# The player controls a submarine consisting of two cells, front and back, to allow direction to be determined. The\n# player can also fire bullets from the front of the submarine. Enemies consist of submarines and fish, distinguished\n# by the fact that submarines shoot bullets and fish do not. A reward of +1 is given each time an enemy is struck by\n# one of the player's bullets, at which point the enemy is also removed. There are also divers which the player can\n# move onto to pick up, doing so increments a bar indicated by another channel along the bottom of the screen. The\n# player also has a limited supply of oxygen indicated by another bar in another channel. Oxygen degrades over time,\n# and is replenished whenever the player moves to the top of the screen as long as the player has at least one rescued\n# diver on board. The player can carry a maximum of 6 divers. When surfacing with less than 6, one diver is removed.\n# When surfacing with 6, all divers are removed and a reward is given for each active cell in the oxygen bar. Each\n# time the player surfaces the difficulty is increased by increasing the spawn rate and movement speed of enemies.\n# Termination occurs when the player is hit by an enemy fish, sub or bullet; or when oxygen reached 0; or when the\n# player attempts to surface with no rescued divers. Enemy and diver directions are indicated by a trail channel\n# active in their previous location to reduce partial observability.\n#\n#####################################################################################################################\nclass Env:\n    def __init__(self, ramping=True):\n        self.channels ={\n            'sub_front':0,\n            'sub_back':1,\n            'friendly_bullet':2,\n            'trail':3,\n            'enemy_bullet':4,\n            'enemy_fish':5,\n            'enemy_sub':6,\n            'oxygen_guage':7,\n            'diver_guage':8,\n            'diver':9\n        }\n        self.action_map = ['n','l','u','r','d','f']\n        self.ramping = ramping\n        self.random = np.random.RandomState()\n        self.reset()\n\n    # Update environment according to agent action\n    def act(self, a):\n        r = 0\n        if(self.terminal):\n            return r, self.terminal\n\n        a = self.action_map[a]\n\n        # Spawn enemy if timer is up\n        if(self.e_spawn_timer==0):\n            self._spawn_enemy()\n            self.e_spawn_timer = self.e_spawn_speed\n\n        if(self.d_spawn_timer==0):\n            self._spawn_diver()\n            self.d_spawn_timer = diver_spawn_speed\n\n        # Resolve player action\n        if(a=='f' and self.shot_timer == 0):\n            self.f_bullets+=[[self.sub_x, self.sub_y, self.sub_or]]\n            self.shot_timer = shot_cool_down\n        elif(a=='l'):\n            self.sub_x = max(0, self.sub_x-1)\n            self.sub_or = False\n        elif(a=='r'):\n            self.sub_x = min(9, self.sub_x+1)\n            self.sub_or = True\n        elif(a=='u'):\n            self.sub_y = max(0, self.sub_y-1)\n        elif(a=='d'):\n            self.sub_y = min(8, self.sub_y+1)\n\n        # Update friendly Bullets\n        for bullet in reversed(self.f_bullets):\n            bullet[0]+=1 if bullet[2] else -1\n            if(bullet[0]<0 or bullet[0]>9):\n                self.f_bullets.remove(bullet)\n            else:\n                removed = False\n                for x in self.e_fish:\n                    if(bullet[0:2]==x[0:2]):\n                        self.e_fish.remove(x)\n                        self.f_bullets.remove(bullet)\n                        r+=1\n                        removed = True\n                        break\n                if(not removed):\n                    for x in self.e_subs:\n                        if(bullet[0:2]==x[0:2]):\n                            self.e_subs.remove(x)\n                            self.f_bullets.remove(bullet)\n                            r+=1\n                            break\n\n        # Update divers\n        for diver in reversed(self.divers):\n            if(diver[0:2]==[self.sub_x,self.sub_y] and self.diver_count<6):\n                self.divers.remove(diver)\n                self.diver_count+=1\n            else:\n                if(diver[3]==0):\n                    diver[3]=diver_move_interval\n                    diver[0]+=1 if diver[2] else -1\n                    if(diver[0]<0 or diver[0]>9):\n                        self.divers.remove(diver)\n                    elif(diver[0:2]==[self.sub_x,self.sub_y] and self.diver_count<6):\n                        self.divers.remove(diver)\n                        self.diver_count+=1\n                else:\n                    diver[3]-=1\n\n        # Update enemy subs\n        for sub in reversed(self.e_subs):\n            if(sub[0:2]==[self.sub_x,self.sub_y]):\n                self.terminal = True\n            if(sub[3]==0):\n                sub[3]=self.move_speed\n                sub[0]+=1 if sub[2] else -1\n                if(sub[0]<0 or sub[0]>9):\n                    self.e_subs.remove(sub)\n                elif(sub[0:2]==[self.sub_x,self.sub_y]):\n                    self.terminal = True\n                else:\n                    for x in self.f_bullets:\n                        if(sub[0:2]==x[0:2]):\n                            self.e_subs.remove(sub)\n                            self.f_bullets.remove(x)\n                            r+=1\n                            break\n            else:\n                sub[3]-=1\n            if(sub[4]==0):\n                sub[4]=enemy_shot_interval\n                self.e_bullets+=[[sub[0] if sub[2] else sub[0], sub[1], sub[2]]]\n            else:\n                sub[4]-=1\n\n        # Update enemy bullets\n        for bullet in reversed(self.e_bullets):\n            if(bullet[0:2]==[self.sub_x,self.sub_y]):\n                self.terminal = True\n            bullet[0]+=1 if bullet[2] else -1\n            if(bullet[0]<0 or bullet[0]>9):\n                self.e_bullets.remove(bullet)\n            else:\n                if(bullet[0:2]==[self.sub_x,self.sub_y]):\n                    self.terminal = True\n\n        # Update enemy fish\n        for fish in reversed(self.e_fish):\n            if(fish[0:2]==[self.sub_x,self.sub_y]):\n                self.terminal = True\n            if(fish[3]==0):\n                fish[3]=self.move_speed\n                fish[0]+=1 if fish[2] else -1\n                if(fish[0]<0 or fish[0]>9):\n                    self.e_fish.remove(fish)\n                elif(fish[0:2]==[self.sub_x,self.sub_y]):\n                    self.terminal = True\n                else:\n                    for x in self.f_bullets:\n                        if(fish[0:2]==x[0:2]):\n                            self.e_fish.remove(fish)\n                            self.f_bullets.remove(x)\n                            r+=1\n                            break\n            else:\n                fish[3]-=1\n\n        # Update various timers\n        self.e_spawn_timer -= self.e_spawn_timer>0\n        self.d_spawn_timer -= self.d_spawn_timer>0\n        self.shot_timer -= self.shot_timer>0\n        if(self.oxygen<=0):\n            self.terminal = True\n        if(self.sub_y>0):\n            self.oxygen-=1\n            self.surface = False\n        else:\n            if(not self.surface):\n                if(self.diver_count == 0):\n                    self.terminal = True\n                else:\n                    r+=self._surface()\n        return r, self.terminal\n\n    # Called when player hits surface (top row) if they have no divers, this ends the game,\n    # if they have 6 divers this gives reward proportional to the remaining oxygen and restores full oxygen\n    # otherwise this reduces the number of divers and restores full oxygen\n    def _surface(self):\n        self.surface = True\n        if(self.diver_count == 6):\n            self.diver_count = 0\n            r = self.oxygen*10//max_oxygen\n        else:\n            r = 0\n        self.oxygen = max_oxygen\n        self.diver_count -= 1\n        if self.ramping and (self.e_spawn_speed>1 or self.move_speed>2):\n            if(self.move_speed>2 and self.ramp_index%2):\n                    self.move_speed-=1\n            if(self.e_spawn_speed>1):\n                    self.e_spawn_speed-=1\n            self.ramp_index+=1\n        return r\n\n    # Spawn an enemy fish or submarine in random row and random direction,\n    # if the resulting row and direction would lead to a collision, do nothing instead\n    def _spawn_enemy(self):\n        lr = self.random.rand() < 1/2\n        is_sub = self.random.rand() < 1/3\n        x = 0 if lr else 9\n        y = self.random.randint(low=1, high=9)\n\n        # Do not spawn in same row an opposite direction as existing\n        if(any([z[1]==y and z[2]!=lr for z in self.e_subs+self.e_fish])):\n            return\n        if(is_sub):\n            self.e_subs+=[[x,y,lr,self.move_speed,enemy_shot_interval]]\n        else:\n            self.e_fish+=[[x,y,lr,self.move_speed]]\n\n    # Spawn a diver in random row with random direction\n    def _spawn_diver(self):\n        lr = self.random.rand() < 1/2\n        x = 0 if lr else 9\n        y = self.random.randint(low=1, high=9)\n        self.divers+=[[x,y,lr,diver_move_interval]]\n\n    # Query the current level of the difficulty ramp, could be used as additional input to agent for example\n    def difficulty_ramp(self):\n        return self.ramp_index\n\n    # Process the game-state into the 10x10xn state provided to the agent and return\n    def state(self):\n        state = np.zeros((10,10,len(self.channels)),dtype=bool)\n        state[self.sub_y,self.sub_x,self.channels['sub_front']] = 1\n        back_x = self.sub_x-1 if self.sub_or else self.sub_x+1\n        state[self.sub_y,back_x,self.channels['sub_back']] = 1\n        state[9,0:max(0,self.oxygen)*10//max_oxygen, self.channels['oxygen_guage']] = 1\n        state[9,9-self.diver_count:9, self.channels['diver_guage']] = 1\n        for bullet in self.f_bullets:\n            state[bullet[1],bullet[0], self.channels['friendly_bullet']] = 1\n        for bullet in self.e_bullets:\n            state[bullet[1],bullet[0], self.channels['enemy_bullet']] = 1\n        for fish in self.e_fish:\n            state[fish[1],fish[0], self.channels['enemy_fish']] = 1\n            back_x = fish[0]-1 if fish[2] else fish[0]+1\n            if(back_x>=0 and back_x<=9):\n                state[fish[1],back_x, self.channels['trail']] = 1\n        for sub in self.e_subs:\n            state[sub[1],sub[0], self.channels['enemy_sub']] = 1\n            back_x = sub[0]-1 if sub[2] else sub[0]+1\n            if(back_x>=0 and back_x<=9):\n                state[sub[1],back_x, self.channels['trail']] = 1\n        for diver in self.divers:\n            state[diver[1],diver[0], self.channels['diver']] = 1\n            back_x = diver[0]-1 if diver[2] else diver[0]+1\n            if(back_x>=0 and back_x<=9):\n                state[diver[1],back_x, self.channels['trail']] = 1\n\n        return state\n\n    # Reset to start state for new episode\n    def reset(self):\n        self.oxygen = max_oxygen\n        self.diver_count = 0\n        self.sub_x = 5\n        self.sub_y = 0\n        # 0=left, 1=right\n        self.sub_or = False\n        self.f_bullets = []\n        self.e_bullets = []\n        self.e_fish = []\n        self.e_subs = []\n        self.divers = []\n        self.e_spawn_speed = init_spawn_speed\n        self.e_spawn_timer = self.e_spawn_speed\n        self.d_spawn_timer = diver_spawn_speed\n        self.move_speed = init_move_interval\n        self.ramp_index = 0\n        self.shot_timer = 0\n        self.surface = True\n        self.terminal = False\n\n    # Dimensionality of the game-state (10x10xn)\n    def state_shape(self):\n        return [10,10,len(self.channels)]\n\n    # Subset of actions that actually have a unique impact in this environment\n    def minimal_action_set(self):\n        minimal_actions = ['n','l','u','r','d','f']\n        return [self.action_map.index(x) for x in minimal_actions]\n\n```\n\nInput: a row-major 10x10x6 binary grid. Index `(row * 10 + column) * 6 + channel`. Channels: player=sub_front|sub_back; danger=enemy_fish|enemy_sub|enemy_bullet; reward=enemy_fish|enemy_sub|diver; projectile=friendly_bullet; trail=trail|sub_back; gauge=oxygen_guage|diver_guage.\n\nNetwork: `h1=tanh(x@W1+b1)`, `h2=tanh(h1@W2+b2)`, `logits=h2@W3+b3`. Shapes are W1 600x32, b1 32, W2 32x32, b2 32, W3 32x6, b3 6. All 20,486 values start at zero.\n\nThe hidden evaluator runs 1,000 fixed-seed episodes, stopping each after 10,000 steps. It divides mean game score by the game's fixed cap and clips the result to [0, 1].\n\nThe final fenced block must start with `edits`. It may contain numeric assignments to indexed entries or slices of W1, b1, W2, b2, W3, and b3. Half-open Python slices and numeric lists are supported, as are `*=`, `+=`, and `-=`. Values must be finite and have absolute value at most 1e6. Example:\n```edits\nW1[12, 0] = 2.5\nb1[0:4] = -1\nW2[0:2, 0:3] = [[1, -1, 0.5], [0, 2, 0]]\nW3[:, 2] *= 2\n```\n", "system_prompt": "You directly program neural-network weights. Follow the task constraints exactly.", "episodes": 1000, "task_id": 270, "family": "minatar_original", "upstream_source_url": "https://pypi.org/project/MinAtar/1.0.15/", "upstream_revision": "MinAtar==1.0.15", "native_source_url": null}
{"name": "asterix", "split": "test", "game": "asterix", "source": "original", "prompt": "Write from scratch the weights of a policy network that plays Asterix as well as possible.\n\nThere is no training, data, loss, gradients, fine-tuning, code execution, calculator, or environment feedback. This is one response. Briefly describe the strategy and hidden units, then provide the weights in the final `edits` code block.\n\nMove in four directions to collect treasure while avoiding horizontally moving enemies.\n\nActions are sampled from softmax logits and have sticky-action probability 0.1.\n\nExact MinAtar 1.0.15 source (`minatar/environments/asterix.py`):\n```python\n################################################################################################################\n# Authors:                                                                                                     #\n# Kenny Young (kjyoung@ualberta.ca)                                                                            #\n# Tian Tian (ttian@ualberta.ca)                                                                                #\n################################################################################################################\nimport numpy as np\n\n\n#####################################################################################################################\n# Constants\n#\n#####################################################################################################################\nramp_interval = 100\ninit_spawn_speed = 10\ninit_move_interval = 5\nshot_cool_down = 5\n\n\n#####################################################################################################################\n# Env\n#\n# The player can move freely along the 4 cardinal directions. Enemies and treasure spawn from the sides. A reward of\n# +1 is given for picking up treasure. Termination occurs if the player makes contact with an enemy. Enemy and\n# treasure direction are indicated by a trail channel. Difficulty is periodically increased by increasing the speed\n# and spawn rate of enemies and treasure.\n#\n#####################################################################################################################\nclass Env:\n    def __init__(self, ramping=True):\n        self.channels ={\n            'player':0,\n            'enemy':1,\n            'trail':2,\n            'gold':3\n        }\n        self.action_map = ['n','l','u','r','d','f']\n        self.ramping = ramping\n        self.random = np.random.RandomState()\n        self.reset()\n\n    # Update environment according to agent action\n    def act(self, a):\n        r = 0\n        if(self.terminal):\n            return r, self.terminal\n\n        a = self.action_map[a]\n\n        # Spawn enemy if timer is up\n        if(self.spawn_timer==0):\n            self._spawn_entity()\n            self.spawn_timer = self.spawn_speed\n\n        # Resolve player action\n        if(a=='l'):\n            self.player_x = max(0, self.player_x-1)\n        elif(a=='r'):\n            self.player_x = min(9, self.player_x+1)\n        elif(a=='u'):\n            self.player_y = max(1, self.player_y-1)\n        elif(a=='d'):\n            self.player_y = min(8, self.player_y+1)\n\n        # Update entities\n        for i in range(len(self.entities)):\n            x = self.entities[i]\n            if(x is not None):\n                if(x[0:2]==[self.player_x,self.player_y]):\n                    if(self.entities[i][3]):\n                        self.entities[i] = None\n                        r+=1\n                    else:\n                        self.terminal = True\n        if(self.move_timer==0):\n            self.move_timer = self.move_speed\n            for i in range(len(self.entities)):\n                x = self.entities[i]\n                if(x is not None):\n                    x[0]+=1 if x[2] else -1\n                    if(x[0]<0 or x[0]>9):\n                        self.entities[i] = None\n                    if(x[0:2]==[self.player_x,self.player_y]):\n                        if(self.entities[i][3]):\n                            self.entities[i] = None\n                            r+=1\n                        else:\n                            self.terminal = True\n\n        # Update various timers\n        self.spawn_timer -= 1\n        self.move_timer -= 1\n\n\n        #Ramp difficulty if interval has elapsed\n        if self.ramping and (self.spawn_speed>1 or self.move_speed>1):\n            if(self.ramp_timer>=0):\n                self.ramp_timer-=1\n            else:\n                if(self.move_speed>1 and self.ramp_index%2):\n                    self.move_speed-=1\n                if(self.spawn_speed>1):\n                    self.spawn_speed-=1\n                self.ramp_index+=1\n                self.ramp_timer=ramp_interval\n        return r, self.terminal\n\n    # Spawn a new enemy or treasure at a random location with random direction (if all rows are filled do nothing)\n    def _spawn_entity(self):\n        lr = self.random.rand() < 1/2\n        is_gold = self.random.rand() < 1/3\n        x = 0 if lr else 9\n        slot_options = [i for i in range(len(self.entities)) if self.entities[i]==None]\n        if(not slot_options):\n            return\n        slot = slot_options[self.random.randint(len(slot_options))]\n        self.entities[slot] = [x,slot+1,lr,is_gold]\n\n    # Query the current level of the difficulty ramp, could be used as additional input to agent for example\n    def difficulty_ramp(self):\n        return self.ramp_index\n\n    # Process the game-state into the 10x10xn state provided to the agent and return\n    def state(self):\n        state = np.zeros((10,10,len(self.channels)),dtype=bool)\n        state[self.player_y,self.player_x,self.channels['player']] = 1\n        for x in self.entities:\n            if(x is not None):\n                c = self.channels['gold'] if x[3] else self.channels['enemy']\n                state[x[1], x[0],c] = 1\n                back_x = x[0]-1 if x[2] else x[0]+1\n                if(back_x>=0 and back_x<=9):\n                    state[x[1], back_x, self.channels['trail']] = 1\n        return state\n\n    # Reset to start state for new episode\n    def reset(self):\n        self.player_x = 5\n        self.player_y = 5\n        self.entities = [None]*8\n        self.shot_timer = 0\n        self.spawn_speed = init_spawn_speed\n        self.spawn_timer = self.spawn_speed\n        self.move_speed = init_move_interval\n        self.move_timer = self.move_speed\n        self.ramp_timer = ramp_interval\n        self.ramp_index = 0\n        self.terminal = False\n\n    # Dimensionality of the game-state (10x10xn)\n    def state_shape(self):\n        return [10,10,len(self.channels)]\n\n    # Subset of actions that actually have a unique impact in this environment\n    def minimal_action_set(self):\n        minimal_actions = ['n','l','u','r','d']\n        return [self.action_map.index(x) for x in minimal_actions]\n\n```\n\nInput: a row-major 10x10x6 binary grid. Index `(row * 10 + column) * 6 + channel`. Channels: player=player; danger=enemy; reward=gold; projectile=empty; trail=trail; gauge=empty.\n\nNetwork: `h1=tanh(x@W1+b1)`, `h2=tanh(h1@W2+b2)`, `logits=h2@W3+b3`. Shapes are W1 600x32, b1 32, W2 32x32, b2 32, W3 32x6, b3 6. All 20,486 values start at zero.\n\nThe hidden evaluator runs 1,000 fixed-seed episodes, stopping each after 10,000 steps. It divides mean game score by the game's fixed cap and clips the result to [0, 1].\n\nThe final fenced block must start with `edits`. It may contain numeric assignments to indexed entries or slices of W1, b1, W2, b2, W3, and b3. Half-open Python slices and numeric lists are supported, as are `*=`, `+=`, and `-=`. Values must be finite and have absolute value at most 1e6. Example:\n```edits\nW1[12, 0] = 2.5\nb1[0:4] = -1\nW2[0:2, 0:3] = [[1, -1, 0.5], [0, 2, 0]]\nW3[:, 2] *= 2\n```\n", "system_prompt": "You directly program neural-network weights. Follow the task constraints exactly.", "episodes": 1000, "task_id": 278, "family": "minatar_original", "upstream_source_url": "https://pypi.org/project/MinAtar/1.0.15/", "upstream_revision": "MinAtar==1.0.15", "native_source_url": null}