lw22
07-19-2009, 05:33 PM
Mainly the question is how can I compare 2 arrays to determine if a value exists in one array and if it is in the same position.
I will give you a brief overview of what this about those. Basically I am trying to make a game similar to the boardgame Mastermind. In the game a code is created of a sequence of 5 colors (there are 8 possible colors in the game and no one color can be used twice in the code). The object is for a person to try and guess the exact sequence of the colors in the code. They have 12 guesses to find the exact sequence. When one of the correct colors is guessed a white peg is placed on the gameboard to indicate a correct color was chosed. When the color is in the exact position in the guess as in the code a black peg is used instead. This website has a working verion of the game already: http://www.irt.org/games/js/mind/
As of now I get the color index of the code and guess sequence and store them in an array. Like I said before I am having trouble comparing the arrays. The problem I have having is when the same color is guessed in the guess sequence. I have the choice of disabling the same color to be guessed but that may take away from some of the strategic opertunities in the game. There should be only 1 peg for each color (so if there are multiple guesses and the color is in the code sequence there should be only 1 peg, either black or white).
I was thinking of making another array of colors in the guess sequence that are found in the actual sequence. Then if a guess color is in the above array that color would be ignored. However this won't work. (Assume blue is in the forth position of the code. If blue is also in the thrid and forth guess sequence a white peg will be chosen since the vba code will only reconize the blue in the thrid position. The correct result would be a black peg.)
This all may be very confusing (especially if you do not know the game). I do not have the time to go into more detail now. I have to take my friend to the train station. If needed I can explain more later. Also the coding isn't the best. I didn't take the time to declare my variables yet. I know this is an unusal request for this type of forum but I figured it wouldn't be bad to bounce some ideas around.
I will give you a brief overview of what this about those. Basically I am trying to make a game similar to the boardgame Mastermind. In the game a code is created of a sequence of 5 colors (there are 8 possible colors in the game and no one color can be used twice in the code). The object is for a person to try and guess the exact sequence of the colors in the code. They have 12 guesses to find the exact sequence. When one of the correct colors is guessed a white peg is placed on the gameboard to indicate a correct color was chosed. When the color is in the exact position in the guess as in the code a black peg is used instead. This website has a working verion of the game already: http://www.irt.org/games/js/mind/
As of now I get the color index of the code and guess sequence and store them in an array. Like I said before I am having trouble comparing the arrays. The problem I have having is when the same color is guessed in the guess sequence. I have the choice of disabling the same color to be guessed but that may take away from some of the strategic opertunities in the game. There should be only 1 peg for each color (so if there are multiple guesses and the color is in the code sequence there should be only 1 peg, either black or white).
I was thinking of making another array of colors in the guess sequence that are found in the actual sequence. Then if a guess color is in the above array that color would be ignored. However this won't work. (Assume blue is in the forth position of the code. If blue is also in the thrid and forth guess sequence a white peg will be chosen since the vba code will only reconize the blue in the thrid position. The correct result would be a black peg.)
This all may be very confusing (especially if you do not know the game). I do not have the time to go into more detail now. I have to take my friend to the train station. If needed I can explain more later. Also the coding isn't the best. I didn't take the time to declare my variables yet. I know this is an unusal request for this type of forum but I figured it wouldn't be bad to bounce some ideas around.