B
B
BonBon Slick2020-07-22 12:28:53
Mathematics
BonBon Slick, 2020-07-22 12:28:53

Counting possible sprite combinations in avatar/character editor?

Есть 72 спрайтов с разными особенностями.
Они разделены на группы
5 - руки
10 - шапки
20 - голов
5 - ноги
12 - футболка
10 - обувь
10 - шорты

Необходимо подсичатть конечный результат всех возможных комбинаций перед тем как их генерировать.

Условия:
Только 1 спрайты из группы может быть скомбинирован. То есть, голову можно выбрать 1, как и шапку, 2 шапки, головы или 2 пары ног быть не может.
Из чего следует что 1 голова может иметь все количество комбинаций - количество комбинаций из голов, то есть - 19 возможных вариантов. А в случае с руками будет - 4 т.к. 1 опцию мы вибарем текущую + 10 шапки + 20 голов и т..д.

Интересует формула подсчета с группировкой и как бы это выглядело программно, подойдет любой язык.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
ayazer, 2020-07-22
@BonBonSlick

sum = power of the direct product of all the possibilities you have. those. S = A x B x C x ...., where A = {hands1, hands2, hands3, hands4, hands5}, B = {hat1, hat2 ...}, ...
the formula is simple - just multiply the cardinalities of all sets what do you have. those. as they wrote in the comments - 5 * 10 * 20 ...
the groupings themselves = the direct work itself. Because in your case, you have sets known at the input, then you just need to run through them and collect all possible options. It will look somewhere like this - https://github.com/novak-as/gimp-tileset-generator...
UPD:
If you take out the minimum necessary part from there (and throw out the complications that are not needed in the context of this example), it comes out quite a bit

(define (push stack value)
  (append (list value) stack)
  )

(define (combine-list list1 list2)  
  (let combine-list ((set '()) (olist2 list2) (list1 list1) (list2 list2))
    (if (null? olist2)
        (if (null? list1)
            set
            (combine-list (push set (car list1)) olist2 (cdr list1) list2)
            )
        (if (null? list1)
            set
            (if (null? list2)
                (combine-list set olist2 (cdr list1) olist2)
                (if (list? (car list2))
                    (combine-list (push set (append (car list2) (list (car list1)))) olist2 list1 (cdr list2))
                    (combine-list (push set (list (car list2) (car list1))) olist2 list1 (cdr list2))
                    )
                )
            )
        )
    )
  )

(define (combine-groups groups)
  (let combine-groups ((result '()) (groups groups))
    (if (null? groups)
        result
        (combine-groups (combine-list (car groups) result) (cdr groups))
        )
    )
  )

with result
(combine-groups (list (list "head1" "head2" "head3") (list "body1" "body2" "body3") (list "left_hand_1" "left_hand_2") (list "right_hand_1" "right_hand_2")))

'(("head1" "body3" "left_hand_1" "right_hand_2")
  ("head2" "body3" "left_hand_1" "right_hand_2")
  ("head3" "body3" "left_hand_1" "right_hand_2")
  ("head1" "body2" "left_hand_1" "right_hand_2")
  ("head2" "body2" "left_hand_1" "right_hand_2")
  ("head3" "body2" "left_hand_1" "right_hand_2")
  ("head1" "body1" "left_hand_1" "right_hand_2")
  ("head2" "body1" "left_hand_1" "right_hand_2")
  ("head3" "body1" "left_hand_1" "right_hand_2")
  ("head1" "body3" "left_hand_2" "right_hand_2")
  ("head2" "body3" "left_hand_2" "right_hand_2")
  ("head3" "body3" "left_hand_2" "right_hand_2")
  ("head1" "body2" "left_hand_2" "right_hand_2")
  ("head2" "body2" "left_hand_2" "right_hand_2")
  ("head3" "body2" "left_hand_2" "right_hand_2")
  ("head1" "body1" "left_hand_2" "right_hand_2")
  ("head2" "body1" "left_hand_2" "right_hand_2")
  ("head3" "body1" "left_hand_2" "right_hand_2")
  ("head1" "body3" "left_hand_1" "right_hand_1")
  ("head2" "body3" "left_hand_1" "right_hand_1")
  ("head3" "body3" "left_hand_1" "right_hand_1")
  ("head1" "body2" "left_hand_1" "right_hand_1")
  ("head2" "body2" "left_hand_1" "right_hand_1")
  ("head3" "body2" "left_hand_1" "right_hand_1")
  ("head1" "body1" "left_hand_1" "right_hand_1")
  ("head2" "body1" "left_hand_1" "right_hand_1")
  ("head3" "body1" "left_hand_1" "right_hand_1")
  ("head1" "body3" "left_hand_2" "right_hand_1")
  ("head2" "body3" "left_hand_2" "right_hand_1")
  ("head3" "body3" "left_hand_2" "right_hand_1")
  ("head1" "body2" "left_hand_2" "right_hand_1")
  ("head2" "body2" "left_hand_2" "right_hand_1")
  ("head3" "body2" "left_hand_2" "right_hand_1")
  ("head1" "body1" "left_hand_2" "right_hand_1")
  ("head2" "body1" "left_hand_2" "right_hand_1")
  ("head3" "body1" "left_hand_2" "right_hand_1"))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question