Python Code Using Marvel Comics – Part 3

In my continued learning for Python, I decided to try to level up my skills and go more advanced. Previously, I took an analog medium, comics or more specifically New Mutants 2019 Issue 07, and converted a fight sequence that simulated dice rolling by porting it into a digital format which you can see here. This time, I chose something more difficult, the Marvel role playing game from 1984 — Marvel Superheroes.

Myself and many others have fond memories of this game. It was a simple concept that used the elements of FASERIP to quantify the statistics of an individual and then used a combat system to have match ups of various characters. The true beauty was that you were able to create your own unique character using the same framework. What was interesting is that there were a plethora of options for character creation. You could be a Robot with powers of emotion or an Alien that had powers that could manipulate weather. The matrix of possibilities was large large. What was more, each type of hero or villain had a different ranking for their statistics which made the uniqueness even higher, but made modeling that tough.

Many times when I start a project, I start thinking about it and then breaking it into smaller and more manageable aspects. From there, I like to start working on the smaller and easier aspects to get some momentum going and begin to see the vision a little more clearly.

Based on that, I started the challenge by seeing what I could do with some IF ELSE statements. I started with Origin. It was fairly simple as there were only 5 possibilities – Altered Human (i.e Spiderman or Fantastic Four), Mutant (i.e X-Men), Hi Tech (i.e Iron Man), Robot (i.e Vision), or Alien (i.e Thor). This was easy to code and was neat to see my first win, but now came the first obstacle, FASERIP.

FASERIP is an acronym for fighting, agility, strength, endurance, reason, intuition, and psyche. Each Origin had a different column in which they rolled their stats on which made nesting the possibilities hard, but doable. In the end I was able to do it, but it took me 551 lines of code using IF, ELIF, ELSE statement with various lists.

I was pumped that I got it working, but there was still so much coding to do as I had not even gotten to powers yet. I knew I had to improve the code so I started looking at what options I had. Random.choices was neat, but it did not weight the FASERIP versus ORIGIN columns the way I wanted. I considered dictionaries and then stumbled across a post on stack overflow that gave me an idea — for loops with range and I would append a list the way I did in the New Mutants 2019 Issue 07 program.

It worked. I was able to take 551 lines of code and get it down to 165 lines! For me, that was amazing. There is still much to do, such as coding powers, but I wanted to post what I had gotten working so far as I continue on my Python journey.

The code can be found at my GitHub. You can also run the program for yourself via my Replit or embedded below.