Attaching package: 'data.table'
The following objects are masked from 'package:dplyr':
between, first, last
The following object is masked from 'package:purrr':
transpose
I had this one pretty quick, just a bit of logic to get the play column right. Of course, I then had to remember to change all the right V2 references which took me a minute to figure out when I missed the second mutate.
dt %>%mutate("play"=case_when( V2 =="X"& V1 =="A"~"Z", V2 =="X"& V1 =="B"~"X", V2 =="X"& V1 =="C"~"Y", V2 =="Y"& V1 =="A"~"X", V2 =="Y"& V1 =="B"~"Y", V2 =="Y"& V1 =="C"~"Z", V2 =="Z"& V1 =="A"~"Y", V2 =="Z"& V1 =="B"~"Z", V2 =="Z"& V1 =="C"~"X", )) %>%mutate("my_score"=case_when( play =="X"~1, play =="Y"~2, play =="Z"~3 )) %>%mutate("win_score"=case_when( (V1 =="A"& play =="X") | (V1 =="B"& play =="Y") | (V1 =="C"& play =="Z") ~3, V1 =="A"& play =="Y"~6, V1 =="A"& play =="Z"~0, V1 =="B"& play =="X"~0, V1 =="B"& play =="Z"~6, V1 =="C"& play =="X"~6, V1 =="C"& play =="Y"~0 )) %>%mutate("score"= my_score + win_score) %>%pull("score") %>%sum()