Some Logical problem
I am writting a method that is suppose to get a vector of Coordinate objects Objects, afterwards its suppose to get the value the coordinates are pointing to on a two dimensional array and compare to see if they all have thesame value. if they are all thesame it returns true, else if anyone of them is different then it returns false.
Here is what I got to muster so far.
I was thinking of using comparing in twos, like we A B C D we compare A B and store boolean in b. compare B C, store in b by b = b && (B == C) so that it doesn't overwrite a false when we get one.
//checks Move elements and the value in their coordinates, if the values are same it reutnr true
//else it returns false
public boolean areSame(Vector<Move> nbrs)
Move p1, p2; //pointer one and pointer two
int v1, v2; //value being pointed at
boolean b = true; // b starts with true because we need it for and operations which would determine
if(nbrs.size() >= getConnect()) // if the no. of elements is less than number to connect
for(int i = 0; i < nbrs.size() -1 ; ++i)
p1 = nbrs.get(i); v1 = board[p1.getX()] [p1.getY()]; //get the Move and finds its value on the board
p2 = nbrs.get(i + 1); v2 = board[p2.getX()] [p2.getY()]; // get the one next to it and find its value on the board
b = b && (v1 == v2); // compare the next two values , This would
return false;//end of check length
Its not working? it usually returns true regardless... I still cant find the bug.
Use a debugger and step through the code so that you can actually see what's happening, rather than guessing at it. As an alternative, put in a plethora of print statements to print out every possible value that play a role each step of the way to do the same.
It works now, <smile> Thanks for the advise. I hope the bug does pop up again...