def get_best_moves(self): scores = [] first_empty = simulate.first_empty_row(self.grid) if first_empty == -1: return if show_debug: print("Simulate First empty row",first_empty) for y in range(len(self.grid)-1, first_empty-1, -1): for x in range(len(self.grid[y])-len(self.block[0])+1): s = self.try_place(y, x, self.grid) if s != None: s.append(self.block) scores.append(s) if show_debug: print("Simulate Printing s") print(s) if show_debug: print("Simulate These are the scores:") for i in scores: print(i[0:2]) print('Simulate This is what is being returned') print(final(scores)) print(scores) if len(scores) > 0: return final(scores, self.mode) else: return
def play(): WIDTH = 8 HEIGHT = 20 grid = [[0 for w in range(WIDTH)] for h in range(HEIGHT)] ##Default 8x20 Grid # grid = [[0, 0, 0, 0, 0, 0, 0, 0], #Custom grid for testing # [0, 0, 0, 0, 0, 0, 0, 0], # [0, 0, 0, 0, 0, 0, 0, 0], # [0, 0, 0, 0, 0, 0, 0, 0], # [0, 0, 0, 0, 0, 0, 0, 0], # [0, 0, 0, 0, 0, 0, 0, 0], # [0, 0, 0, 1, 1, 1, 1, 0], # [1, 1, 1, 1, 1, 1, 1, 1], # [1, 1, 1, 1, 1, 1, 1, 1]] print("Press any key to simulate a round with a random block") print("Pressing the lowercase name of a block will generate said block") print("Press 'q' to exit") while True: c,removed = 0,0 block = get_command() #BEST IS IN THE FORM OF: #[columns-removed_rows, HOLES, removed_rows, [y_c,x_c]] best = best_move.single_best_move(block, grid, float(HEIGHT-1-simulate.first_empty_row(grid))/float(HEIGHT-1)) if best != None: new_grid = simulate.place(best[3][0], best[3][1], grid, best[4], block.type(), "dc") instructions.get_moves(new_grid, grid,best[4], best[3]) if show_debug: print("Move:") print(best[0:4]) print("Before fall:") debug.show(new_grid) grid = simulate.drop_lines(new_grid) # if show_debug: # print("After fall:") # debug.show(grid) # removed += best[2] # c +=1 # print"Combo", best[2] # print"Removed", removed # print"Height", best[0] # print"Round",c else: print "Game over" return