revisa el codigo y dime si es correcto: ""import random
import os

def initialize_grid():
    """Initialize a 4x4 grid with two random tiles (2 or 4)."""
    grid = [[0] * 4 for _ in range(4)]
    add_new_tile(grid)
    add_new_tile(grid)
    return grid

def add_new_tile(grid):
    """Add a new tile (2 or 4) to a random empty cell in the grid."""
    empty_cells = [(i, j) for i in range(4) for j in range(4) if grid[i][j] == 0]
    if empty_cells:
        i, j = random.choice(empty_cells)
        grid[i][j] = random.choice([2]*9 + [4])  # 90% chance of 2, 10% chance of 4

def print_grid(grid):
    """Display the current state of the grid."""
    os.system('cls' if os.name == 'nt' else 'clear')
    print("2048 Game\n")
    for row in grid:
        print('+------+------+------+------+' )
        print('|', end='')
        for val in row:
            print(f'{val:^6}|', end='') if val != 0 else print(f'{" ":^6}|', end='')
        print()
    print('+------+------+------+------+' )

def can_move(grid):
    """Check if any moves are possible."""
    for i in range(4):
        for j in range(4):
            if grid[i][j] == 0:
                return True
            if j < 3 and grid[i][j] == grid[i][j+1]:
                return True
            if i < 3 and grid[i][j] == grid[i+1][j]:
                return True
    return False

def move_left(grid):
    """Handle left swipe movement and merging logic."""
    score = 0
    new_grid = []
    for row in grid:
        non_zero = [num for num in row if num != 0]
        merged_row = []
        skip = False
        i = 0
        while i < len(non_zero):
            if not skip and i + 1 < len(non_zero) and non_zero[i] == non_zero[i+1]:
                merged_value = non_zero[i] * 2
                score += merged_value
                merged_row.append(merged_value)
                skip = True
            else:
                merged_row.append(non_zero[i])
                skip = False
            i += 1 if skip else 1
        merged_row += [0] * (4 - len(merged_row))
        new_grid.append(merged_row)
    return new_grid, score

def reverse(grid):
    """Reverse the grid rows (used for right movement)."""
    return [row[::-1] for row in grid]

def transpose(grid):
    """Transpose the grid (used for up and down movements)."""
    return [list(row) for row in zip(*grid)]

def move_right(grid):
    """Handle right swipe by reversing, moving left, then reversing again."""
    reversed_grid = reverse(grid)
    new_grid, score = move_left(reversed_grid)
    return reverse(new_grid), score

def move_up(grid):
    """Handle up swipe by transposing, moving left, then transposing again."""
    transposed_grid = transpose(grid)
    new_grid, score = move_left(transposed_grid)
    return transpose(new_grid), score

def move_down(grid):
    """Handle down swipe by transposing, reversing, moving left, then reversing and transposing back."""
    transposed_grid = transpose(grid)
    reversed_grid = reverse(transposed_grid)
    new_grid, score = move_left(reversed_grid)
    return transpose(reverse(new_grid)), score

def main():
    """Main game loop handling user input and game state."""
    grid = initialize_grid()
    total_score = 0
    while True:
        print_grid(grid)
        print(f"Score: {total_score}")
        move = input("Enter move (w/a/s/d): ").lower()
        if move not in ('w', 'a', 's', 'd'):
            continue

        if move == 'a':
            new_grid, score = move_left(grid)
        elif move == 'd':
            new_grid, score = move_right(grid)
        elif move == 'w':
            new_grid, score = move_up(grid)
        elif move == 's':
            new_grid, score = move_down(grid)

        if new_grid != grid:
            grid = new_grid
            total_score += score
            add_new_tile(grid)
            if not can_move(grid):
                print_grid(grid)
                print(f"Game Over! Final Score: {total_score}")
                break
        else:
            if not can_move(grid):
                print_grid(grid)
                print(f"Game Over! Final Score: {total_score}")
                break

if __name__ == "__main__":
    main()""