How do I shuffle combinations uniquely

  • Hi there,

    This is my problem:

    I have an array containing a combination of values, say 1 a, 2 b, 3 c, 4 d and 5 e (in my case, the numbers are clients and the alphabetics are characters in my game)

    Now i want to create new combinations of clients and characters where no combination may be already present in the current array.

    example:

    1a, 2b, 3c, 4d, 5e may result in 1b, 2a, 3d, 4e and 5c but not in 1b ,2a,3d,4c,5e (5e already exists).

    Please help.

    I need to execute these steps multiple times per game session, but it is enought to check against the last created combinations.

    Mark

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Basically the logic would be :

    copy array1 to array2

    shuffle array2

    compare array1 to array2

    and if any two values are the same repeat the shuffle

    A partial look of how the loop should look is this:

    +------------------------------------------------+
    | while                                          |
    +------------------------------------------------+
    	local variable again=0
    	+--------------------------------------------+
    	|                                            | shuffle array2
    	+--------------------------------------------+
    	+--------------------------------------------+
    	| array: for each x                          | set again to 1
    	| array: current value=array2.at(array.curX) |
    	+--------------------------------------------+
    	+--------------------------------------------+
    	| again=0                                    | stop loop
    	+--------------------------------------------+[/code:ents26h8]
    You can find ideas of ways to do the shuffling elsewhere on the forum.
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)