How do I shuffle combinations uniquely

Just started using Construct 2? Post your questions here

Post » Mon Feb 01, 2016 12:17 pm

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
B
6
S
2
Posts: 7
Reputation: 466

Post » Mon Feb 01, 2016 7:51 pm

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:
Code: Select all
+------------------------------------------------+
| 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
   +--------------------------------------------+

You can find ideas of ways to do the shuffling elsewhere on the forum.
B
92
S
32
G
107
Posts: 5,274
Reputation: 69,959


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 0 guests