问题描述
注意:**请阅读所有其他相关问题:**
这是我第一次和第二次尝试问这个问题:
Here is my first and second attempts at asking this question:
- Efficient way to determine the outcome of test matrix
- Would cartesian product be the best approach for this
问题出在这里
- 我有几个(如20个)布尔验证(true/false)
- 所有布尔验证总体上也具有验证结果
我正在尝试找到最佳的解决方案来测试所有验证以及验证结果.我当时正在研究可以容纳所有可能组合的矩阵,但这可能是一个过大的杀伤力.
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.
以下是示例(1-20):
Here is an example ( 1 - 20 ):
- test_1 =杀死30人
- test_2 =已找到地图1
- test_3 =掌握1级知识
- test_4 =已达到咕unt声状态
- test_5 =拥有攻击武器
- test_6 =有刀子
- test_7 =有手榴弹
- test_x =等...
所以当播放器将所有这些验证都设置为TRUE时,我就可以给出一个关卡结果
So when the Player has all these validations as TRUE I can then give a level result
- 如果test_1,test_2,test_3(这三个的任意组合):级别=绿色
所有组合均为(15):
All combinations are ( 15 ):
- test_1
- test_2
- test_3
- test_1,test_2
- test_1,test_3
- test_2,test_1(重复的可以跳过此步骤)
- test_2,test_3
- test_3,test_1(重复项可以跳过)
- test_3,test_2(重复项可以跳过)
- test_1,test_2,test_3
- test_1,test_3,test_2(重复的可以跳过)
- test_2,test_1,test_3(重复项可以跳过)
- test_2,test_3,test_1(重复项可以跳过)
- test_3,test_1,test_2(重复的可以跳过)
- test_3,test_2,test_1(重复项可以跳过)
- 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 )
所以唯一的组合是(7而不是15):
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
现在,我正在尝试寻找最佳解决方案,以找到所有20个验证的唯一组合,并从该矩阵中提出一个级别验证.
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.
更新:
此外,我只需要找到TRUE组合,这样您就可以阅读如下所示的Unique组合:
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
验证测试的布尔值结果
- 真,假,假
- FALSE,TRUE,FALSE
- FALSE,FALSE,TRUE
- 正确,正确,错误
- TRUE,FALSE,TRUE
- FALSE,TRUE,TRUE
- TRUE,TRUE,TRUE
因此,这些组合中的任何一个都将是绿色等级.
So any of these combinations would be a GREEN level.
我还需要知道测试验证的顺序以及要进行级别分配进行比较的矩阵顺序.因此对于绿色级别,我仅需要测试1、2和3的验证结果组合矩阵.因此,我可以忽略测试4-20
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
更新#2:
我知道这看起来像一个简单的OR条件,但是我想取出组合逻辑以将级别设置为矩阵.我可以使用组合矩阵来确定级别逻辑,而不必在代码本身中编写其他代码或修改当前逻辑.我只想比较一组给定测试的验证结果,并为这些结果指定一个级别.验证组合的不同排列会导致不同的级别分配.
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?
推荐答案
(为清晰起见,删除了我之前的两个答案)
(removed my two previous answers for clarity)
上次编辑后,我想首先确保确保100%理解了您想要的"级别检测算法".
After your last edit, instead of answering directly, I would like first to be sure to 100% understand the "level detection algorithm" you want.
如果我很好理解,您想定义/维护一个简单的配置结构,告诉哪些测试给出哪个级别.
If I understand well, you would like to define/maintain a simple configuration structure telling which tests give which level.
例如具有关联数组:
array(
'green' => array('test1', 'test2', 'test3'),
'orange' => array('test2', 'test3', 'test5')
...
);
含义:如果满足列表中的一项或多项测试,则将该级别(数组键)分配给播放器.这样的逻辑可以轻松涵盖很多组合,并且可以避免处理庞大的矩阵.
With the meaning: if one or more of the tests in the list are satisfied, assign that level (array key) to the player. Such logic could easily cover quite a lot of combinations, and would avoid handling a huge matrix.
例如,您可能想扩展逻辑以告知测试列表中至少满足N个测试.
Maybe you want to extend the logic to tell, for example, that at least N tests among the test list are satisfied.
array(
'green' => array(
'tests' => array('test1', 'test2', 'test3'),
'nb_required' => 2
),
...
);
这就是你想要的吗?
顺便说一句,为什么不使用经典的XP/升级系统? :-p
BTW, why don't you use a classic XP/level up system? :-p
这篇关于矩阵组合逻辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!