Tutorial de algoritmos de programación | Cursos Platzi

Platzi
31 Jul 201407:03

Summary

TLDRThis video teaches the basics of programming using a Pokémon battle as an example. It explains how to create an algorithm for a Pokémon fight, covering key programming concepts like objects, variables, and loops. The instructor walks through the process step-by-step, showing how Pikachu and Jigglypuff battle until one is defeated. This lesson aims to simplify programming by relating it to a familiar and engaging context, making it accessible even for beginners. The video is part of a free online programming course offered by Mejorándola on the Platzi platform.

Takeaways

  • 🔄 Programming is like understanding the flow of any process.
  • 🐾 The example uses Pokémon to illustrate programming concepts.
  • 💡 Pokémon battles are turn-based, making it easier to explain algorithm cycles.
  • 📝 Each Pokémon is considered an object in programming with attributes like name, health, and attack power.
  • 📊 Variables are used to store data, like the health of each Pokémon.
  • 🔄 A cycle (loop) continues as long as certain conditions (like health > 0) are met.
  • ⚔️ On each turn, a Pokémon attacks, reducing the opponent's health by its attack power.
  • 🔀 The turn variable switches between 1 and 0 to alternate between Pokémon.
  • ✅ The loop ends when one Pokémon's health drops to zero or below.
  • 🏆 After the loop, the program checks which Pokémon is still alive to determine the winner.

Q & A

  • What is the main topic discussed in the script?

    -The script discusses the basics of programming using a Pokémon battle as an analogy to explain concepts like objects, variables, conditions, and loops.

  • How does the speaker use Pokémon to explain programming?

    -The speaker uses a Pokémon battle between Pikachu and Jigglypuff to illustrate how programming works, including the use of objects to represent Pokémon, variables to store their attributes, and loops to manage the turn-based battle sequence.

  • What are the key programming concepts introduced in the script?

    -The key programming concepts introduced are objects, variables, conditions, loops, and how to assign and manipulate values within a program.

  • How does the speaker define an object in programming?

    -An object in programming is defined as something that has properties and behaviors. In the example, each Pokémon is an object with properties like name, life (health points), and attack power.

  • What variables are used to represent the Pokémon's attributes in the example?

    -The variables used are 'name' for the Pokémon's name, 'life' for their health points, and 'attack' for their attack power.

  • What is the initial life and attack power of Pikachu and Jigglypuff in the example?

    -Pikachu starts with a life of 100 and an attack power of 55. Jigglypuff also starts with a life of 100 but has an attack power of 45.

  • How is the turn-based battle managed in the script?

    -The turn-based battle is managed using a variable called 'turn'. If 'turn' equals 1, it is Pikachu's turn to attack; if 'turn' equals 0, it is Jigglypuff's turn.

  • What happens during each turn of the battle?

    -During each turn, the attacking Pokémon reduces the opponent's life by its attack power. The turn variable is then switched to allow the other Pokémon to attack in the next cycle.

  • What condition is checked to continue or end the battle?

    -The battle continues as long as both Pokémon have a life greater than 0. If either Pokémon's life falls to 0 or below, the battle ends.

  • How does the script explain the use of loops in programming?

    -The script explains that loops in programming are used for repetitive tasks that continue while a condition is true. In the battle example, the loop continues as long as both Pokémon are alive.

  • What is the outcome of the Pokémon battle in the example?

    -Pikachu wins the battle because its attack power is higher, leading to Jigglypuff's life being reduced to below 0 before Pikachu's life is reduced to 0.

  • How does the script use algebra to explain variable assignments?

    -The script uses algebra to explain how variables can hold values that change over time, such as the life points of the Pokémon being updated after each attack.

  • What is the purpose of the conditional statement at the end of the algorithm?

    -The conditional statement at the end of the algorithm checks which Pokémon's life is less than or equal to 0 to determine the winner of the battle.

  • What additional resources does the speaker mention for learning programming?

    -The speaker mentions that the full course, including live classes and practical examples, is available on the educational platform 'Platzi' and encourages viewers to access the JavaScript files for real-world programming practice.

Outlines

00:00

🐱‍💻 Understanding Programming through Pokémon

Programming is as easy as understanding the flow of any process. Using Pokémon as an example, even for those who are not familiar with the game, the concept can be grasped easily. Pokémon involves battles between two creatures. Here, Pikachu and Jigglypuff are used to demonstrate the concept. Both Pokémon have common attributes like names, health (starting at 100), and attack power (Pikachu has 55, Jigglypuff has 45). The battle operates in turns, similar to algebraic variables, where each Pokémon attacks in cycles until one's health drops to zero. The turn system is managed using variables, with Pikachu attacking first. The battle sequence is explained in detail, highlighting how variables and conditions are used to simulate the combat until a Pokémon loses all its health.

05:00

🔄 The Pokémon Battle Algorithm

The battle continues with Jigglypuff attacking after Pikachu, reducing Pikachu's health. This cycle repeats until one Pokémon's health drops below zero. The script explains the process in detail, demonstrating how the program evaluates whose turn it is, performs the attack, and updates the health points accordingly. When Jigglypuff's health falls below zero, the cycle ends. The algorithm then checks the final conditions to determine the winner. Pikachu's health remains above zero, indicating its victory. This example encapsulates basic programming concepts like variables, conditions, and loops, providing a foundational understanding for beginners. The course promises to expand on these concepts with practical JavaScript examples, available for free through the provided platform.

Mindmap

Keywords

💡Programar

The term 'Programar' refers to the act of writing code or instructions for a computer to follow. It is central to the video's theme of teaching programming concepts through a relatable example. In the script, 'Programar' is used to introduce the idea of creating an algorithm for a Pokémon battle, which simplifies the process into understandable steps.

💡Flujo de proceso

'Flujo de proceso' translates to 'process flow' and is a concept that represents the sequence of steps in a process. It is essential in programming for structuring algorithms. In the script, the presenter uses the process flow to explain how the Pokémon battle algorithm will be structured, emphasizing the step-by-step approach.

💡Objeto

In programming, 'Objeto' or 'object' refers to a data structure that combines data and functions into a single unit. The script uses Pokémon characters as objects, each with attributes like name, health, and attack power, to illustrate how objects are used in programming.

💡Algebra

'Algebra' is a branch of mathematics concerned with finding values of variables. In the context of the video, algebra is mentioned as a useful tool for understanding variables and their manipulation in programming. The script uses algebraic concepts to explain how health points are reduced during the Pokémon battle.

💡Variables

A 'Variable' in programming is a storage location paired with an associated symbolic name, which contains some known or unknown quantity of information. The script introduces the concept of variables by using them to keep track of whose turn it is in the Pokémon battle and to store the health and attack values of each Pokémon.

💡Ciclos

'Ciclos' or 'loops' are a programming construct that allows code to be executed repeatedly while a condition holds true. The script explains how loops are used in the Pokémon battle algorithm to simulate turns until one Pokémon's health reaches zero.

💡Condiciones

'Condiciones' or 'conditions' in programming are statements that determine the flow of execution by evaluating an expression to true or false. In the script, conditions are used to check if the Pokémon are still alive (health > 0) and to exit the loop when one Pokémon's health falls below zero.

💡Turno

'Turno' or 'turn' in the context of the video refers to the sequence in which Pokémon get to attack. The script uses the concept of turn to alternate between Pikachu and Gigli, illustrating how sequential operations are managed in programming.

💡Ataque

'Ataque' or 'attack' in the script represents the action one Pokémon performs to reduce the health of the other. It is used to demonstrate how attributes of objects (like attack power) interact within the algorithm.

💡Vida

'Vida' or 'health' in the script is an attribute of the Pokémon objects, representing their current state of well-being. Health points are central to the battle algorithm, as they determine when a Pokémon is defeated.

💡Pikachu

Pikachu is a character from the Pokémon franchise and is used as an example in the script to illustrate programming concepts. As a well-known Pokémon, it helps make the programming concepts more relatable to the audience.

💡Gigli

Gigli, though not an official Pokémon, is used in the script as a second character to demonstrate a battle scenario alongside Pikachu. It serves to provide a contrast in attributes, such as health and attack power, which is crucial for illustrating programming logic.

💡JavaScript

JavaScript is a programming language often used for web development. In the script, it is mentioned as the language in which the complete course files are provided, indicating that the concepts taught will be applicable in real-world programming scenarios.

Highlights

Programming is as easy as understanding the flow of any process.

Pokémon battle concept: putting two animals to fight, likened to objects in programming.

Each Pokémon has attributes like name, health (100), and attack power.

Example Pokémon: Pikachu with 55 attack points and Jigglypuff with 45 attack points.

Battle operates in turns: first one Pokémon attacks, then the other.

Declare Pokémon with their health and determine whose turn it is.

Use algebra concepts: variables to store data, like turn and health.

Create a loop for the battle: cycle through attacks until one Pokémon's health is 0 or less.

Steps in the loop: check turn, execute attack, update health, and switch turn.

Example attack sequence: Pikachu attacks Jigglypuff, reducing its health.

Switch turns and continue the loop until one Pokémon's health drops below zero.

When the loop ends, check which Pokémon's health is 0 or less to declare the winner.

Explanation of conditions and loops in programming with the Pokémon battle example.

Learning outcomes: understanding variables, conditions, and loops in programming.

Invitation to a free online programming course with real-world coding examples.

Transcripts

play00:00

programar es tan fácil como entender el

play00:02

flujo de cualquier proceso yo les voy a

play00:05

hablar de pokémon incluso si no les

play00:07

gusta pokemon e incluso si nunca han

play00:09

jugado a ningún videojuego en su vida

play00:10

esto va a ser muy fácil de entender

play00:11

pokemon es poner a pelear a dos animales

play00:14

no importa lo que peta piense al

play00:16

respecto nintendo no ha matado a ningún

play00:18

animal hasta ahora tienes dos animales

play00:20

vamos a imaginar que uno es pikachu y el

play00:23

otro es dirijo picacho y gigli pues son

play00:26

dos pokemones que van a pelear por sus

play00:28

vidas y hoy vamos a crear el algoritmo

play00:32

primero pensemos en cada uno de los

play00:34

pokemones como algo que en programación

play00:35

se llama un objeto ambos pokemones

play00:37

tienen muchas cosas en común los

play00:40

pokemones tienen nombre pikachu gigli

play00:42

por los pokemones tienen vida imaginemos

play00:45

que ambas vidas inician el 100 y los

play00:47

pokemones también tienen un poder de

play00:49

ataque picacho es obviamente más

play00:50

poderoso entonces tiene 55 puntos de

play00:53

ataque y gigli pop no es tan poderoso

play00:55

tiene 45 puntos de ataque los puntos de

play00:58

ataque van a ser los que le quiten vida

play01:00

al pokemon cuando esté peleando

play01:01

arrancamos cómo funciona batalla pokemon

play01:03

por turnos primero

play01:05

a uno luego pelea el otro así que

play01:07

declaremos a nuestros pokemones

play01:09

tendremos a pikachu que tiene una vida

play01:11

de 100 a gigli porque tiene una vida de

play01:14

100 y ahora necesitamos saber el turno

play01:16

de quienes se acuerdan de álgebra no se

play01:19

preocupen no griten todo va a estar bien

play01:21

álgebra de hecho es una herramienta

play01:23

extremadamente útil porque en álgebra

play01:25

nos enseñaron que son las variables

play01:26

hagamos una pausa se acuerdan que si x

play01:28

es igual a 1 y es igual a 2 e imaginemos

play01:32

que z es igual a x más cuánto vale z con

play01:36

todo receta 3 porque las variables son

play01:39

nombres donde se les pueden guardar

play01:41

datos son cajitas donde podemos guardar

play01:43

algo volviendo a nuestro a nuestra

play01:45

batalla pokemon vamos a crear una

play01:47

variable que recuerde de quién es el

play01:49

turno vamos a decir que si el turno es

play01:51

igual a uno le toca a pikachu si el

play01:53

turno es igual a cero le toca a gigli

play01:55

por esta batalla está arreglada turno es

play01:58

igual a 1 vamos a tener esa variable

play02:00

turno es igual a 1 porque piqué yo

play02:02

arranca inicia nuestra baja de pokemon

play02:03

las batallas porque mono ocurren en

play02:05

ciclos primero le toca uno y si siguen

play02:07

con vida le toca otro y si siguen con

play02:09

vida le toca una vez más al primero

play02:11

ciclo ciclo de ataque hasta que alguien

play02:15

pierda realmente nadie muere en el mundo

play02:17

pokemon pero por alguna razón la

play02:19

medicina es gratis lo que vamos a crear

play02:21

entonces es un ciclo los ciclos en la

play02:23

programación son instrucciones

play02:25

repetitivas que ocurren mientras una

play02:27

condición sea verdadera esto qué

play02:30

significa mientras la vida de pikachu

play02:31

sea mayor que 0 es decir está vivo y la

play02:34

vida de gigli posee mayor que 0 entramos

play02:36

al ciclo de combate que es lo primero

play02:38

que tenemos que verificar recuerden que

play02:40

programar es como hablarle a alguien que

play02:42

no tiene conocimiento de nada tienen que

play02:44

decirle todo pasito a paso tenemos que

play02:46

evaluar el turno de quién es cuánto vale

play02:49

turno 1 entonces a quién le toca a

play02:51

pikachu lo primero que hacemos en el

play02:53

ciclo es si turno es igual a 1 turno de

play02:57

pikachu el turno de pikachu se define

play02:59

como que la vida de gigli x es igual a

play03:03

la vida de gigli por menos el ataque de

play03:06

pikachu gigli

play03:07

vida es igual a gigli form punto vida

play03:10

menos pikachu punto ataque porque no

play03:13

puedo decir simplemente gigli por punto

play03:15

vida menos pikachu punto ataque

play03:17

porque es álgebra entonces tengo que

play03:19

asignarle a la variable se acuerdan de

play03:22

las variables tengo que asignarle a la

play03:24

vida de gigli por su misma vida

play03:27

- el ataque que le estoy quitando

play03:30

[Música]

play03:31

ahora gigli pues tiene menos 55 y su

play03:34

vida vale 45 que es lo último que me

play03:37

toca hacer antes de terminar el ciclo

play03:38

cambiar el turno entonces ahora turno es

play03:41

igual a 0 para que cuando haga el ciclo

play03:43

le toque a gigli po termina el ciclo y

play03:46

volvemos al principio mientras la vida

play03:48

de picasso sea mayor que 0 lo es y la

play03:51

biopsia mayor que 0 todavía lo es

play03:53

entramos al ciclo un turno es igual a 1

play03:57

nocturno es igual a 0 vamos al turno de

play04:00

gigli por y el turno gigli prof es tan

play04:02

fácil como decir pikachu punto vida es

play04:05

igual a pikachu punto vida menos gigli

play04:08

por punto ataque con ahora pikachu tiene

play04:11

65 de vida porque gigli por flota con 45

play04:15

les dije que esta partida estaba reglada

play04:17

que nos falta hacer cambiar el turno

play04:18

entonces el turno ahora es igual a 1

play04:21

ciclo volvemos al inicio mientras la

play04:24

vida de pikachu va ya se lo saben ahora

play04:27

le toca pikachu hitler punto vida que

play04:29

vale 45 es igual a gigli punto vida 45 -

play04:34

piqué su punto ataque 55

play04:37

ahora gigli por vida tiene menos diez

play04:41

clips está muerto pero si glifos no lo

play04:44

sabe todavía porque no hemos salido del

play04:46

ciclo filippov está ahí en menos 10 y

play04:49

recuerden la programación corre a la

play04:51

velocidad de la luz así que a medida que

play04:54

nosotros hacemos esto lentamente y paso

play04:55

por paso nuestro computador ya lo hizo

play04:58

hace millones de mini segundos

play05:00

nanosegundos microsegundos muy rápido

play05:02

todavía creemos que llegue porque está

play05:04

vivo así que le va a tocar una vez más

play05:06

ágil y por fin del ciclo vamos a la

play05:09

condición mientras pikachu punto vida

play05:12

sea mayor que 0 todavía es mayor que 0

play05:14

no se acuerdan y gigli por vida sea

play05:17

mayor que 0 menos 10 no entonces la

play05:21

ecuación es falsa gigli por está muerto

play05:26

y picacho está vivo

play05:28

gigli pues tiene una vida menor que cero

play05:30

por ende la condición no se cumple

play05:31

salimos del ciclo y vamos a la parte de

play05:34

abajo del algoritmo en la parte de bajo

play05:36

el algoritmo

play05:37

tenemos una condición las condiciones

play05:39

tenemos que saber quién murió fue

play05:41

pikachu como

play05:42

picasso vida es menor o igual a cero y

play05:47

noten lo que hice acá no todo es menor o

play05:48

mayor puedo hacer igual mayor o igual

play05:51

menor o igual es pikachu punto vida

play05:53

menor o igual a cero no picacho punto y

play05:57

está perfecto pikachu punto vida no es

play06:00

menor que cero y como solamente hay dos

play06:02

pokemons y la ecuación del ciclo nos

play06:04

obligaba a salir cuando uno los dos

play06:06

estuviera muerto

play06:07

no necesitamos directamente preguntar si

play06:09

gigli pov es menor que cero ya es obvio

play06:11

que lo es no hay otra condición

play06:13

así que mostramos la animación de qué

play06:15

pikachu ganó estos son todas las bases

play06:16

para aprender a programar desde el

play06:18

inicio hoy aprendiste variables

play06:20

condiciones ciclos y si estás en este

play06:23

momento en el curso de programación

play06:24

básica de mejorándola en platz y nuestra

play06:27

plataforma educación online vas a

play06:28

encontrar todos los archivos en

play06:30

javascript que es código de programación

play06:32

de verdad para ver cómo esto funciona en

play06:34

el mundo real que paso a paso te va a

play06:36

estar mostrando qué vas a hacer esto es

play06:38

solo la introducción esto es solamente

play06:40

un vídeo pequeñito de un curso entero

play06:42

con clases en vivo de cómo aprender a

play06:45

programar desde cero el curso entero es

play06:47

completamente gratis

play06:48

mejorando la programación

play06:52

[Música]

Rate This

5.0 / 5 (0 votes)

Related Tags
Programming EducationPokémon BattlesAlgebra BasicsCoding TutorialGame MechanicsTurn-Based StrategyVariable UsageCycles in CodingConditional LogicBeginner FriendlyFree Course