Thursday, February 2, 2017

WeDo & Scratch: Goal Keeper

Let's continue our soccer game programming! Continuemos la programación del juego de fútbol!

In a soccer game we also have a goal keeper to face the goal kicker. Since no many people like to be the goalie, what better than having a robotic friend to block the shots and to run between the posts. Penalties now look more interesting!

Four our goal keeper to be really effective between the posts, it needs to move really fast without the other team being able to forecast the moves. For that we need to use random inputs using the dice in the WeDo software.

Pero como en el juego de fútbol no solo tenemos al tirador, para ser justos también debemos tener a un portero, y como no muchos quieren ser porteros, que mejor que tener un portero robótico que intente atajar nuestros disparos desde el punto penal.

Nuestro portero, para ser efectivo debe ser capaz de moverse muy rápidamente sin que los jugadores puedan prever su siguiente movimiento. Para ello podemos utilizar una entrada al azar utilizando el boque de los dados del software del WeDo. 


We need to use the start button (the play icon) and then the repeat block for the goalie to continue moving like crazy. We need to assign one direction for the motor, then to wait a random time (using the dice), turn the motor the other way, then wait another random time before moving the other way, and to start all over again.

Tenemos que usar el bloque iniciar  (triangulo verde) y luego el bloque de repetir para que nuestro portero este moviéndose constantemente. Asignamos al motor que gire en una dirección, que espere aleatoriamente un rato (para eso los dados) antes de cambiar de dirección, que vuelva a esperar al azar nuevamente antes de repetir el ciclo una y otra vez más.

Coding in Scratch is quite similar. We need to look for the start block (“when the flag is clicked” command) and the repeat forever block. Those are under the Control menu. The wait command (“wait __ secs”) is also found over there. The motor commands are found under the Motion menu for the motor to turn this way and to turn in reverse. You need to look for the “pick random __ to __ secs” code under the Operators menu. You need to fill out the numbers 1 and 3 on the empty
cells.



Tenemos que usar el bloque iniciar  (triangulo verde) y luego el bloque de repetir para que nuestro portero este moviéndose constantemente. Asignamos al motor que gire en una dirección, que espere aleatoriamente un rato (para eso los dados) antes de cambiar de dirección, que vuelva a esperar al azar nuevamente antes de repetir el ciclo una y otra vez más.




However, who is taking note on the score? Is not easier to develop a program to do it automatically rather than manually? Why not coding it for to the computer to carry the tabs. You can do it with the WeDo software in another piece of code running alongside the goal keeper. We need the Display block (the red icons) configured to start with the number zero (to start the score using a white background). A repeat block is also required, the wait (hourglass icon) with the distance sensor attached (to detect if a ball crossed the goal line), another display block (add to display block to add 1 every time an annotation is detected), wait for half a second (the number 5 on the image), and repeat the procedure all over.

WeDo will show an image similar to the one shown below with the score of the game.



Pero, ¿quién lleva el conteo de los goles? ¿Acaso no es más sencillo programarlo usando el ordenador que tener que estar anotándolo manualmente? Para ello en el software del WeDo creamos otro programa para que realice el conteo. Necesitamos el bloque de la pantalla (los de color rojo) configurado con el número cero (para que realice un conteo sobre un fondo de color blanco). También se requiere el bloque de repetir, el de esperar, el del sensor de distancia (para detectar si un balón atravesó la portería), otro bloque de pantalla, pero el de sumar a pantalla (con un signo de suma) que se encarga de sumar una unidad cada vez que el sensor de distancia detecta algo pasar por el frente, y el de esperar por medio segundo antes de volverse a repetir.

En WeDo, se verá una ventana como la de abajo mostrando el conteo de los goles que detectó el sensor.
The programming in Scratch follows the same approach as the WeDo code (a second program alongside the goal keeper code). You need the start button (“when the flag is clicked”) and a score counter starting from zero. For this, you need to create a new variable called score. That needs to be done under the Variables menu (Make a variable and click the checkbox to make it visible on the white canvas). The first time you enter the menu it will be empty. After that, you need to use the “set __ to __” block, choose the variable you created from the drop down menu and add a zero.  Under the Control menu you need to choose the forever block, the “wait until __” and the “wait __ secs”. On the Sensors menu you need to choose the “__ sensor value” block, find the distance sensor on the drop down menu. You need also to add a comparison block, the less than (“__<__“) command from the Operators menu. You can test variations of  this number for better results (50 was found adecuate for this part as in the image). You need to program the wait block for half a second, otherwise it may count the same annotation multiple times. Last, but not least, you need to choose the “change __ by __” block from the Variables menu and select the increment for the last command.


En Scratch el programa es bastante similar. Tenemos que escribir un nuevo programa, colocar el bloque de iniciar (al presionar la bandera) y colocar el contador de goles en cero antes del bloque de repetir. Ahora se necesita crear una nueva variable bajo el menú de Variables (la última opción). Si no creas la variable el menú estará vacío. En este programa se creó una llamada goles, se seleccionó el bloque de “fijar ____ a __”, allí puedes seleccionar la variable creada e inicializarla en el número cero. En el menú Control está el bloque de “repetir por siempre”, el bloque de “esperar hasta que” y el de “esperar __ segundos”. En el menú de Sensores podemos seleccionar el de distancia, pero es necesario ir al menú de Operadores y buscar el bloque de comparación de menor que (“__<__ “). Puedes escoger el número para esta comparación que te dé mejores resultados. Se escogió 50 en la imagen de abajo. Lo programamos para que espere medio segundo, de lo contrario puede contar el mismo gol varias veces seguidas. Por último el bloque de “cambiar ___ por __” permite seleccionar el incremento de la variable escogida.

This program will show a counter on Scratch similar to the image shown below with the score.


En Scratch, podremos ver una imagen parecido a la siguiente realizando el conteo de la cantidad de goles.


Enjoy, subscribe and

Disfruta, suscríbete y

2 comments:

  1. Very informative. I am thankful to you for sharing this awesome article with this helpful knowledge. This is the blog that provide the lots of good information thanks for provide such good information. Every time I come here, I get some very useful info. This one is the best post on. Thanks for sharing this unique article. By the way, here you can find my blog at custom essay writing service.

    ReplyDelete