Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reciclando papeles #59

Merged
merged 11 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pilas-bloques-exercises",
"version": "1.4.13",
"version": "1.4.15",
"description": "Exercises for Pilas Bloques",
"homepage": "http://pilasbloques.program.ar",
"author": {
Expand Down
17 changes: 16 additions & 1 deletion src/actores/segundoCiclo/Capy/Tacho.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
/// <reference path="../../ActorAnimado.ts"/>
class Tacho extends ActorAnimado {
lleno;
static _grilla = 'actor.tacho.png'

constructor(lleno = false) {
super(0, 0, {cantColumnas: 2});
this.definirAnimacion("vacio", [0], 1);
this.definirAnimacion("lleno", [1], 1);

this.lleno = lleno;
if(lleno)
this.cargarAnimacion("lleno")
else
this.cargarAnimacion("vacio")
}

vaciar() {
this.cargarAnimacion("vacio")
this.lleno = false;
}

llenar() {
this.cargarAnimacion("lleno")
this.lleno = true;
}

estaLleno(): boolean {
return this.lleno;
}
}
88 changes: 88 additions & 0 deletions src/escenas/ReciclandoPapeles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/// <reference path = "EscenaActividad.ts" />
/// <reference path = "../actores/CuadriculaMultiple.ts" />
/// <reference path = "../actores/segundoCiclo/Capy/Tacho.ts" />
/// <reference path = "../actores/segundoCiclo/Capy/Papel.ts" />
/// <reference path = "../actores/segundoCiclo/Capy/Capy.ts" />

class ReciclandoPapeles extends EscenaActividad {
cuadricula : CuadriculaMultiple;
definidor: DefinidorColumnasFijo;
automata;
tachos;
papeles;

iniciar() {
this.fondo = new Fondo('fondo.capy.png',0,0);
this.definidor = new DefinidorColumnasFijo(5,[5,6,8,4,7]);
this.cuadricula = new CuadriculaMultiple(
this.definidor,
0,0,
{separacionEntreCasillas: 5},
{grilla:'casilla.futbolRobots2.png',
cantFilas: 5,
cantColumnas: 16,
alto:45,ancho:45}
);
this.cuadricula.cambiarImagenInicio('casillainiciomono.png');

var capy = new Capy()
capy.escala *= 0.5;
this.automata = new ActorCompuesto(0, 0, { subactores: [capy] });
this.cuadricula.agregarActor(this.automata, 0, 0);
this.automata.escala *= 0.3;
this.automata.y += 40;

this.papeles=[]
this.tachos=[]

this.cuadricula.forEachFila((nroFila: number) => this.agregarTacho(nroFila))
this.cuadricula.forEachFila((nroFila: number) => this.agregarPapel(nroFila))

}

agregarPapel(fila: number) {
var elPapel = new Papel()
this.cuadricula.agregarActor(elPapel, fila, 0)
elPapel.aprender(Flotar, { Desvio: 2 });
this.papeles.push( new ActorCompuesto(0, 0, { subactores: [elPapel] }));
}

agregarTacho(fila: number) {
var elTacho = new Tacho()
this.cuadricula.agregarActor(elTacho, fila, this.definidor.tamanos[fila]-1)
this.tachos.push( new ActorCompuesto(0, 0, { subactores: [elTacho] }));
this.tachos.escala *= 0.8;
}

estaResueltoElProblema(){
return this.hayTachosLlenosAlFinalDeLasFilas() && this.cuadricula.cantFilas === this.cantidadDeTachosLlenos() && !this.cantidadDePapelesSinLevantar();
}

hayTachosLlenosAlFinalDeLasFilas(){
return this.tachos.every( tacho => tacho.subactores[0].estaLleno() );
}

cantidadDePapelesSinLevantar(): number {
var cant: number = 0;
this.papeles.forEach( papel => cant += papel.subactores[0].vivo );
return cant;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

¿Se usa la cantidad para algo más que si está resuelto el problema?

Suggested change
cantidadDePapelesSinLevantar(): number {
var cant: number = 0;
this.papeles.forEach( papel => cant += papel.subactores[0].vivo );
return cant;
}
hayPapelesSinLevantar(): boolean {
return this.papeles.every( papel => papel.subactores[0].vivo );
}

Si es solo para verificar si hay papeles quizás queda mas expresivo así

Copy link
Contributor Author

@danielferro69 danielferro69 Oct 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Por un "problema en la logica" donde puedo levantar un papel y poner ese MISMO papel, sin soltarlo en todos los tachos, es que corroboro que sea la cantidad de filas. Por eso hice la cuenta. Es mas que nada para manejar el error.
No... estoy mal yo... Eso es con los tachos, no con los papeles. Esta perfecto lo que sugeris. Ya lo uso asi. Gracias

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

de todas formas, me bajo tu reforma y la pruebo en los tests y en el ejemplo. Gracias


cantidadDeTachosLlenos(): number {
var cant: number = 0;
this.tachos.forEach( tacho => cant += tacho.subactores[0].estaLleno() );
return cant;
}

ultimasCasillas(){
return this.cuadricula.filterCasillas(casilla => casilla.esFin());
}

actualizar(): void {
super.actualizar();
if( !this.tachos[this.automata.casillaActual().nroFila].subactores[0].estaLleno() &&
this.automata.tieneAlgoEnLaMano() &&
this.automata.casillaActual() === this.tachos[this.automata.casillaActual().nroFila].subactores[0].casillaActual() )
this.tachos[this.automata.casillaActual().nroFila].subactores[0].llenar();
}
}
10 changes: 9 additions & 1 deletion src/escenas/libroPrimaria/EscenaDesdeMapa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ abstract class EscenaDesdeMapa extends EscenaActividad {
let nroColumna: number = casilla.nroColumna;
let ids: string[] = mapa[nroFila][nroColumna].split("&");
ids.forEach(id => {
if (id != '' && id != ' ' && id != '-' && id != '_') { // si no es casilla libre
if(id === '+'){
this.guardarPosicionFinal([nroColumna, nroFila])
}else if (id != '' && id != ' ' && id != '-' && id != '_') { // si no es casilla libre
let actor = this.mapearIdentificadorAActor(id, nroFila, nroColumna);
cuadricula.agregarActorEnCasilla(actor, casilla, true);
}
Expand Down Expand Up @@ -497,6 +499,12 @@ class GeneradorDeCasillaNula implements GeneradorDeCasilla {
esAleatorioPara(generador: GeneradorDeMapasAleatorios): boolean { return false; }
}

/** Corresponde a las casillas indicadas con `+`. */
class GeneradorDeCasillaFinal implements GeneradorDeCasilla {
generarSemillaDeCasilla(generador: GeneradorDeMapasAleatorios): SemillaDeCasilla { return new SemillaDeCasilla('+'); }
esAleatorioPara(generador: GeneradorDeMapasAleatorios): boolean { return false; }
}

/** Corresponde al modificador `?` (recursivo). */
class GeneradorDeCasillaMaybe implements GeneradorDeCasilla {
constructor(private generadorInterno: GeneradorDeCasilla, private proba?: number) { }
Expand Down
5 changes: 4 additions & 1 deletion src/gramaticaAleatoria.ne
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ Atom -> Id {% d => new GeneradorDeCasillaSimple(d[0]) %}
| Col {% id %}
| Nil {% id %}
| Void {% id %}
| "(" _ Term _ ")" {% d => d[2] %}
| End {% id %}
| "(" _ Term _ ")" {% d => d[2] %}
Id -> [a-zA-Z0-9]:+ {% d => d[0].join("") %}
Bag -> "$" {% d => new GeneradorDeCasillaBolsa() %}
| "$" _ Id {% d => new GeneradorDeCasillaBolsa(d[2]) %}
Expand All @@ -56,4 +57,6 @@ Macro -> "#" _ Id {% d => new GeneradorDeCasillaMacro(d[2]) %}

And -> Atom _ "&" _ Atom {% d => new GeneradorDeCasillaAnd(d[0], d[4]) %}

End -> "+" {% d => new GeneradorDeCasillaFinal() %}

Void -> "_" {% d => new GeneradorDeCasillaNula() %}
Loading