Quantcast
Channel: Questions in topic: "javascipt"
Viewing all articles
Browse latest Browse all 1875

Stack overflow on finite recursion

$
0
0
I tried to make an algorithm to fill all tiles adjacent to each other with the same color, but when I run it it throws the Exception. This is the code: function Colorear(naciones:Transform[],colores:Color[],n:int,color:Color){ if(colores[n].a==0){ colores[n]=color; for(var nacion_vecina:Transform in naciones[n].GetComponent(nation1).locacion.GetComponent(ubicacion).Conexiones){ var lugar=System.Array.IndexOf(naciones,nacion_vecina.GetComponent(nation_helper1).nation); if(nacion_vecina.GetComponent(nation_helper1).nation!=null){ if(nacion_vecina.GetComponent(nation_helper1).nation.GetComponent(nation1).colornacion==naciones[n].GetComponent(nation1).colornacion && colores[lugar].a==0){ Colorear(naciones,colores,lugar,colores[n]); } } } } } Since the amount of nations is finite, and this code colors them each time it's called **before** making the recursion, it should eventually end (they are only a few hundred nations), and yet it crashes.

Viewing all articles
Browse latest Browse all 1875

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>