You can also use:

combo=0;
if(a){combo+=1000;}
if(b){combo+=100;}
if(c){combo+=10;}
if(d){combo+=1;}

Then convert combo to a string and check the character at each position ( charAt(0), charAt(1), etc.) for a one or zero, which will tell you if the associated variable is true or false.

-Marc

At 10:47 AM 1/25/2006, you wrote:
You seem to have something like a 'Round Robin' situation, only more complex
as it is not only about pairs, but also about singles/triplets/quadruplets.

If each of these possible combinations leads to a different action, the
if/else if or switch statement will naturally be very long...

To make it quite a bit more readable and thus managable, maybe you could do

        combo = '';

        if ( a ){ combo += 'a'; }
        if ( b ){ combo += 'b'; }
        if ( c ){ combo += 'c'; }
        if ( d ){ combo += 'd'; }

        switch(combo){
                case 'a':
                        // do stuff
                        brek;
                case 'ab':
                        // do some other stuff
                        break;
                case 'abc':

                        //etc.
        }

For finding all the 'pairs' see my RoundRobin class below (used to be in the
archives, but can't find it anymore)

hth
--------------
Andreas Weber
motiondraw.com


class com.motiondraw.util.RoundRobin{

        /*

        Usage

        import com.motiondraw.util.RoundRobin

        numPlayers = 12;

        // create players
        players = new Array();
        for(var i=0; i<numPlayers; i++){
                players[i] = String.fromCharCode(65+i);
        }

        var rr:RoundRobin = new RoundRobin(players);
        rr.displaySchedule();


        */

        public var players:Array;
        public var schedule:Array;

        function RoundRobin(players:Array){
                init.apply(this, arguments);
        }

        function init(players){
                this.players = players;

                var pc = players.slice(0);
                var n = pc.length;
                if(n%2){
                        var odd = true;
                        pc.push('@');
                        n++;
                }

                var nr = n - 1;
                var r = new Array();
                schedule = new Array();

                for (var i=0; i<nr; i++) {
                        r[i] = new Array();
                        r[i][0] = pc[nr];
                        for (var j=0; j<n-1; j++) {
                                r[i][j+1] = pc[(i+j) % (n-1)];
                        }
                }

                for(var i=0, len=r.length; i<len; i++){
                        schedule[i] = new Array();
                        for(var j=0; j<nr/2; j++){
                                if(!(odd && j==0)){
schedule[i].push([r[i][j], r[i][nr-j]]);
                                }
                        }
                }
        }

        public function displaySchedule(short:Boolean){
                var output = new Array();

                for(var i=0, len=schedule.length; i<len; i++){

                        //trace('--- '+(i+1)+'. round ---');

                        for(var j=0, len2=schedule[i].length; j<len2; j++){
//trace(' '+j+' '+schedule[i][j][0]+' vs. '+schedule[i][j][1])

output.push('"'+schedule[i][j][0]+''+schedule[i][j][1]+'"');
                        }
                }
                trace(output);
                trace(output.length);
        }
}



-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of eric
dolecki
Sent: Wednesday, January 25, 2006 7:03 PM
To: Flashcoders mailing list
Subject: [Flashcoders] checking combinations


I have 4 variables I need to check the states of routinely... and
combinations thereof.

I am assuming that if I have a counter, and interogate and += them values, I
can then check the value of the counter to determine the combinations.

psudeo-code:

var counter:Number = 0;
if ( a ){ counter += 2; }
if ( b ){ counter += 3; }
if ( c ){ counter += 6; }
if ( d ){ counter += 12;}

if ( counter == 2 ){
     // only a was true
} else if ( counter == 3 ){
     // only b was true
}  ...

Which is fine, but thats gonna be one honkin' if else statement to catch all
the combinations.

Is there a better way of doing this that will catch all the possible
combinations in an elegant way?

- edolecki
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to