The "Freeola Customer Forum" forum, which includes Retro Game Reviews, has been archived and is now read-only. You cannot post here or create a new thread or review on this forum.
Not so much the code, but the algorithm.
You have to guess 4 colours in the correct order (choose between 8 colours) to win the game.
After every guess it needs to display pico and fermi points.
Pico - correct colour, correct position
Fermi - correct colour, wrong position
Pico points are dead easy, however I'm really smashing monitors over the Fermi points.
Any ideas?
I tried the vector arrays, failed and then gave up.
If statements all the way =P
Thanks again.
> Use vectors, not arrays. It will make it much easier to separate the
> pico points first.
This is very good advice. Vectors are pretty much always preferable to arrays.
Think about the problem in structured English. This is what you want to do:
For each element in the players guess:
.....if that element is the same as the corresponding element
.....of the solution, remove that element from the guess and add
.....a picopoint
For each element in the players guess:
.....if that element is present in the solution, add a fermipoint
And now to apply the above comments to Venombyte's code:
int pico = 0;
int fermi = 0;
//FOR EACH ELEMENT IN THE PLAYERS GUESS
for (int i=0; i
.....//if that element is the same as the corresponding
.....//element of the solution...
.....if ( guessVector.elementAt(i).equals(answerVector.elementAt(i)) )
.....{
..........//remove that element from the guess
..........//and add a picopoint
..........guessVector.remove(i);
..........answerVector.remove(i)
..........pico++;
..........i--;
.....}
}
boolean found = false;
//FOR EACH ELEMENT IN THE PLAYERS GUESS
for (int i=0; i
.....//if that element is present in the solution, add a fermipoint
.....for (int j=0; j
..........if (guessVector.elementAt(i).equals(answerVector.elementAt(j)) )
..........{
...............fermi++;
...............found = true;
..........}
.....}
}
Hope this (a) formats correctly and (b) makes sense.
You've started, so you'll finish.
First check for all your Pico points. Every time you get one, remove the entry from both your guess and answer array.
Then loop through the arrays checking for matches in the 'wrong place', and stopping the inner loop every time you get a match (in case of multiple entries for the same colour).
int pico = 0;
int fermi = 0;
for (int i=0; i
if ( guessVector.elementAt(i).equals(answerVector.elementAt(i)) )
{
guessVector.remove(i);
answerVector.remove(i)
pico++;
i--; //better decrement since you've removed an element
}
}
//all pico points will now have been removed, so if you find a match when
//looping, it must be a fermi point
for (int i=0; i
boolean found = false;
for (int j=0; j
if (guessVector.elementAt(i).equals(answerVector.elementAt(j)) )
{
fermi++;
found = true;
//setting found to true makes sure you only get max of ONE fermi
// point when running the inner loop for a given guess value
}
}
}
NOTE: You will also need to cast the vector content according to your chosen data type
Use the outer loop to cycle through the colours. Having said that, duplicates where a colour appears twice, one in the correct position, one not, would be an issue. Ah well, you can think up some additional checks for it.
String[] answerarray = {colour1 +colour2 +colour3 +colour4};
String[] guessarray = {select1 +select2 +select3 +select4};
Now the next part I don't understand at all. I've done for loops to go through arrays before, however I really hate arrays and everything I learn about them goes in one ear and out the other.
Sorry, how would I do this?
Simplest way is to have 2 arrays, one that contains the 4 colours selected at random, the other containing the 4 colours the user selected. Create a function that takes a colour as a parameter and loops through the array containing the randomly selected colours. At each position in the array it checks if the current colour matches the one passed to the function. If it does then the function returns the position of the colour. If it gets the end of the array without finding the colour then it returns -1.
The main part is to then have a loop that goes through your array of user selected colours. And at each position in the array you call your function, passing the current colour. Your function returns either -1 (the colour isn't in there) or the position of the colour. If the return value is -1, then the colour isn't in there at all so increase neither score, If the position returned is equal to the current position in the array then you're increasing the Pico score. If not (and its not -1) then you're increasing the Fermi score.
Hm, is that clear? Reading t back, doesn't seem like a good explanation. Explaining stuff was never my forte..
fermicount = 0;
if (select1 == colour1) {picocount++;}
if (select2 == colour2) {picocount++;}
if (select3 == colour3) {picocount++;}
if (select4 == colour4) {picocount++;}
select = user chosen colour
colour = computer generated colour (answer)
> Pico points are dead easy, however I'm really smashing monitors over
> the Fermi points.
Maybe you could show us how you're doing Pico points? Theres plenty enough solutions but it would be easier to help if we knew how you've represented your data and how you do your pico points calculation.