Ramikan-BR commited on
Commit
f77da6d
1 Parent(s): 36ed327

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +73 -0
README.md CHANGED
@@ -11,6 +11,79 @@ tags:
11
  - trl
12
  - sft
13
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
  # Uploaded model
16
 
 
11
  - trl
12
  - sft
13
  ---
14
+ ```python
15
+ <s> Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
16
+
17
+ ### Input:
18
+ Write a code to create the snake game
19
+
20
+ ### Output:
21
+
22
+ ```python
23
+ import pygame
24
+ import random
25
+
26
+ # Initialize the pygame library
27
+ pygame.init()
28
+
29
+ # Set the width and height of the game window
30
+ width = 600
31
+ height = 600
32
+
33
+ # Set the title of the game window
34
+ pygame.display.set_caption("Snake Game")
35
+
36
+ # Create a white background surface
37
+ background = pygame.Surface((width, height))
38
+ background.fill((255, 255, 255))
39
+
40
+ # Create a snake object
41
+ snake = []
42
+ snake.append([width // 2, height // 2])
43
+
44
+ # Create a food object
45
+ food = [random.randint(0, width - 1), random.randint(0, height - 1)]
46
+
47
+ # Create a clock object to control the game speed
48
+ clock = pygame.time.Clock()
49
+
50
+ # Game loop
51
+ running = True
52
+ while running:
53
+ # Handle events
54
+ for event in pygame.event.get():
55
+ if event.type == pygame.QUIT:
56
+ running = False
57
+
58
+ # Move the snake
59
+ keys = pygame.key.get_pressed()
60
+ if keys[pygame.K_LEFT]:
61
+ snake.append([snake[-1][0] - 10, snake[-1][1]])
62
+ elif keys[pygame.K_RIGHT]:
63
+ snake.append([snake[-1][0] + 10, snake[-1][1]])
64
+ elif keys[pygame.K_UP]:
65
+ snake.append([snake[-1][0], snake[-1][1] - 10])
66
+ elif keys[pygame.K_DOWN]:
67
+ snake.append([snake[-1][0], snake[-1][1] + 10])
68
+
69
+ # Check if the snake has eaten the food
70
+ if snake[-1] == food:
71
+ food = [random.randint(0, width - 1), random.randint(0, height - 1)]
72
+
73
+ # Check if the snake has hit a wall or itself
74
+ if snake[-1][0] < 0 or snake[-1][0] >= width or snake[-1][1] < 0 or snake[-1][1] >= height or snake[-1] in snake[:-1]:
75
+ running = False
76
+
77
+ # Update the game window
78
+ pygame.display.update()
79
+ clock.tick(10)
80
+
81
+ # Quit the pygame library
82
+ pygame.quit()
83
+ ```</s>
84
+ ````
85
+
86
+
87
 
88
  # Uploaded model
89