Views
No views yet
Generate the model for more details../llama-cli -hf Intel/Qwen3-235B-A22B-Instruct-2507-gguf-q4km-AutoRound:q4_k_m --conversation1"""
2> Hi
3Hello! ٩(◕‿◕。)۶ How can I assist you today?
4
5> Code a flappy bird in python
6Sure! Below is a simple implementation of **Flappy Bird** using **Python** and the **Pygame** library. This version includes:
7
8- A bird that flaps when you press the spacebar or click.
9- Pipes that move from right to left.
10- Collision detection.
11- Score tracking.
12- Game over when the bird hits a pipe or the ground/ceiling.
13
14---
15
16### ✅ Requirements
17
18Make sure you have `pygame` installed:
19
20```bash
21pip install pygame
22```
23
24---
25
26### 🐤 Flappy Bird Code
27
28```python
29import pygame
30import random
31import sys
32
33# Initialize Pygame
34pygame.init()
35
36# Screen dimensions
37SCREEN_WIDTH = 400
38SCREEN_HEIGHT = 600
39screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
40pygame.display.set_caption("Flappy Bird")
41
42# Colors
43WHITE = (255, 255, 255)
44BLACK = (0, 0, 0)
45GREEN = (0, 255, 0)
46BLUE = (0, 0, 255)
47SKY_BLUE = (135, 206, 235)
48
49# Game settings
50GRAVITY = 0.5
51FLAP_STRENGTH = -10
52PIPE_SPEED = 3
53PIPE_GAP = 150
54PIPE_FREQUENCY = 1500 # milliseconds
55
56# Bird settings
57bird_x = 100
58bird_y = SCREEN_HEIGHT // 2
59bird_velocity = 0
60bird_width = 40
61bird_height = 30
62
63# Pipe list
64pipes = []
65last_pipe_time = 0
66
67# Score
68score = 0
69font = pygame.font.SysFont('Arial', 26)
70
71# Clock
72clock = pygame.time.Clock()
73
74# Game loop
75running = True
76game_active = True
77
78def draw_bird(x, y):
79 pygame.draw.rect(screen, BLUE, (x, y, bird_width, bird_height), border_radius=10)
80
81def create_pipe():
82 height = random.randint(100, SCREEN_HEIGHT - PIPE_GAP - 100)
83 top_pipe = pygame.Rect(SCREEN_WIDTH, 0, 60, height)
84 bottom_pipe = pygame.Rect(SCREEN_WIDTH, height + PIPE_GAP, 60, SCREEN_HEIGHT)
85 return {"top": top_pipe, "bottom": bottom_pipe, "passed": False}
86
87def draw_pipes(pipes):
88 for pipe in pipes:
89 pygame.draw.rect(screen, GREEN, pipe["top"])
90 pygame.draw.rect(screen, GREEN, pipe["bottom"])
91
92def move_pipes(pipes):
93 for pipe in pipes:
94 pipe["top"].x -= PIPE_SPEED
95 pipe["bottom"].x -= PIPE_SPEED
96
97def remove_offscreen_pipes(pipes):
98 return [pipe for pipe in pipes if pipe["top"].right > 0]
99
100def check_collision(pipes, bird_y):
101 # Check ceiling or floor
102 if bird_y < 0 or bird_y + bird_height > SCREEN_HEIGHT:
103 return True
104
105 # Check pipes
106 bird_rect = pygame.Rect(bird_x, bird_y, bird_width, bird_height)
107 for pipe in pipes:
108 if bird_rect.colliderect(pipe["top"]) or bird_rect.colliderect(pipe["bottom"]):
109 return True
110 return False
111
112def draw_score():
113 score_text = font.render(f"Score: {score}", True, BLACK)
114 screen.blit(score_text, (10, 10))
115
116# Main game loop
117while running:
118 current_time = pygame.time.get_ticks()
119 screen.fill(SKY_BLUE)
120
121 for event in pygame.event.get():
122 if event.type == pygame.QUIT:
123 running = False
124 if event.type == pygame.KEYDOWN:
125 if event.key == pygame.K_SPACE and game_active:
126 bird_velocity = FLAP_STRENGTH
127 if event.key == pygame.K_r and not game_active:
128 # Restart game
129 bird_y = SCREEN_HEIGHT // 2
130 bird_velocity = 0
131 pipes = []
132 score = 0
133 game_active = True
134 if event.type == pygame.MOUSEBUTTONDOWN and game_active:
135 bird_velocity = FLAP_STRENGTH
136
137 if game_active:
138 # Bird physics
139 bird_velocity += GRAVITY
140 bird_y += bird_velocity
141
142 # Generate pipes
143 if current_time - last_pipe_time > PIPE_FREQUENCY:
144 pipes.append(create_pipe())
145 last_pipe_time = current_time
146
147 # Move and draw pipes
148 move_pipes(pipes)
149 pipes = remove_offscreen_pipes(pipes)
150 draw_pipes(pipes)
151
152 # Check for scoring
153 for pipe in pipes:
154 if pipe["top"].right < bird_x and not pipe["passed"]:
155 score += 1
156 pipe["passed"] = True
157
158 # Collision check
159 if check_collision(pipes, bird_y):
160 game_active = False
161
162 # Draw bird and score
163 draw_bird(bird_x, bird_y)
164 draw_score()
165
166 # Game over screen
167 if not game_active:
168 game_over = font.render("Game Over! Press 'R' to Restart", True, BLACK)
169 screen.blit(game_over, (SCREEN_WIDTH // 2 - 180, SCREEN_HEIGHT // 2))
170
171 pygame.display.update()
172 clock.tick(60)
173
174pygame.quit()
175sys.exit()
176```
177
178---
179
180### 🎮 How to Play
181
182- Press **Spacebar** or **click the mouse** to make the bird flap.
183- Avoid hitting the pipes, ceiling, or floor.
184- Your score increases each time you pass a pair of pipes.
185- After game over, press **'R'** to restart.
186
187---
188
189### 🧩 Enhancements (Optional)
190
191You can improve this by:
192- Adding sound effects.
193- Using bird/pipes images instead of rectangles.
194- Adding start screen.
195- Increasing difficulty over time.
196
197Let me know if you want a version with images or sound! 🎵🐦
198
199"""
2001import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3from auto_round import AutoRound
4
5model_name = "Qwen/Qwen3-235B-A22B-Instruct-2507"
6
7model = AutoModelForCausalLM.from_pretrained(model_name,
8 device_map="cpu", torch_dtype="auto")
9tokenizer = AutoTokenizer.from_pretrained(model_name)
10
11autoround = AutoRound(model, tokenizer, iters=0, layer_config=layer_config, nsamples=512)
12autoround.quantize_and_save("/dataset/Qwen3-235B-A22B-Instruct-2507-q4km", format="gguf:q4_k_m")
13