|
I am making a program that gennerates a code, as a string of number, then the user inputs a number of the same lenght and the program compares the two sets of numbers. The programme then generates a guitext for each number and colors it according to wether the number is the correct number and place in the code(green), the number is in the code but not at the given place (yellow), or the number is not pressent in the code (red). I want the code to only return as manny yellows of a number as times that the number is prsent in the code. I coded it in c# and I'm using three forloops, but for a reason i can not figur out the innermost forloop never returns true even though it should. any ideas, solutions are welcome. I'm posten the funtion where the comparring is happening. the var line is used for controlling the spacing of the guiTexts teh var n is the lenght of the code being checked.
(comments are locked)
|
|
Sorry I missed the point a bit there, hehe. This is hardly a full solution, but you might want to make another table as you go through and store uniques. When you get a duplicate, you pass over it. Only issue there is you're not giving them feedback from every number. I think the type of 1:1 feedback you're trying to give is at odds with the duplicates issue. If you give them feedback for each number, you'll have duplicate feedback. If you don't give feedback for duplications, they'll likely ascertain that the number (they'll end up spamming multiples of) exists in the set, actually making the code easier to crack in some regards. I was going to suggest another color to indicate "correct, but duplicates", but the user can just do 012344456 and if they see the other color they know 4 is there. Maybe that's the point, but it seems like a solution for this case might break the integrity of the challenge. That's all I've got and it's not much of an answer, but maybe it will give you some things to think about.
(comments are locked)
|
|
Hey Burton Thank you for your reply. I can see its a cleaner and more clear method, so I have rewriten my code based on your solution. But it dosn't sovle my problem with the returns of more yellows of a number than there is instances in the code. ex. if the random code contains two instances of the number 7 and the user inputs 7 three times, the returning 7's should be, 2 green and one red, 2 yellow and one red or one green one yellow and one red. But as it is, it return 3 yellow, 2 yellow and one green or 2 green and one yellow. anyone got an solution for this? code inserted below using System.Collections; using System.Collections.Generic; public class hacking : MonoBehaviour { //used to calculate line spaces float line = 0; //GUItext containing the user intput public GUIText codeIn; public float timer = 0; private GUIText[] outNumber = new GUIText[8]; private GUIText outText = new GUIText(); int n; //used to generate a random number for the code float a; int itemCount = 8; int minValue = 0; int maxValue = 10; int numTries = 0; bool hasSolution = false; Dictionary<int, int> masterItemIndex = new Dictionary<int, int>(); //If this flag is true, we'll store our correct answers bool storeCorrects = true; List correctItems = new List(); List guesses = new List(); }
(comments are locked)
|
|
I would suggest you re-approach the way you've got this programed. I've been looking at it for a few minutes and I'm reminded that usually I get myself to rethink how I've approached a problem if I've got 3 loops nested. The only time I'd allow myself to do this is for a pre-runtime (in-editor) function. I would suggest using either a custom datatype that would allow you to store a number value and all of the indexes where it occurs. Or a Dictionary where your number is the key and you have a string value that you could parse for indexes of all of the occurrences. I needed a break from what I was working on tonight, so I wrote a Dictionary based solution. I think you'll find it pretty easy to read, but let me know if you have any questions. :). I almost always use Lists too for my collections, as I believe they're faster than just an ArrayList.
(comments are locked)
|
