În acest articol vom analiza cum putem face codare cu DeepSeek R1 de pe calculatorul personal, în mod gratuit. Modelul DeepSeek R1 a adus multă agitație în lumea tehnologiei prin performanțele modului să de analiză a cerințelor utilizatorilor, ușurința de folosire, dar și costurile reduse la utilizarea în cloud.
1. Instalarea modelului DeepSeek R1 pe dispozitivele personale
DeepSeek are în portfoliu mai multe modele AI, în format open-source, care permit descărcarea și utilizarea lor cu o licență MIT. Acesta permite folosirea modelului fără limitări legate de copiere, modificare, distribuire, sublicențiere sau alte restricții comerciale.
R1 este un model cu raționament care împarte sarcinile primite de la utilizator în mai multe subsarcini pe care le rezolvă pe rând pentru a da un răspuns cât mai bun.
DeepSeek R1 se bazează pe modelul V3 – care este unul dintre cele mai bune modele de dezvoltare software de pe piață.
Aceste modele pot fi folosite din cloud (chiar de pe DeepSeek sau de la diverși furnizori de modele AI precum Cerebras sau Groq) sau poate fi descărcat de pe HuggingFace, sau Ollama și folosit ca interferență directă pe dispozitivele personale.
În exemplul de azi vom folosi Ollama care permite o integrare ușoară împreună cu diverse aplicații de dezvoltare software.
În funcție de capacitățile tehnice ale dispozitivului local se pot instala modele AI cuantizate divers:
- 1.5b cu o dimensiune de aprox. 1.1 GB
- 7b cu o dimensiune de aprox 4.7 GB
- 8b cu o dimensiune de aprox 4.9 GB
- 14b cu o dimensiune de aprox 9 GB
- 32b cu o dimensiune de aprox 20 GB
- 70b cu o dimensiune de aprox 43 GB
- 671b cu o dimensiune de aprox 713GB
De asemenea trebuie să ținem cont că DeepSeek R1 este un model MoE care deși are 671 miliarde de parametri, activează doar 37 miliarde atunci când este folosit.
Pentru testul de azi am folosit modelul de 32b pe care l-am instalat local cu comanda:
ollama pull deepseek-r1:32b
După ce modelul a fost instalat putem folosi server-ul Ollama pentru a interacționa direct cu modelul folosind comanda:
ollama run deepseek-r1:32b
sau putem să îl integrăm într-un mediu de dezvoltare software precum Visual Code Studio, atât pentru scrierea de cod, cât și pentru auto-completări sau corectări de cod.
2. Generarea unui cod python
Am cerut modelului DeepSeek R1 să genereze un cod python care să simuleze o monedă care cade din partea de sus a ecranului spre partea de jos, iar apoi sub acțiunea simultată a gravitației să execute mișcările specifice până la oprirea completă.
Promptul utilizat a fost:
write a simple python code that simulates a rolling dime faling to the bottom of the screen and the rolling until if finishes all the moves. The dime should falow the gravitational rules only and move acordingly.

Din acest moment DeepSeek R1 activează modulul de raționament și începe să împartă sarcina primită în mai multe subsarcini care pot prezenta provocări diverse. DeepSeek R1 gândește în felul următor:
<think>
Okay, I need to figure out how to write a Python program that simulates a rolling dime
falling to the bottom of the screen and then rolling around according to gravity. Hmm,
where do I start?
First, I remember that for animations, especially in 2D, using Pygame is a good choice
because it's designed for game development and can handle graphics and physics
relatively easily.
I should outline what needs to be done:
1. **Setup the Pygame environment**: Initialize the screen with a certain width and
height. I think 800x600 might be a good starting point.
2. **Create the dime**: The dime is a circular object, so using a circle shape would
make sense. I'll define its radius, maybe around 20 pixels.
3. **Positioning**: Initially, place the dime at the top of the screen so it can fall
down.
4. **Gravity simulation**: To make the dime fall, I need to apply gravity as an
acceleration. Maybe a value like 0.5 units per frame squared for smooth movement.
5. **Movement and physics**:
- Apply gravity each frame by adding it to the vertical velocity.
- Update the position based on the velocity.
- When the dime hits the bottom, instead of stopping, make it bounce or roll. Maybe
invert the vertical velocity when it hits the ground but keep some energy loss to
simulate damping.
6. **Rolling motion after hitting the bottom**: After the initial fall, I want the dime
to start rolling horizontally. So once it's on the ground, add a horizontal velocity.
This can be achieved by setting a constant horizontal speed or maybe having it roll in a
random direction each time it bounces.
7. **Edges of the screen**: If the dime reaches the edges (left or right), I should make
it bounce back to keep it moving within the screen.
8. **Drawing and updating**: Each frame, clear the screen, draw the dime at its new
position, then update the display. Also, handle events to keep the window responsive.
I think using Pygame's drawing functions like `pygame.draw.circle` would be sufficient
for rendering the dime.
Wait, I should consider how to manage different states of movement—falling and rolling.
Maybe after the initial fall when it hits the ground, set a flag or change the velocity
vector to include horizontal movement.
Also, damping is important so that the motion eventually stops, simulating real-world
physics where energy dissipates over time. So each bounce should reduce the velocity by
a certain factor (like 0.8) to simulate friction and air resistance.
Putting it all together:
- Initialize Pygame, set up the window.
- Set initial position at the top middle of the screen.
- Apply gravity each frame.
- When hitting the bottom, invert vertical velocity with damping.
- Add horizontal movement after the first fall.
- Handle edge collisions by reversing horizontal velocity and applying damping.
I might need to adjust parameters like gravity strength, damping factor, and horizontal
speed to get a smooth animation that looks natural. Testing each part step by step would
help identify any issues early on.
Let me try drafting some code:
1. Import Pygame modules.
2. Set up the screen dimensions.
3. Initialize Pygame and create the window.
4. Define the dime's properties: position, radius, color.
5. Physics variables: gravity, velocity (start with zero vertical), damping factor.
6. Main loop:
- Handle events (like quitting).
- Apply physics:
- Add gravity to vertical velocity.
- Update position based on velocity.
- Check if the dime is below or above the screen and adjust accordingly.
- If hitting the bottom, invert vertical velocity with damping and add horizontal
speed.
- When at edges, invert horizontal velocity with damping.
- Clear screen.
- Draw the dime as a circle.
- Update display.
7. Exit Pygame properly when done.
I think this covers all the necessary steps. I'll proceed to write the code following
this structure, making sure to include comments for clarity and test each part as I go.
</think>

Așadar problemele identificate sunt:
- stabilirea unui mediu favorabil pentru dezoltarea codului (o fereastră de ecran);
- stabilirea caracteristicilor obiectului (monedei) asupra căruia au loc prelucrările grafice – în acest caz un obiec circular pentru care îi setează și o mărime aproximativă;
- stabilirea poziției de început a simulării (din mijlocul părții de sus a ecranului) și a modului de cădere spre partea de jos;
- stabilirea elementelor de simulare a gravitației (viteza de cădere);
- stabilirea elementelor de mișcare a obiectului și a interacțiunii cu mediul – de exemplu cu partea de jos și cu marginile laterale ale ecranului;
- stabilirea mișcării orizontale a obiectului;
- modul cum imaginile sunt reprezentate grafic.
După stabilirea acestor prime cerințe pe care utilizatorul nu le-a comunicat în mod explicit, dar cu siguranță le-a subînțeles, modelul trece la planificarea propriu zisă a scrierii codului și a stabilirii tuturor pașilor intermediari:
- folosirea unei librării python;
- setarea dimensiunilor ferestrei și a obiectului;
- setarea culorii obiectului;
- setarea elementelor de gravitație, viteză de deplasare, forțe de respingere la interacțiunea obiectului cu elementele din jur;
- pașii de mișcare ai obiectului;
- modul de reprezentare grafic;
- stabilirea punctului de final al simulării.
3. Rezultatele codării
Pe baza subtaskurilor stabilite în pasul precedent, obținem următorul exemplu de codare cu DeepSeek R1:
import pygame
# Initialize Pygame
pygame.init()
# Set up the window
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Rolling Dime Simulation")
# Define colors
WHITE = (255, 255, 255)
YELLOW = (255, 255, 0)
# Dime properties
RADIUS = 20
dime_x = SCREEN_WIDTH // 2 # Start at the middle top
dime_y = RADIUS # Just above the top edge
# Physics parameters
GRAVITY = 0.5
velocity_y = 0
HORIZONTAL_SPEED = 3
velocity_x = HORIZONTAL_SPEED # Initial horizontal speed after hitting ground
DAMPING = 0.8 # Energy loss on collision (80% retained)
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# Apply gravity
velocity_y += GRAVITY
# Update position
dime_y += velocity_y
dime_x += velocity_x
# Ground collision (bottom of the screen)
if dime_y + RADIUS > SCREEN_HEIGHT:
dime_y = SCREEN_HEIGHT - RADIUS
velocity_y = -velocity_y * DAMPING # Reverse and reduce vertical speed
# Start rolling after hitting the ground
if abs(velocity_x) < 0.1: # If not moving horizontally, start rolling
velocity_x = HORIZONTAL_SPEED
# Wall collision (left/right)
if dime_x - RADIUS < 0 or dime_x + RADIUS > SCREEN_WIDTH:
velocity_x = -velocity_x * DAMPING # Reverse and reduce horizontal speed
# Keep vertical movement smooth even after hitting ground
if dime_y == SCREEN_HEIGHT - RADIUS and velocity_y >= 0:
velocity_y = 0
# Clear the screen
screen.fill(WHITE)
# Draw the dime
pygame.draw.circle(screen, YELLOW, (int(dime_x), int(dime_y)), RADIUS)
# Update display
pygame.display.flip()
# Control frame rate
pygame.time.Clock().tick(60)
# Quit Pygame
pygame.quit()
Codul rulează fără probleme:

Desigur putem cere lui R1 să facă diferite modificări la cod, precum schimbarea culorii monedei sau adăugarea simulării unei rotori și pe plan transversal.
Este remarcabil însă că tot procesul de codare a putut fi făcut fără erori pornind de la un simplu prompt fără foarte multe informații suplimentare de la utilizator.
4. Concluzii
DeepSeek R1 este un model foarte performant, dar unul din marile sale avantaje este faptul că poate fi utilizat local astfel încât datele utilizatorului să fie securizate și să rămână strict pe dispozitivele dezvoltatorilor software.
Da, este nevoie de folosirea unor plăci GPU de capacitate mare pentru a rula cele mai bune variante ale modelului AI, dar după cum se vede, chiar și o variantă de mijloc – DeepSeek R1 32b produce rezultate excelente.
Ne putem imagina o structură de dezvoltare compusă din mai mulți agenți AI care să analizeze subtaskurile unui proiect și să le împartă pentru agenți care funcționează în cloud și agenți care funcționează local, obținând astfel cel mai bun cost/performanță și securitate posibil.