dongwu5801 2012-11-23 15:31
浏览 29
已采纳

矩阵组合逻辑

NOTE: **Please read all other related questions:**

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_7 = Has Grenade
  • 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?

  • 写回答

4条回答 默认 最新

  • doufei8691 2012-11-23 15:51
    关注

    (removed my two previous answers for clarity)

    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.

    e.g. with an associative array:

    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.

    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
        ),
      ...
      );
    

    Is that what you want?

    BTW, why don't you use a classic XP/level up system? :-p

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样