def mm_test(landing_height, eroded_cells, row_trans, col_trans, pits, cuml_wells, pit_depth, pit_rows): controller = { "landing_height": landing_height, "eroded_cells": eroded_cells, "row_trans": row_trans, "col_trans": col_trans, "pits": pits, "cuml_wells":cuml_wells, "pit_depth": pit_depth, "pit_rows": pit_rows } osim = TetrisSimulator( controller=controller, board=tetris_cow2(), curr=all_zoids["L"], next=all_zoids["S"], show_choice=False, show_scores=False, show_options=False, show_result=False, seed=1 ) return osim.run()
def get_features(board, zoid_str, controller, dictionaries=True): """ Given a board (with list of list representation), future zoid, and controller, this function returns the set of all possible options and their feature values. Params: board - [[int]] - list of list representation of board zoid_str - string - string value for a zoid (e.g. "T") controller - {string: int} - dictionary controller for a simulator If dictionaries=True then it will return it as a series of nested dictionaries organized as: return_val[orientation][row][col] = {zoid: '', board: [[]], features: {}} If dictionaries=False then it will return it as a list of dictionaries, with one dictionary for each option/feature set: return_val = [{'zoid': zoid, 'orient': orientation, 'row': row, 'col': col, 'board': [[]], 'features': {}}] """ sim = TetrisSimulator(controller=controller) sim.space = tetris_cow2.convert_old_board(board) sim.curr_z = all_zoids[zoid_str] if dictionaries == True: # Return all features as an organized dictionary structure all_feats = {} for orient, pos in sim.get_options(): if orient not in all_feats.keys(): all_feats[orient] = {} if pos[0] not in all_feats[orient].keys(): all_feats[orient][pos[0]] = {} zoid = sim.curr_z.get_copy() board = sim.space.get_cow() # Not really sure what the value=2 does, but was used in simulator.py board.imprint_zoid(zoid, orient=orient, pos=pos, value=2) board_and_feats = { 'zoid': zoid_str, 'board': board.row_space(), 'features': sim.get_features(board, sim.space) } all_feats[orient][pos[0]][pos[1]] = board_and_feats return all_feats else: all_feats = [] for orient, pos in sim.get_options(): option = {} zoid = sim.curr_z.get_copy() option['zoid'] = zoid_str option['row'] = pos[0] option['col'] = pos[1] option['orient'] = orient board = sim.space.get_cow() board.imprint_zoid(zoid, orient=orient, pos=pos, value=2) option['board'] = board.row_space() option['features'] = sim.get_features(board, sim.space) all_feats.append(option) return all_feats
def test_perfect_fit(self): """ Tests if a single overhang move option is correctly identified :return: None """ raw_board = [[1, 1, 1, 1, 0, 0, 1, 1, 1, 1], [1, 1, 1, 0, 0, 0, 0, 1, 1, 1], [1, 1, 1, 1, 0, 0, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]] board = tetris_cow2.convert_old_board(fill_board_with_zeros(raw_board)) sim = TetrisSimulator(curr=all_zoids["T"], board=board, overhangs=True) # ensure simulator correctly identifies overhang spaces self.assertDictEqual({3: [2], 6: [2]}, sim.get_overhangs()) # ensure additional overhang moves are present sim_overhangs = set(sim.possible_moves_overhangs()) - set( sim.possible_moves()) self.assertSetEqual({(1, (1, 3)), (3, (1, 5))}, sim_overhangs)
#session_vars, name, features, controller, vars = False, outs = False results = [] for a in range(0, controllers): random_controller = generate_controller(start_controller, tolerances, rng=rng) controller_name = "G" + str(x + 1) + "_" + str(a + 1) game_seed = rng.randint(0, 100000) sim = TetrisSimulator(controller=random_controller, show_choice=show_choice, show_result=show_result, choice_step=v_step, name=controller_name, seed=game_seed) sim_result = sim.run(max_eps=episodes, printstep=report_every) #session_vars, name, features, controller, vars = False, outs = False write_controller(outfile, session_variables, controller_name, features, random_controller, outs=sim_result, game_seed=game_seed, type="search", gen=x + 1, num=a + 1,
line = lines[x] if x == 0: player_board = [[0]*10 for i in range(20)] else: prev_line = lines[x - 1] prev_line = prev_line.rstrip().split('\t') player_board = eval(eval(prev_line[board_ix])) line = line.rstrip().split('\t') if line[curr_zoid_ix] != 'NA': player_zoid = line[curr_zoid_ix] working_controller = CERLscore working_features = CERLscore.keys() sim = TetrisSimulator(controller=working_controller) sim.space = tetris_cow2.convert_old_board(player_board) sim.curr_z = all_zoids[player_zoid] feats = get_features(player_board, player_zoid, working_controller, dictionaries=False) for f in feats: lh_val = f['features']['landing_height'] * working_controller['landing_height'] ec_val = f['features']['eroded_cells'] * working_controller['eroded_cells'] rt_val = f['features']['row_trans'] * working_controller['row_trans'] ct_val = f['features']['col_trans'] * working_controller['col_trans'] pit_val = f['features']['pits'] * working_controller['pits'] wells_val = f['features']['cuml_wells'] * working_controller['cuml_wells'] move_score = lh_val + ec_val + rt_val + ct_val + pit_val + wells_val