Zurück   Flashforum > Flash > ActionScript > ActionScript 1

Antwort
 
LinkBack Themen-Optionen Ansicht
Alt 26-08-2003, 20:42   #1 (permalink)
Use your brain!
 
Benutzerbild von MaDDeePee
 
Registriert seit: Aug 2003
Beiträge: 207
Heftige Rekursion splitten?

Hallo Leute!
Aus gegebenem Anlass, weil ich leider immernoch keine Lösung finde... Ich müsste die folgende Funktion irgendwie an den Stellen, auf denen sie sich selbst wieder aufruft, auf mehrere Frames splitten! Wenn nicht, dann ist die Berechnung zu aufwendig und es gibt ne Warnmeldung!

Weis jemand einen Rat, ohne dass ich viel Quellcode erklären muss? Schade, dass ein bewegen des Abspielkopfes vor der Funktionsaufrufung IN der Funktion nichts bringt......

*heul*

ActionScript:
  1. function checkfields($movepoints, $x, $y, $matrix, $lastfieldname, $startpath) {
  2.     var $path = $startpath;
  3.     if ($movepoints>=0) {
  4.         for ($i=0; $i<=($matrix.length-1); $i++) {
  5.             if (($matrix[$i][1] == $x) && ($matrix[$i][2] == $y)) {
  6.                 var $fieldname = $matrix[$i][0];
  7.                 var $terrainpoints = _root[$fieldname].$terrainpoints;
  8.                 break;
  9.             }
  10.         }
  11.         if (((_root[$fieldname].$path.split("|").length)-1) == 0) {
  12.             _root[$fieldname].$path = $path+"|"+_root[$fieldname]._x+"*"+_root[$fieldname]._y;
  13.             _root[$fieldname].$used_movepoints = $movepoints;
  14.         } else {
  15.             if (((_root[$fieldname].$path.split("|").length)>(($path+"|"+_root[$fieldname]._x+"*"+_root[$fieldname]._y).split("|").length)) && (_root[$fieldname].$used_movepoints>=$movepoints)) {
  16.                 _root[$fieldname].$path = $path+"|"+_root[$fieldname]._x+"*"+_root[$fieldname]._y;
  17.                 _root[$fieldname].$used_movepoints = $movepoints;
  18.             } else {
  19.                 return;
  20.             }
  21.         }
  22.     } else {
  23.         return;
  24.     }
  25.     if ((($movepoints-$terrainpoints)>=0) && ((_global.$selected_mclip[1] != _root[$fieldname]._x) || (_global.$selected_mclip[2] != _root[$fieldname]._y))) {
  26.         _root[$fieldname]._alpha = 100;
  27.         if (((_root[$lastfieldname]._x != ($x+(_global.$matrixwidth/2))) || (_root[$lastfieldname]._y != ($y-(_global.$matrixheight*0.75)))) && (($x+(_global.$matrixwidth/2))<(_global.$fieldsize_x*_global.$matrixwidth)) && ($y-(_global.$matrixheight*0.75)>0)) {
  28.             checkfields($movepoints-$terrainpoints, ($x+(_global.$matrixwidth/2)), ($y-(_global.$matrixheight*0.75)), $matrix, $fieldname, $path+"|"+_root[$fieldname]._x+"*"+_root[$fieldname]._y);
  29.         }
  30.         if (((_root[$lastfieldname]._x != ($x+_global.$matrixwidth)) || (_root[$lastfieldname]._y != ($y+0))) && (($x+_global.$matrixwidth)<(_global.$fieldsize_x*_global.$matrixwidth))) {
  31.             checkfields($movepoints-$terrainpoints, ($x+_global.$matrixwidth), ($y+0), $matrix, $fieldname, $path+"|"+_root[$fieldname]._x+"*"+_root[$fieldname]._y);
  32.         }
  33.         if (((_root[$lastfieldname]._x != ($x+(_global.$matrixwidth/2))) || (_root[$lastfieldname]._y != ($y+(_global.$matrixheight*0.75)))) && ((($x+(_global.$matrixwidth/2))<(_global.$fieldsize_x*_global.$matrixwidth)) && (($y+(_global.$matrixheight*0.75))<(_global.$fieldsize_y*_global.$matrixheight)))) {
  34.             checkfields($movepoints-$terrainpoints, ($x+(_global.$matrixwidth/2)), ($y+(_global.$matrixheight*0.75)), $matrix, $fieldname, $path+"|"+_root[$fieldname]._x+"*"+_root[$fieldname]._y);
  35.         }
  36.         if (((_root[$lastfieldname]._x != ($x-(_global.$matrixwidth/2))) || (_root[$lastfieldname]._y != ($y+(_global.$matrixheight*0.75)))) && ((($x-(_global.$matrixwidth/2))>0) && (($y+(_global.$matrixheight*0.75))<((_global.$fieldsize_y*_global.$matrixheight))))) {
  37.             checkfields($movepoints-$terrainpoints, ($x-(_global.$matrixwidth/2)), ($y+(_global.$matrixheight*0.75)), $matrix, $fieldname, $path+"|"+_root[$fieldname]._x+"*"+_root[$fieldname]._y);
  38.         }
  39.         if (((_root[$lastfieldname]._x != ($x-_global.$matrixwidth)) || (_root[$lastfieldname]._y != ($y-0))) && (($x-_global.$matrixwidth)>0)) {
  40.             checkfields($movepoints-$terrainpoints, ($x-_global.$matrixwidth), ($y-0), $matrix, $fieldname, $path+"|"+_root[$fieldname]._x+"*"+_root[$fieldname]._y);
  41.         }
  42.         if (((_root[$lastfieldname]._x != ($x-(_global.$matrixwidth/2))) || (_root[$lastfieldname]._y != ($y-(_global.$matrixheight*0.75)))) && ((($x-(_global.$matrixwidth/2))>0) && (($y-(_global.$matrixheight*0.75))>0))) {
  43.             checkfields($movepoints-$terrainpoints, ($x-(_global.$matrixwidth/2)), ($y-(_global.$matrixheight*0.75)), $matrix, $fieldname, $path+"|"+_root[$fieldname]._x+"*"+_root[$fieldname]._y);
  44.         }
  45.     }
  46.     return "done";
  47. }
MaDDeePee ist offline   Mit Zitat antworten
Alt 26-08-2003, 22:56   #2 (permalink)
helpQLODhelp
 
Benutzerbild von bokel
 
Registriert seit: Feb 2002
Ort: Köln
Beiträge: 8.505
Ich habe hier mal einen kleinen Test gemacht, bei dem ich eine rekursive Funktion umgebaut habe, so dass sie iterativ arbeitet.

ActionScript:
  1. // Einfache Rekursion
  2. function rekTest( a){
  3.     result.push(a);
  4.     if( a < 3) rekTest(a+1);
  5. }
  6. result = new Array();
  7. rekTest(0);
  8. trace(result);
  9.  
  10.  
  11. //Ohne Rekursion
  12. function rekTest2( a){
  13.     var stack = new Array();
  14.     stack.push( a);
  15.     do {
  16.         a = stack.pop();
  17.         result.push(a);
  18.         if( a < 3) stack.push(a + 1);
  19.     } while( stack.length);
  20. }
  21. result = new Array();
  22. rekTest2(0);
  23. trace(result);
  24.  
  25.  
  26. // Doppelte Rekursion
  27. function rekTest3( a){
  28.     result.push(a);
  29.     if( a < 3) rekTest3(a+1);
  30.     if( a < 4) rekTest3(a+1);
  31. }
  32. result = new Array();
  33. rekTest3(0);
  34. trace(result);
  35.  
  36. // Ohne Rekursion
  37. function rekTest4( a){
  38.     var stack = new Array();
  39.     stack.push( a);
  40.     do {
  41.         a = stack.pop();
  42.         result.push(a);
  43.         if( a < 3) stack.push(a + 1);
  44.         if( a < 4) stack.push(a + 1);
  45.     } while( stack.length);
  46. }
  47. result = new Array();
  48. rekTest4(0);
  49. trace(result);

Wenn du dein Script nach diesem Stil umbauen könntest, dann könntest du es jederzeit unterbrechen und im nächsten Frame weiterlaufen lassen.

mfg r.
bokel ist offline   Mit Zitat antworten
Alt 29-08-2003, 13:52   #3 (permalink)
Use your brain!
 
Benutzerbild von MaDDeePee
 
Registriert seit: Aug 2003
Beiträge: 207
Thumbs up

Ein vorbildliches posting!

Vielen Dank!

Es hat hat zwar seine Zeit gedauert, aber ich habe nun den Umbau geschafft und alles läuft nun ohne Warnmeldung!

*respekt-zeig*

Grüße,

Daniel
MaDDeePee ist offline   Mit Zitat antworten
Antwort

Lesezeichen

Themen-Optionen
Ansicht

Forumregeln
Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks sind an
Pingbacks sind an
Refbacks sind an



Alle Zeitangaben in WEZ +1. Es ist jetzt 15:03 Uhr.

Domains, Webhosting & Vserver von Host Europe
Unterstützt das Flashforum!
Adobe User Group


Copyright ©1999 – 2012 Marc Thiele