def try_place(self, y, x, grid):
     grid = simulate.place(y, x, grid, self.block, 2, 'dc')
     if grid != None and self.check_lowest(y, x, grid) != None:
         if show_debug:           
             print("try_place Block")
             debug.show(self.block)
             print("try_place Grid")
             debug.show(grid)
         return self.count_lines(grid, y, x)
Beispiel #2
0
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
def get_moves(new_grid,old_grid, block, coords):
    y, x = coords[0], coords[1]
    
    print("OLD:")
    debug.show(new_grid)
    
    r_left = simulate.place(y, x, old_grid, flipper.rotate_cclockwise(block), 1, "dc") != None
    r_right = simulate.place(y, x, old_grid, flipper.rotate_clockwise(block), 1, "dc") != None
    left = simulate.place(y, x-1, old_grid, block, 1, "dc") != None
    right = simulate.place(y, x+1, old_grid, block, 1, "dc") != None
    up = simulate.place(y-1, x+1, old_grid, block, 1, "dc") != None
    
    print("r_left", r_left)
    if r_left:
        debug.show(simulate.place(y, x, old_grid, flipper.rotate_cclockwise(block), 1, "dc"))
    print("r_right", r_right)
    if r_right:
        debug.show(simulate.place(y, x, old_grid, flipper.rotate_clockwise(block), 1, "dc"))
    print("l", left)
    print("r", right)
    print("u", up)