Day 2 has us using look up tables and enum switches to play the elves at Rock Paper Scissors.
Boilerplate
My first step is to create an Enumeration for the Rock Paper Scissors:
And a Structure to hold the Round:
Part 1
The problem asks us to score Rounds, so I create a Blueprint function to do that:
Part 1 has us summing the round scores to calculate a match score:
The D02 Read Line node is another Blueprint function, which splits the string on space (‘ ‘), and finds the left & right sides of that split in a Map of String-to-Enum to create a Round:
I used a Map for this (in part because I incorrectly anticipated how Part 2 would play out), set up as a local variable in the calling code:
Part 2
In Part 2 we need to reinterpret the X Y Z as Win Loose Draw. I create another Enumeration:
And implement a Select Response function:
Which I can use in a modified copy of D02 Read Line:
Which is in turn used in a modified copy of the D02 Score Match:
Summary
I used Strings Mapped to Enumerations, and Enum Switches, and broke the problem into Reading a Line (string) into a Round (struct), and Scoring the Round.
I hope this has been interesting or useful. Let me know in the comments! 🙂