Browse Source

Added images

root 7 years ago
parent
commit
b74550b309
5 changed files with 342 additions and 2 deletions
  1. 168
    1
      README-en.md
  2. 174
    1
      README-es.md
  3. BIN
      images/main1.png
  4. BIN
      images/main2.png
  5. BIN
      images/main3.png

+ 168
- 1
README-en.md View File

@@ -1 +1,168 @@
1
-![](titlepage.png)
1
+#Repetition Structures - Game of sticks
2
+
3
+![main1.png](images/main1.png)
4
+![main2.png](images/main2.png)
5
+![main3.png](images/main3.png)
6
+
7
+One of the advantages of using computer programs is that we can easily implement repetitive tasks. Structures such as the `for`, `while`, and `do-while` allow us to repeat a block of instructions as many times as needed. These structures are also known as *repetition structures*. In today’s laboratory experience you will practice the use of loops to implement a game of sticks in C++.
8
+
9
+##Objectives:
10
+
11
+Design algorithms to realize a task.
12
+Translate an algorithm into pseudocode.
13
+Implement a complete program.
14
+Practice the use of repetition structures.
15
+
16
+This laboratory experience is an adaptation of the exercise found in:
17
+http://nifty.stanford.edu/2014/laaksonen-vihavainen-game-of-sticks/handout.html.
18
+
19
+##Pre-Lab
20
+
21
+Before coming to the laboratory session you should have:
22
+
23
+Reviewed the basic concepts related to repetition structures.
24
+
25
+2. Studied the concepts and instructions for the laboratory session.
26
+
27
+3. Taken the Pre-Lab quiz available through the course’s Moodle portal.
28
+
29
+---
30
+
31
+---
32
+
33
+## Game of Sticks
34
+
35
+The game of sticks is played between two contestants. At the beginning of the game there is a pile of sticks on the table. In each turn, each player takes from 1 to 3 sticks from the table. The player that picks up the last stick loses the game.
36
+
37
+For example, a game of sticks could go like this:
38
+
39
+*  The game starts with 20 sticks on the table.
40
+* Aurora takes 3 sticks, there are 17 left.
41
+* Bruno takes 2 sticks, there are 15 left.
42
+* Aurora takes 1 stick, there are 14 left.
43
+* Bruno takes 3 sticks, there are 11 left.
44
+* Aurora takes 2 sticks, there are 9 left.
45
+* Bruno takes 2 sticks, there are 7 left.
46
+* Aurora takes 3 sticks, there are 4 left.
47
+* Bruno takes 1 stick, there are 3 left.
48
+* Aurora takes 2 sticks, there is 1 left.
49
+* Bruno has to take the last stick and loses the game.
50
+
51
+---
52
+
53
+---
54
+
55
+
56
+## Laboratory Session
57
+
58
+In today’s laboratory experience you will practice the use of loops to implement a game of sticks.
59
+
60
+### Exercise 1: Design the algorithm
61
+
62
+Design an algorithm so that two people can play the game of sticks on the computer. The algorithm should have these restrictions:
63
+
64
+At the beginning, it should ask the number of sticks there will be on the table. The range of accepted numbers is [10, 100]. If the user enters a number outside of this range, the program will continue asking.
65
+
66
+In each turn, the player will be allowed to take from 1 to 3 sticks (without exceeding the number of available sticks on the table). If the user enters a number outside of this range, the program will continue asking.
67
+
68
+When the game ends, the program should say who the winner is.
69
+
70
+**Example**
71
+
72
+```
73
+Welcome to the game of sticks!
74
+
75
+Enter an initial number of sticks [10,100]: 150
76
+Enter an initial number of sticks [10,100]: 10
77
+
78
+There are 10 sticks on the table.
79
+Player 1 - Enter the number of sticks to take (1-3): 4
80
+Player 1 - Enter the number of sticks to take (1-3): 3
81
+
82
+There are 7 sticks on the table.
83
+Player 2 - Enter the number of sticks to take (1-3): 3
84
+
85
+There are 4 sticks on the table.
86
+Player 1 - Enter the number of sticks to take (1-3): 2
87
+
88
+There are 2 sticks on the table.
89
+Player 2 - Enter the number of sticks to take (1-2): 3
90
+Player 2  - Enter the number of sticks to take (1-2): 1
91
+
92
+There is 1 stick on the table.
93
+Player 1 - Enter the number of sticks to take (1-1): 1
94
+You lose, Player 1 :-(
95
+```
96
+
97
+###Exercise 2: Write the pseudocode
98
+
99
+#### Instructions:
100
+
101
+1. Close the computer.
102
+
103
+2. Express the algorithm in pseudocode.
104
+
105
+3. Execute the pseudocode by hand to capture logical errors. Try it with various *extreme* cases and write the results by hand. [Here](https://docs.google.com/a/upr.edu/presentation/d/1m-lXCUTKhCZC8vTnmtAXwfxQjIKkSVhTUrcywiZsdbQ/edit?usp=sharing) you can see an example of how to hand check an algorithm.
106
+
107
+
108
+###Exercise 3: Implement the code
109
+
110
+#### Instructions: 
111
+
112
+1. Open the computer.
113
+
114
+2. Implement the algorithm in a C++ program.
115
+
116
+**Help**
117
+
118
+1) Use the `int` type variable to keep track of the player. At the end of each turn, change the player like this: 
119
+
120
+   ```cpp
121
+   player = player == 1 ? 2 : 1;
122
+
123
+   ```
124
+or number the players as 0 and 1 and use your mastery of the modulus operator:
125
+
126
+   ```cpp
127
+   player = (player + 1) % 2;
128
+
129
+   ```
130
+
131
+2) Think about the 3 commandments of repetition structures:
132
+
133
+   a. What is the loop control variable and what condition will be used to iterate the loop?
134
+
135
+   b. What value should the loop control variable be initialized to?
136
+
137
+   c. How is the loop control variable modified during each iteration?
138
+
139
+###Deliverables: 
140
+
141
+Use “Deliverables 1” in Moodle to hand in the pseudocode for the game of sticks.
142
+
143
+2. Use “Deliverables 2” in Moodle to hand in the paper where you and your partner executed the pseudocode by hand. 
144
+
145
+3. Use “Deliverables 3” in Moodle to hand in a `.cpp` file with the C++ program to play the game of sticks. The program should not have compiler errors, should be documented and function as intended. Remember to use good programming techniques, include the name of the programmers and document your program.
146
+
147
+
148
+
149
+---
150
+
151
+
152
+---
153
+
154
+##References
155
+
156
+[1] http://nifty.stanford.edu/2014/laaksonen-vihavainen-game-of-sticks/handout.html
157
+
158
+[2] http://www.gardengames.com/acatalog/509_Garden_Games_Giant_Pick-Up_Sticks.html
159
+
160
+[3] http://www.toves.org/books/java/ch05-while/
161
+
162
+[4] http://forum.codecall.net/topic/35425-pseudocode-tutorial-the-basics/page-2
163
+
164
+---
165
+
166
+---
167
+
168
+---

+ 174
- 1
README-es.md View File

@@ -1 +1,174 @@
1
-![](./titlepage.png)
1
+#Estructuras de repetición - Juego de palitos
2
+
3
+![main1.png](images/main1.png)
4
+![main2.png](images/main2.png)
5
+![main3.png](images/main3.png)
6
+
7
+
8
+
9
+Una de las ventajas de utilizar programas de computadoras es que podemos realizar tareas repetitivas fácilmente. Los ciclos como `for`, `while`, y `do-while` son  estructuras de control que nos permiten repetir un conjunto de instrucciones. A estas estructuras también se les llama *estructuras de repetición*.  En la experiencia de laboratorio de hoy practicarás el uso de ciclos  para implementar el juego de "palitos" en C++.
10
+
11
+
12
+##Objetivos:
13
+
14
+1. Diseñar algoritmos para realizar una tarea.
15
+2. Traducir un algoritmo a pseudocódigo.
16
+3. Implementar un programa completo.
17
+4. Practicar el uso de estructuras de repetición.
18
+
19
+
20
+Esta experiencia de laboratorio es una adaptación del ejercicio en: http://nifty.stanford.edu/2014/laaksonen-vihavainen-game-of-sticks/handout.html.
21
+
22
+##Pre-Lab:
23
+
24
+Antes de llegar al laboratorio debes haber:
25
+
26
+1. Repasado los conceptos básicos relacionados a estructuras de repetición.
27
+
28
+2. Estudiado los conceptos e instrucciones para la sesión de laboratorio.
29
+
30
+3. Tomado el quiz Pre-Lab que se encuentra en Moodle.
31
+
32
+---
33
+
34
+---
35
+
36
+## Palitos (Game of Sticks)
37
+
38
+
39
+El juego de los palitos se juega entre dos contrincantes. Al principio del juego hay un montículo de palitos en la mesa. En cada turno, cada jugador retira de 1 a 3 palitos de la mesa. El jugador que recoge el último palito pierde el juego.
40
+
41
+Por ejemplo, un juego de palitos podría transcurrir así:
42
+
43
+* El juego comienza con 20 palitos en la mesa.
44
+* Aurora retira 3 palitos, faltan 17.
45
+* Bruno retira 2 palitos, faltan 15.
46
+* Aurora retira 1 palito, faltan 14.
47
+* Bruno retira 3 palitos, faltan 11.
48
+* Aurora retira 2 palitos, faltan 9.
49
+* Bruno retira 2 palitos, faltan 7.
50
+* Aurora retira 3 palitos, faltan 4.
51
+* Bruno retira 1 palito, faltan 3.
52
+* Aurora retira 2 palitos, falta 1.
53
+* Bruno tiene que retirar el único palito restante y pierde el juego.
54
+
55
+
56
+---
57
+
58
+---
59
+
60
+
61
+##Sesión de laboratorio:
62
+
63
+En la experiencia de laboratorio de hoy practicarás el uso de ciclos para implementar el juego de palitos.
64
+
65
+###Ejercicio 1: Diseñar el algoritmo
66
+
67
+
68
+Diseña un algoritmo para que dos personas puedan jugar el juego de los palitos en la computadora. El algoritmo debe respetar las siguientes restricciones:
69
+
70
+1. Al principio debe pedir el número de palitos que habrá en la mesa. El rango de números aceptados será de [10,100]. Si el usuario entra un número fuera de ese rango, el programa continuará preguntando.
71
+
72
+2. En cada jugada, se permitirá que el jugador retire de 1 a 3 palitos (sin exceder el número de palitos disponibles en la mesa). Si el usuario entra un número fuera de tal rango, el programa continuará preguntando.
73
+
74
+3. Al finalizar el juego, el programa debe informar quién fue el ganador.
75
+
76
+**Ejemplo:**
77
+
78
+```
79
+¡Bienvenidos al juego de palitos!
80
+
81
+Entre el numero inicial de palitos [10,100]: 150
82
+Entre el numero inicial de palitos [10,100]: 10
83
+
84
+Hay 10 palitos en la mesa.
85
+Jugador 1 - Entre el numero de palitos a retirar (1-3): 4
86
+Jugador 1 - Entre el numero de palitos a retirar (1-3): 3
87
+
88
+Hay 7 palitos en la mesa.
89
+Jugador 2 - Entre el numero de palitos a retirar (1-3): 3
90
+
91
+Hay 4 palitos en la mesa.
92
+Jugador 1 - Entre el numero de palitos a retirar (1-3): 2
93
+
94
+Hay 2 palitos en la mesa.
95
+Jugador 2 - Entre el numero de palitos a retirar (1-2): 3
96
+Jugador 2 - Entre el numero de palitos a retirar (1-2): 1
97
+
98
+Hay 1 palito en la mesa.
99
+Jugador 1 - Entre el numero de palitos a retirar (1-1): 1
100
+Perdiste Jugador 1 :-(
101
+```
102
+
103
+
104
+###Ejercicio 2: Escribir el pseudocódigo
105
+
106
+#### Instrucciones:
107
+
108
+0. Cierra la computadora.
109
+
110
+1. Expresa el algoritmo en pseudocódigo. 
111
+
112
+2. Ejecuta "a mano" el pseudocódigo para capturar errores lógicos. Trátalo con varios casos *extremos* y escribe sus resultados a mano. [Aquí](https://docs.google.com/a/upr.edu/presentation/d/1m-lXCUTKhCZC8vTnmtAXwfxQjIKkSVhTUrcywiZsdbQ/edit?usp=sharing) puedes ver un ejemplo de como hacer "hand-checking" a un algoritmo.
113
+
114
+
115
+###Ejercicio 3: Implementar el código
116
+
117
+#### Instrucciones:
118
+
119
+0. Abre la computadora.
120
+
121
+1. Implementa el algoritmo en un programa en C++.
122
+
123
+**Ayudas:**
124
+
125
+1. Utiliza una variable de tipo `int` para llevar cuenta del jugador. Al final de cada turno, intercambia el jugador asi:
126
+
127
+    ```cpp
128
+    jugador = jugador == 1 ? 2 : 1;
129
+    ```
130
+
131
+    o enumera los jugadores como 0 y 1 y usa tu maestría en operador módulo:
132
+
133
+    ```cpp
134
+    jugador = (jugador + 1) % 2;
135
+    ```
136
+
137
+2. Piensa en los 3 mandamientos de las estructuras de repetición:
138
+
139
+    a. ¿Cuál es la variable de control del ciclo y que condición será la que mantiene el ciclo iterando? 
140
+
141
+    b. ¿A que se inicializa la variable de control del ciclo?
142
+    
143
+    c. ¿Cómo se modifica la variable de control del ciclo en cada iteración?
144
+
145
+
146
+###Entregas:
147
+
148
+1. Utiliza "Entrega 1" en Moodle para entregar el pseudocódigo del juego de palitos.
149
+
150
+2. Utiliza "Entrega 2" en Moodle para entregar el papel donde tu y tu pareja hicieron la ejecución "a mano" del pseudocódigo del juego de palitos.
151
+
152
+3. Utiliza "Entrega 3" en Moodle para entregar un archivo `.cpp` con el programa en C++ para jugar palitos. El programa no debe tener errores de compilación, debe estar debidamente documentado y funcionar "como se supone". Recuerda utilizar buenas prácticas de programación, incluir el nombre de los programadores y documentar tu programa.
153
+
154
+
155
+
156
+---
157
+
158
+---
159
+
160
+##Referencias
161
+
162
+[1] http://nifty.stanford.edu/2014/laaksonen-vihavainen-game-of-sticks/handout.html
163
+
164
+[2] http://www.gardengames.com/acatalog/509_Garden_Games_Giant_Pick-Up_Sticks.html
165
+
166
+[3] http://www.toves.org/books/java/ch05-while/
167
+
168
+[4] http://forum.codecall.net/topic/35425-pseudocode-tutorial-the-basics/page-2
169
+
170
+---
171
+
172
+---
173
+
174
+---

BIN
images/main1.png View File


BIN
images/main2.png View File


BIN
images/main3.png View File