namespace AdventOfCode.Solutions._2022.Day02 { internal class GameRules { private static int Win = 6, Draw = 3, Lost = 0, Rock = 1, Paper = 2, Scissors = 3; private static string OpponentRock = "A", OpponentPaper = "B", OpponentScissors = "C", PlayRock = "X", PlayPaper = "Y", PlayScissors = "Z", PlayWin = "Z", PlayDraw = "Y", PlayLose = "X"; private static Dictionary PossibleScores { get; set; } internal static void BuildScoreDic() { if (PossibleScores == null) { PossibleScores = new Dictionary { // Rock combos { OpponentRock + " " + PlayPaper, Paper + Win }, // win { OpponentRock + " " + PlayRock, Rock + Draw }, // draw { OpponentRock + " " + PlayScissors, Scissors + Lost }, // lose // Paper { OpponentPaper + " " + PlayScissors, Scissors + Win }, // win { OpponentPaper + " " + PlayPaper, Paper + Draw }, // draw { OpponentPaper + " " + PlayRock, Rock + Lost }, // lose // Scissors { OpponentScissors + " " + PlayRock, Rock + Win }, // win { OpponentScissors + " " + PlayScissors, Scissors + Draw }, // draw { OpponentScissors + " " + PlayPaper, Paper + Lost } // lose }; } } internal static void BuildWinDrawLoseTable() { if (PossibleScores == null) { PossibleScores = new Dictionary { // Rock combos { OpponentRock + " " + PlayWin, Paper + Win }, // win { OpponentRock + " " + PlayDraw, Rock + Draw }, // draw { OpponentRock + " " + PlayLose, Scissors + Lost }, // lose // Paper { OpponentPaper + " " + PlayWin, Scissors + Win }, // win { OpponentPaper + " " + PlayDraw, Paper + Draw }, // draw { OpponentPaper + " " + PlayLose, Rock + Lost }, // lose // Scissors { OpponentScissors + " " + PlayWin, Rock + Win }, // win { OpponentScissors + " " + PlayDraw, Scissors + Draw }, // draw { OpponentScissors + " " + PlayLose, Paper + Lost } // lose }; } } internal static int GetScore(string play) => PossibleScores[play]; } }