0 Replies - 3320 Views - Last Post: 14 May 2013 - 07:59 PM Rate Topic: -----

#1 vaio911  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 19
  • Joined: 29-October 11

checking the correct pieces

Posted 14 May 2013 - 07:59 PM

I am trying to implement a method that will check if there are 4 pieces in a row,col,or diagonal that are the same.
It's basically like Connect 4.

public boolean check(Piece a,int row,int col)
   {
   	Grid<Piece> pie=getGrid();
   	int[] ok = new int[]{0,45,90,135,180,225,270,315};
   	Location k = new Location(row,col);
   	for(int x = 0;x < 8;x++)
   	{
   		if(pie.isValid(k.getAdjacentLocation(ok[x]))&&pie.get(k.getAdjacentLocation(ok[x]))!=null&&pie.get(k.getAdjacentLocation(ok[x])).getName().equals(a.getName()))
   		{
   			k=k.getAdjacentLocation(ok[x]);
   			if(pie.isValid(k.getAdjacentLocation(ok[x]))&&pie.get(k.getAdjacentLocation(ok[x]))!=null&&pie.get(k.getAdjacentLocation(ok[x])).getName().equals(a.getName()))
   			{
   				k=k.getAdjacentLocation(ok[x]);
   				if(pie.isValid(k.getAdjacentLocation(ok[x]))&&pie.get(k.getAdjacentLocation(ok[x]))!=null&&pie.get(k.getAdjacentLocation(ok[x])).getName().equals(a.getName()))
   				{
   					return true;
   				}
   			}
   		}
   	}	return false;
   }


I have no idea what's the problem. The code is taking in a Piece object and the row and col that it is in.
I am checking all locations possible in 45 degree increments that are adjacent to it and then check if the the adj loc is equal to the current loc.

Thank guys.

Is This A Good Question/Topic? 0
  • +

Page 1 of 1