import pygame
import sys
import math
import random

# 初始化 Pygame
pygame.init()

# 窗口设置
WIDTH, HEIGHT = 800, 650
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("🥕 保卫胡萝卜")

# 颜色定义
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
GREEN = (34, 139, 34)
LIGHT_GREEN = (144, 238, 144)
BROWN = (139, 69, 19)
LIGHT_BROWN = (160, 120, 80)
DARK_BROWN = (101, 67, 33)
ORANGE = (255, 165, 0)
DARK_ORANGE = (200, 120, 0)
RED = (255, 50, 50)
DARK_RED = (200, 0, 0)
YELLOW = (255, 255, 0)
BLUE = (50, 150, 255)
DARK_BLUE = (0, 0, 200)
PURPLE = (200, 50, 255)
GRAY = (150, 150, 150)
DARK_GRAY = (80, 80, 80)
LIGHT_GRAY = (200, 200, 200)
SKY_BLUE = (135, 206, 235)

# 帧率控制
clock = pygame.time.Clock()
FPS = 60

# 中文字体
def get_chinese_font(size):
    font_names = ["SimHei", "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", "WenQuanYi Micro Hei", "Arial"]
    for name in font_names:
        try:
            return pygame.font.SysFont(name, size)
        except:
            continue
    return pygame.font.Font(None, size)

font = get_chinese_font(28)
small_font = get_chinese_font(18)
big_font = get_chinese_font(40)

# 植物类
class Plant:
    def __init__(self, x, y, plant_type):
        self.x = x
        self.y = y
        self.type = plant_type
        self.size = 30
        self.attack_range = 150
        self.attack_cooldown = 0
        self.max_cooldown = 30
        self.damage = 1
        self.target = None
        
        if plant_type == "sunflower":
            self.color = YELLOW
            self.cost = 50
            self.attack_range = 0
        elif plant_type == "pea":
            self.color = GREEN
            self.cost = 100
            self.damage = 1
            self.max_cooldown = 20
        elif plant_type == "wall":
            self.color = BROWN
            self.cost = 50
            self.attack_range = 0
        elif plant_type == "fire":
            self.color = RED
            self.cost = 150
            self.damage = 2
            self.max_cooldown = 15
            self.attack_range = 120
        elif plant_type == "ice":
            self.color = BLUE
            self.cost = 120
            self.damage = 1
            self.max_cooldown = 25
            self.attack_range = 130
    
    def update(self, enemies):
        if self.type in ["pea", "fire", "ice"]:
            # 寻找最近的敌人
            if self.target and self.target.alive:
                dist = math.hypot(self.x - self.target.x, self.y - self.target.y)
                if dist > self.attack_range:
                    self.target = None
            else:
                self.target = None
                for enemy in enemies:
                    if enemy.alive:
                        dist = math.hypot(self.x - enemy.x, self.y - enemy.y)
                        if dist <= self.attack_range:
                            self.target = enemy
                            break
            
            # 攻击
            if self.target:
                self.attack_cooldown -= 1
                if self.attack_cooldown <= 0:
                    self.attack_cooldown = self.max_cooldown
                    return self.target
        return None
    
    def draw(self, surface):
        cx, cy = self.x, self.y
        
        if self.type == "sunflower":
            # 向日葵
            pygame.draw.circle(surface, self.color, (cx, cy), self.size)
            pygame.draw.circle(surface, DARK_ORANGE, (cx, cy), 10)
            # 花瓣
            for i in range(8):
                angle = i * math.pi / 4
                px = cx + 20 * math.cos(angle)
                py = cy + 20 * math.sin(angle)
                pygame.draw.circle(surface, YELLOW, (int(px), int(py)), 8)
            # 笑脸
            pygame.draw.circle(surface, BLACK, (cx - 6, cy - 4), 3)
            pygame.draw.circle(surface, BLACK, (cx + 6, cy - 4), 3)
            pygame.draw.arc(surface, BLACK, (cx - 10, cy - 2, 20, 15), 0, math.pi, 2)
        
        elif self.type == "pea":
            # 豌豆射手
            pygame.draw.rect(surface, GREEN, (cx - 15, cy - 20, 30, 40), border_radius=5)
            pygame.draw.circle(surface, LIGHT_GREEN, (cx + 15, cy - 5), 10)
            pygame.draw.circle(surface, LIGHT_GREEN, (cx + 15, cy + 5), 10)
            pygame.draw.circle(surface, BLACK, (cx, cy - 8), 3)
            pygame.draw.circle(surface, BLACK, (cx, cy + 8), 3)
            # 嘴巴
            pygame.draw.arc(surface, BLACK, (cx - 5, cy - 3, 10, 6), 0, math.pi, 2)
        
        elif self.type == "wall":
            # 坚果墙
            pygame.draw.rect(surface, BROWN, (cx - 20, cy - 25, 40, 50), border_radius=8)
            pygame.draw.rect(surface, LIGHT_BROWN, (cx - 15, cy - 20, 30, 40), border_radius=5)
            # 表情
            pygame.draw.circle(surface, BLACK, (cx - 7, cy - 5), 3)
            pygame.draw.circle(surface, BLACK, (cx + 7, cy - 5), 3)
            pygame.draw.rect(surface, BLACK, (cx - 5, cy + 5, 10, 4), border_radius=2)
        
        elif self.type == "fire":
            # 火系射手
            pygame.draw.rect(surface, DARK_RED, (cx - 15, cy - 20, 30, 40), border_radius=5)
            pygame.draw.circle(surface, RED, (cx + 15, cy), 12)
            # 火焰效果
            for i in range(5):
                angle = random.uniform(0, 2 * math.pi)
                dist = random.uniform(8, 16)
                px = cx + 15 + dist * math.cos(angle)
                py = cy + dist * math.sin(angle)
                pygame.draw.circle(surface, ORANGE, (int(px), int(py)), 4)
        
        elif self.type == "ice":
            # 冰系射手
            pygame.draw.rect(surface, BLUE, (cx - 15, cy - 20, 30, 40), border_radius=5)
            pygame.draw.circle(surface, (200, 230, 255), (cx + 15, cy), 12)
            # 冰晶效果
            for i in range(6):
                angle = i * math.pi / 3
                px = cx + 15 + 14 * math.cos(angle)
                py = cy + 14 * math.sin(angle)
                pygame.draw.line(surface, (200, 230, 255), (cx + 15, cy), (px, py), 2)

# 子弹类
class Bullet:
    def __init__(self, x, y, target, damage=1, bullet_type="normal"):
        self.x = x
        self.y = y
        self.target = target
        self.speed = 5
        self.damage = damage
        self.type = bullet_type
        self.alive = True
        
        if bullet_type == "fire":
            self.color = ORANGE
            self.size = 6
        elif bullet_type == "ice":
            self.color = (200, 230, 255)
            self.size = 6
        else:
            self.color = LIGHT_GREEN
            self.size = 5
    
    def update(self):
        if not self.alive or not self.target.alive:
            self.alive = False
            return
        
        dx = self.target.x - self.x
        dy = self.target.y - self.y
        dist = math.hypot(dx, dy)
        
        if dist < 5:
            self.target.hit(self.damage, self.type)
            self.alive = False
            return
        
        self.x += (dx / dist) * self.speed
        self.y += (dy / dist) * self.speed
    
    def draw(self, surface):
        if not self.alive:
            return
        pygame.draw.circle(surface, self.color, (int(self.x), int(self.y)), self.size)
        pygame.draw.circle(surface, WHITE, (int(self.x), int(self.y)), self.size // 2)

# 敌人类
class Enemy:
    def __init__(self, path, wave):
        self.path = path
        self.path_index = 0
        self.x = path[0][0]
        self.y = path[0][1]
        self.speed = 1 + wave * 0.05
        self.hp = 5 + wave * 1
        self.max_hp = self.hp
        self.alive = True
        self.size = 15
        self.type = random.choice(["normal", "fast", "tank"])
        
        if self.type == "fast":
            self.speed *= 1.5
            self.hp = int(self.hp * 0.7)
            self.max_hp = self.hp
            self.color = (200, 200, 50)
        elif self.type == "tank":
            self.speed *= 0.7
            self.hp = int(self.hp * 2)
            self.max_hp = self.hp
            self.color = (150, 100, 150)
        else:
            self.color = (200, 100, 100)
        
        self.slow_timer = 0
        self.slow_factor = 1
    
    def update(self):
        if not self.alive:
            return
        
        # 减速效果
        if self.slow_timer > 0:
            self.slow_timer -= 1
            speed = self.speed * 0.5
        else:
            speed = self.speed
        
        # 沿路径移动
        if self.path_index < len(self.path) - 1:
            target_x, target_y = self.path[self.path_index + 1]
            dx = target_x - self.x
            dy = target_y - self.y
            dist = math.hypot(dx, dy)
            
            if dist < speed:
                self.path_index += 1
                self.x, self.y = self.path[self.path_index]
            else:
                self.x += (dx / dist) * speed
                self.y += (dy / dist) * speed
        else:
            # 到达终点 - 偷走胡萝卜！
            self.alive = False
            return "stolen"
        
        return None
    
    def hit(self, damage, bullet_type="normal"):
        self.hp -= damage
        if bullet_type == "fire":
            self.hp -= 1  # 额外火焰伤害
        elif bullet_type == "ice":
            self.slow_timer = 30  # 减速0.5秒
        
        if self.hp <= 0:
            self.alive = False
            return True
        return False
    
    def draw(self, surface):
        if not self.alive:
            return
        
        # 身体
        pygame.draw.circle(surface, self.color, (int(self.x), int(self.y)), self.size)
        pygame.draw.circle(surface, BLACK, (int(self.x), int(self.y)), self.size, 2)
        
        # 兔子耳朵
        ear_offset = 8
        pygame.draw.ellipse(surface, self.color, 
                          (self.x - 10, self.y - 25, 8, 18))
        pygame.draw.ellipse(surface, self.color, 
                          (self.x + 2, self.y - 25, 8, 18))
        pygame.draw.ellipse(surface, (255, 200, 200), 
                          (self.x - 8, self.y - 22, 4, 12))
        pygame.draw.ellipse(surface, (255, 200, 200), 
                          (self.x + 4, self.y - 22, 4, 12))
        
        # 眼睛
        pygame.draw.circle(surface, BLACK, (self.x - 5, self.y - 3), 3)
        pygame.draw.circle(surface, BLACK, (self.x + 5, self.y - 3), 3)
        pygame.draw.circle(surface, WHITE, (self.x - 4, self.y - 5), 1)
        pygame.draw.circle(surface, WHITE, (self.x + 6, self.y - 5), 1)
        
        # 嘴巴
        pygame.draw.arc(surface, BLACK, (self.x - 6, self.y + 2, 12, 8), 0, math.pi, 1)
        
        # 牙齿
        pygame.draw.rect(surface, WHITE, (self.x - 3, self.y + 3, 3, 4))
        pygame.draw.rect(surface, WHITE, (self.x + 1, self.y + 3, 3, 4))
        
        # 血条
        bar_width = 30
        bar_height = 4
        bar_x = self.x - bar_width // 2
        bar_y = self.y - self.size - 10
        pygame.draw.rect(surface, RED, (bar_x, bar_y, bar_width, bar_height))
        hp_ratio = self.hp / self.max_hp
        pygame.draw.rect(surface, GREEN, (bar_x, bar_y, bar_width * hp_ratio, bar_height))
        
        # 类型标签
        if self.type == "fast":
            label = small_font.render("⚡", True, BLACK)
            surface.blit(label, (self.x - 8, self.y - 35))
        elif self.type == "tank":
            label = small_font.render("🛡️", True, BLACK)
            surface.blit(label, (self.x - 8, self.y - 35))

# 游戏主类
class CarrotDefense:
    def __init__(self):
        self.carrot_x = 700
        self.carrot_y = 300
        self.carrot_hp = 20
        self.max_carrot_hp = 20
        self.money = 200
        self.plants = []
        self.enemies = []
        self.bullets = []
        self.wave = 0
        self.enemies_per_wave = 5
        self.enemies_spawned = 0
        self.spawn_timer = 0
        self.wave_delay = 60
        self.game_over = False
        self.win = False
        self.selected_plant = None
        self.path = []
        self.create_path()
        
        # 植物按钮
        self.buttons = [
            {"name": "向日葵", "type": "sunflower", "cost": 50, "color": YELLOW},
            {"name": "豌豆射手", "type": "pea", "cost": 100, "color": GREEN},
            {"name": "坚果墙", "type": "wall", "cost": 50, "color": BROWN},
            {"name": "火焰射手", "type": "fire", "cost": 150, "color": RED},
            {"name": "寒冰射手", "type": "ice", "cost": 120, "color": BLUE},
        ]
        
        self.button_rects = []
        self.create_buttons()
    
    def create_path(self):
        # 兔子行进路径
        points = [
            (50, 500),
            (200, 500),
            (200, 200),
            (400, 200),
            (400, 400),
            (550, 400),
            (550, 250),
            (700, 250),
        ]
        self.path = points
    
    def create_buttons(self):
        self.button_rects = []
        for i, btn in enumerate(self.buttons):
            x = 20 + i * 100
            y = HEIGHT - 60
            rect = pygame.Rect(x, y, 80, 50)
            self.button_rects.append(rect)
    
    def get_plant_position(self, x, y):
        # 将鼠标位置对齐到网格
        grid_size = 40
        grid_x = ((x - 20) // grid_size) * grid_size + 20 + grid_size // 2
        grid_y = ((y - 80) // grid_size) * grid_size + 80 + grid_size // 2
        
        # 检查是否在有效区域
        if grid_x < 20 or grid_x > WIDTH - 20 or grid_y < 80 or grid_y > HEIGHT - 80:
            return None
        
        # 检查是否在路径上
        for i in range(len(self.path) - 1):
            x1, y1 = self.path[i]
            x2, y2 = self.path[i + 1]
            # 检查点是否在路径线段附近
            dist = self.distance_to_segment(grid_x, grid_y, x1, y1, x2, y2)
            if dist < 25:
                return None
        
        # 检查是否与其他植物重叠
        for plant in self.plants:
            if math.hypot(grid_x - plant.x, grid_y - plant.y) < 35:
                return None
        
        return grid_x, grid_y
    
    def distance_to_segment(self, px, py, x1, y1, x2, y2):
        dx = x2 - x1
        dy = y2 - y1
        if dx == 0 and dy == 0:
            return math.hypot(px - x1, py - y1)
        
        t = ((px - x1) * dx + (py - y1) * dy) / (dx * dx + dy * dy)
        t = max(0, min(1, t))
        
        near_x = x1 + t * dx
        near_y = y1 + t * dy
        return math.hypot(px - near_x, py - near_y)
    
    def spawn_enemy(self):
        if self.enemies_spawned < self.enemies_per_wave:
            enemy = Enemy(self.path, self.wave)
            self.enemies.append(enemy)
            self.enemies_spawned += 1
    
    def start_wave(self):
        if self.enemies_spawned >= self.enemies_per_wave and not self.enemies:
            self.wave += 1
            self.enemies_per_wave = 5 + self.wave * 2
            self.enemies_spawned = 0
            self.wave_delay = 60
            return True
        return False
    
    def update(self, keys, mouse_pos, mouse_clicked):
        if self.game_over or self.win:
            return
        
        # 波次管理
        if self.wave_delay > 0:
            self.wave_delay -= 1
            if self.wave_delay == 0:
                self.spawn_enemy()
        
        # 生成敌人
        if self.wave_delay <= 0 and self.enemies_spawned < self.enemies_per_wave:
            self.spawn_timer -= 1
            if self.spawn_timer <= 0:
                self.spawn_enemy()
                self.spawn_timer = max(10, 30 - self.wave * 1)
        
        # 更新植物
        for plant in self.plants:
            target = plant.update(self.enemies)
            if target and plant.type != "sunflower":
                # 发射子弹
                bullet_type = "normal"
                if plant.type == "fire":
                    bullet_type = "fire"
                elif plant.type == "ice":
                    bullet_type = "ice"
                bullet = Bullet(plant.x + 15, plant.y, target, plant.damage, bullet_type)
                self.bullets.append(bullet)
        
        # 更新子弹
        for bullet in self.bullets[:]:
            bullet.update()
            if not bullet.alive:
                self.bullets.remove(bullet)
        
        # 更新敌人
        for enemy in self.enemies[:]:
            result = enemy.update()
            if result == "stolen":
                self.carrot_hp -= 1
                if self.carrot_hp <= 0:
                    self.game_over = True
                self.enemies.remove(enemy)
            elif not enemy.alive:
                self.money += 20
                self.enemies.remove(enemy)
        
        # 检查波次完成
        if self.wave_delay <= 0 and not self.enemies and self.enemies_spawned >= self.enemies_per_wave:
            self.start_wave()
        
        # 向日葵产生阳光
        for plant in self.plants:
            if plant.type == "sunflower" and random.random() < 0.005:
                self.money += 25
        
        # 鼠标点击处理
        if mouse_clicked:
            # 检查是否点击了植物按钮
            for i, rect in enumerate(self.button_rects):
                if rect.collidepoint(mouse_pos):
                    if self.money >= self.buttons[i]["cost"]:
                        self.selected_plant = self.buttons[i]["type"]
                        self.money -= self.buttons[i]["cost"]
                    break
            else:
                # 尝试种植
                if self.selected_plant:
                    pos = self.get_plant_position(mouse_pos[0], mouse_pos[1])
                    if pos:
                        x, y = pos
                        plant = Plant(x, y, self.selected_plant)
                        self.plants.append(plant)
                    # 取消选择
                    self.selected_plant = None
    
    def draw(self, surface):
        # 背景 - 草地
        surface.fill(LIGHT_GREEN)
        
        # 网格（草地纹理）
        for x in range(20, WIDTH, 40):
            for y in range(80, HEIGHT - 80, 40):
                if (x // 40 + y // 40) % 2 == 0:
                    pygame.draw.rect(surface, GREEN, (x, y, 40, 40))
        
        # 绘制路径
        for i in range(len(self.path) - 1):
            x1, y1 = self.path[i]
            x2, y2 = self.path[i + 1]
            pygame.draw.line(surface, DARK_BROWN, (x1, y1), (x2, y2), 20)
            pygame.draw.line(surface, LIGHT_BROWN, (x1, y1), (x2, y2), 18)
        
        # 路径点标记
        for x, y in self.path:
            pygame.draw.circle(surface, DARK_BROWN, (x, y), 8)
        
        # 绘制胡萝卜（终点）
        carrot_rect = pygame.Rect(self.carrot_x - 20, self.carrot_y - 30, 40, 60)
        # 胡萝卜身体
        pygame.draw.ellipse(surface, ORANGE, carrot_rect)
        pygame.draw.ellipse(surface, DARK_ORANGE, carrot_rect, 2)
        # 叶子
        for i in range(3):
            angle = -math.pi / 2 + (i - 1) * 0.4
            lx = self.carrot_x + 15 * math.cos(angle)
            ly = self.carrot_y - 30 + 15 * math.sin(angle)
            pygame.draw.ellipse(surface, GREEN, (lx - 5, ly - 10, 10, 15))
        
        # 胡萝卜血量条
        bar_width = 60
        bar_height = 8
        bar_x = self.carrot_x - bar_width // 2
        bar_y = self.carrot_y + 35
        pygame.draw.rect(surface, RED, (bar_x, bar_y, bar_width, bar_height))
        hp_ratio = self.carrot_hp / self.max_carrot_hp
        pygame.draw.rect(surface, GREEN, (bar_x, bar_y, bar_width * hp_ratio, bar_height))
        pygame.draw.rect(surface, BLACK, (bar_x, bar_y, bar_width, bar_height), 2)
        
        # 绘制植物
        for plant in self.plants:
            plant.draw(surface)
        
        # 绘制敌人
        for enemy in self.enemies:
            enemy.draw(surface)
        
        # 绘制子弹
        for bullet in self.bullets:
            bullet.draw(surface)
        
        # 绘制选中的植物（跟随鼠标）
        if self.selected_plant:
            mouse_pos = pygame.mouse.get_pos()
            x, y = mouse_pos
            # 半透明预览
            temp_plant = Plant(x, y, self.selected_plant)
            temp_surf = pygame.Surface((60, 60), pygame.SRCALPHA)
            temp_plant.draw(temp_surf)
            temp_surf.set_alpha(150)
            surface.blit(temp_surf, (x - 30, y - 30))
        
        # UI面板 - 底部
        ui_rect = pygame.Rect(0, HEIGHT - 70, WIDTH, 70)
        pygame.draw.rect(surface, DARK_GRAY, ui_rect)
        pygame.draw.rect(surface, GRAY, ui_rect, 2)
        
        # 植物按钮
        for i, rect in enumerate(self.button_rects):
            btn = self.buttons[i]
            color = btn["color"]
            if self.money < btn["cost"]:
                color = GRAY
            pygame.draw.rect(surface, color, rect, border_radius=8)
            pygame.draw.rect(surface, BLACK, rect, 2, border_radius=8)
            
            # 按钮文本
            label = small_font.render(btn["name"], True, BLACK)
            label_rect = label.get_rect(center=(rect.centerx, rect.centery - 10))
            surface.blit(label, label_rect)
            
            cost_label = small_font.render(f"${btn['cost']}", True, BLACK)
            cost_rect = cost_label.get_rect(center=(rect.centerx, rect.centery + 15))
            surface.blit(cost_label, cost_rect)
        
        # 信息面板 - 顶部
        info_y = 10
        
        # 金钱
        money_text = font.render(f"💰 {self.money}", True, BLACK)
        surface.blit(money_text, (20, info_y))
        
        # 波次
        wave_text = font.render(f"🌊 第 {self.wave} 波", True, BLACK)
        surface.blit(wave_text, (180, info_y))
        
        # 敌人数量
        enemy_text = font.render(f"🐰 {len(self.enemies)} 只兔子", True, BLACK)
        surface.blit(enemy_text, (380, info_y))
        
        # 胡萝卜HP
        hp_text = font.render(f"🥕 {self.carrot_hp}/{self.max_carrot_hp}", True, BLACK)
        surface.blit(hp_text, (560, info_y))
        
        # 游戏结束
        if self.game_over:
            overlay = pygame.Surface((WIDTH, HEIGHT), pygame.SRCALPHA)
            overlay.fill((0, 0, 0, 180))
            surface.blit(overlay, (0, 0))
            
            game_over_text = big_font.render("💀 胡萝卜被偷走了！", True, RED)
            text_rect = game_over_text.get_rect(center=(WIDTH // 2, HEIGHT // 2 - 40))
            surface.blit(game_over_text, text_rect)
            
            restart_text = font.render("按 R 重新开始", True, WHITE)
            restart_rect = restart_text.get_rect(center=(WIDTH // 2, HEIGHT // 2 + 20))
            surface.blit(restart_text, restart_rect)
        
        # 胜利
        if self.win:
            overlay = pygame.Surface((WIDTH, HEIGHT), pygame.SRCALPHA)
            overlay.fill((0, 0, 0, 180))
            surface.blit(overlay, (0, 0))
            
            win_text = big_font.render("🎉 保卫成功！", True, YELLOW)
            text_rect = win_text.get_rect(center=(WIDTH // 2, HEIGHT // 2 - 40))
            surface.blit(win_text, text_rect)
            
            restart_text = font.render("按 R 重新开始", True, WHITE)
            restart_rect = restart_text.get_rect(center=(WIDTH // 2, HEIGHT // 2 + 20))
            surface.blit(restart_text, restart_rect)
        
        # 操作提示
        hint = small_font.render("点击底部选择植物，点击草地种植 | 点击已选植物取消选择", True, DARK_GRAY)
        surface.blit(hint, (WIDTH // 2 - 200, HEIGHT - 90))

# 主游戏函数
def main():
    game = CarrotDefense()
    running = True
    mouse_clicked = False
    
    while running:
        mouse_clicked = False
        
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False
            
            if event.type == pygame.MOUSEBUTTONDOWN:
                if event.button == 1:  # 左键
                    mouse_clicked = True
                    # 如果已选择植物，点击右键取消
                elif event.button == 3:  # 右键
                    game.selected_plant = None
            
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_r:
                    game = CarrotDefense()
                if event.key == pygame.K_ESCAPE:
                    game.selected_plant = None
        
        mouse_pos = pygame.mouse.get_pos()
        keys = pygame.key.get_pressed()
        
        # 更新游戏
        game.update(keys, mouse_pos, mouse_clicked)
        
        # 绘制
        game.draw(screen)
        pygame.display.flip()
        clock.tick(FPS)
    
    pygame.quit()
    sys.exit()

if __name__ == "__main__":
    main()