# A tibble: 3 × 3
p1 p2 outcome
<chr> <chr> <dbl>
1 rock rock 3
2 rock paper 6
3 scissors paper 0
I’ll use a few different joins to map the first column and the second column to "rock", "paper" and "scissors", and also to map player 2’s move to a score.
Rows: 2500 Columns: 2
── Column specification ────────────────────────────────────────────────────────
Delimiter: " "
chr (2): X1, X2
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
It’s just a few joins, then rowwise mapping of the rock_paper_scissors_outcome() function to get the score components. Adding the columns together and summarizing finishes it off.
strategy |># reusing the score map from part 1left_join(p1_map) |># now column 2 gets mapped to outcomeleft_join(outcome_map) |># given the scores and outcomes, get player 2 movesleft_join(strategy_map) |># score player 2 movesleft_join(score_map) |># score playsmutate(outcome_score =map2( p1, p2, rock_paper_scissors_outcome ) |>simplify(),total_score = score + outcome_score ) |># total scoresummarise(total_score =sum(total_score))
Joining, by = "X1"
Joining, by = "X2"
Joining, by = c("p1", "outcome")
Joining, by = "p2"
# A tibble: 1 × 1
total_score
<dbl>
1 14060
Just for fun
library(ggdark)library(khroma)library(showtext)
Loading required package: sysfonts
Loading required package: showtextdb
library(scales)
Attaching package: 'scales'
The following object is masked from 'package:purrr':
discard
The following object is masked from 'package:readr':
col_factor
font_add_google(name ="Mountains of Christmas", family ="christmas")showtext_auto()