public void switchDisplays(MastermindResult result) { int currentCount = 0; for (int i = 0; i < result.red; i++) { DisplayButton displayButtonA = displayButtons[i]; displayButtonA.GetComponent <DisplayButton>().displayRed(); currentCount++; } for (int j = 0; j < result.white; j++) { DisplayButton displayButtonB = displayButtons[result.red + j]; displayButtonB.GetComponent <DisplayButton>().displayWhite(); currentCount++; } }
public MastermindResult Test(MastermindColor[] guess) { triesRemaining--; MastermindResult result = new MastermindResult() { red = 0, white = 0 }; Dictionary <MastermindColor, int> nohits = new Dictionary <MastermindColor, int>(); // count reds for (int i = 0; i < goal.Length; i++) { if (goal[i] == guess[i]) { result.red++; } else { if (!nohits.ContainsKey(goal[i])) { nohits[goal[i]] = 0; } nohits[goal[i]]++; } } // count whites for (int i = 0; i < guess.Length; i++) { if (nohits.ContainsKey(guess[i]) && nohits[guess[i]] > 0) { result.white++; nohits[guess[i]]--; } } if (result.red == goal.Length) { success = true; } return(result); }
// user submits row public void Submit() { // lock buttons Lock(); submitButton.gameObject.SetActive(false); // get row colors MastermindColor[] guess = buttons.Select(button => button.mastermindColor).ToArray(); // submit MastermindResult result = mastermind.Test(guess); // TODO: do something at end of game if (!mastermind.Success() && !mastermind.Failure()) { displayResults.GetComponent <DisplayResults>().switchDisplays(result); //Debug.Log($"Red: {result.red}, White: {result.white}"); // create next row mastermind.AddRow(); } else { displayResults.GetComponent <DisplayResults>().switchDisplays(result); } }