# 矩阵组合逻辑

Here is my first and second attempts at asking this question:

Here is the problem:

• I have several ( like 20 ) Boolean validations ( true / false )
• All Boolean validations as a whole also have a validation Result

I'm trying to find the best solution to test all the validations and also the validation result. I was looking into a Matrix to hold all possible combinations but that might be an overkill.

Here is an example ( 1 - 20 ):

• test_1 = Has 30 Kills
• test_2 = Has Found Map 1
• test_3 = Has Mastered Level 1
• test_4 = Has Achieved Grunt Status
• test_5 = Has Assault weapon
• test_6 = Has Knife
• test_x = Etc...

So when the Player has all these validations as TRUE I can then give a level result

• if test_1, test_2, test_3 ( any combination of the three ): level = green

All combinations are ( 15 ):

• test_1
• test_2
• test_3
• test_1, test_2
• test_1, test_3
• test_2, test_1 ( duplicate can skip this )
• test_2, test_3
• test_3, test_1 ( duplicate can skip this )
• test_3, test_2 ( duplicate can skip this )
• test_1, test_2, test_3
• test_1, test_3, test_2 ( duplicate can skip this )
• test_2, test_1, test_3 ( duplicate can skip this )
• test_2, test_3, test_1 ( duplicate can skip this )
• test_3, test_1, test_2 ( duplicate can skip this )
• test_3, test_2, test_1 ( duplicate can skip this )

So unique combinations are ( 7 instead of 15 ):

• test_1
• test_2
• test_3
• test_1, test_2
• test_1, test_3
• test_2, test_3
• test_1, test_2, test_3

Now I'm trying to find the best possible solution to find unique combinations for all 20 validations and come up with a level validation from that matrix.

UPDATE:

Also I need to find only TRUE Combinations so you might read the Unique Combinations like this:

• test_1
• test_2
• test_3
• test_1, test_2
• test_1, test_3
• test_2, test_3
• test_1, test_2, test_3

Boolean Value Results from Validation Tests

• TRUE, FALSE, FALSE
• FALSE, TRUE, FALSE
• FALSE, FALSE, TRUE
• TRUE, TRUE, FALSE
• TRUE, FALSE, TRUE
• FALSE, TRUE, TRUE
• TRUE, TRUE, TRUE

So any of these combinations would be a GREEN level.

Also I need to know the order of the test validations as well as the matrix order to compare for level assignment. So for GREEN level I only need the validation result combination matrix for test 1, 2 and 3. So I could ignore tests 4 - 20

UPDATE #2:

I know this looks like a simple OR condition but I wanted to take out the combination logic to set the level into a matrix. I could use the matrix of combinations to determine the level logic without having to code additional or modify current logic in the code itself. I wanted to just compare the validations results for a given set of tests and assign a level to those results. Different permutations of the validation combinations would result in different level assignments.

I understand that I could add the combination logic in the code itself, but as this logic looks to be very volatile and thought this might offer a more flexible solution. Suggestions?

2012/11/23 15:31
• php
• matrix
• 点赞
• 收藏
• 回答
私信