def _move_right(self): new_state = self.state() original_cells = self._current_state['grid']['cells'] for row_num in range(0, 4): row = [ cell_value(original_cells[3][row_num]), cell_value(original_cells[2][row_num]), cell_value(original_cells[1][row_num]), cell_value(original_cells[0][row_num]) ] transformed_row, value_add = Game._left_move_from_cache(row) new_entries = [ None if value == 0 else { 'position': { 'x': index, 'y': row_num }, 'value': value } for index, value in enumerate(transformed_row) ] new_state['grid']['cells'][3][row_num] = new_entries[0] new_state['grid']['cells'][2][row_num] = new_entries[1] new_state['grid']['cells'][1][row_num] = new_entries[2] new_state['grid']['cells'][0][row_num] = new_entries[3] new_state['score'] = new_state['score'] + value_add return new_state
async def apply(oracle, state, weight): cells = state['grid']['cells'] adjacent_matches = 0 for col_num in range(0, 4): if cell_value(cells[col_num][0]) == cell_value(cells[col_num][1]): adjacent_matches = adjacent_matches + 1 if cell_value(cells[col_num][1]) == cell_value(cells[col_num][2]): adjacent_matches = adjacent_matches + 1 if cell_value(cells[col_num][2]) == cell_value(cells[col_num][3]): adjacent_matches = adjacent_matches + 1 for row_num in range(0, 4): if cell_value(cells[0][row_num]) == cell_value(cells[1][row_num]): adjacent_matches = adjacent_matches + 1 if cell_value(cells[1][row_num]) == cell_value(cells[2][row_num]): adjacent_matches = adjacent_matches + 1 if cell_value(cells[2][row_num]) == cell_value(cells[3][row_num]): adjacent_matches = adjacent_matches + 1 if adjacent_matches == 0: return -1 * weight return adjacent_matches * weight