package model;

import java.util.HashSet;
import java.util.Set;

/**
 * The Move class, which stores the currently selected set of points on the
 * PlayerApplication's board.
 *
 * @author Bailey Sheridan, Nick Chaput, and Eli Skeggs
 */
public class Move {
  // TODO: structure to optimize for the eventual removal and replacement of
  // tiles (i.e. organize the points by row)
  public Set<Point> points = new HashSet<Point>();
  public int moveSum = 0;

  public Move() {}

  /**
   * Returns whether the move is a valid move.
   *
   * A move is valid if it contains at least two tiles that sum to 6.
   */
  public boolean isValid() {
    return points.size() > 1 && moveSum == 6;
  }

  /**
   * Expand the move to include another unique point.
   *
   * Precondition: board contains a tile at the given x, y point.
   */
  public void expand(Board board, Point point) {
	boolean isUnique = true;
	for (Point p : points) {
  	    if (point.x == p.x && point.y == p.y) {
  	    	isUnique = false;
  	    }
  	}
	if (isUnique) {
		if (points.add(point)) {
			moveSum += (board.grid[point.x][point.y].tile.number + 1);
    	}
	}
  }

  /**
   * Check whether the given point is adjacent to any of the points in the move.
   *
   * @param point The point to check for adjacency.
   * @return Whether the given point is adjacent to at least one point in the
   *   current move (does not check that the new point is not already contained
   *   in the move).
   */
  public boolean isAdjacent(Point point) {
	  boolean isAdjacent = false;
	  for (Point p : points) {
		  isAdjacent = ((Math.abs(point.x-p.x) == 1 && point.y-p.y == 0)
				  		|| (point.x-p.x == 0 && Math.abs(point.y-p.y) == 1));
	  }
	  return isAdjacent;
  }
}

@@ -875,166 +875,65 @@
 ) %7B%0A
-%09boolean isUnique = true;%0A%09for (Point p : points) %7B%0A  %09    if (point.x == p.x && point.y == p.y
+    if (points.size() == 0 %7C%7C isAdjacent(point)
 ) %7B%0A  
-%09
     
-%09isUnique = false;%0A  %09    %7D%0A  %09%7D%0A%09if (isUnique) %7B%0A%09%09
 if (
@@ -953,19 +953,24 @@
 int)) %7B%0A
-%09%09%09
+        
 moveSum 
@@ -1028,12 +1028,16 @@
     
-%09%7D%0A%09
+  %7D%0A    
 %7D%0A  
@@ -1415,40 +1415,10 @@
 ) %7B%0A
-%09
   
-boolean isAdjacent = false;%0A%09
   fo
@@ -1444,25 +1444,18 @@
 ) %7B%0A
-%09%09  isAdjacent = 
+      if (
 ((Ma
@@ -1468,17 +1468,19 @@
 (point.x
--
+ - 
 p.x) == 
@@ -1495,29 +1495,29 @@
 nt.y
--p.y == 0)%0A%09%09%09%09  %09%09%7C%7C
+ == p.y) %7C%7C%0A         
  (po
@@ -1525,17 +1525,15 @@
 nt.x
--p.x
  == 
-0
+p.x
  && 
@@ -1548,17 +1548,19 @@
 (point.y
--
+ - 
 p.y) == 
@@ -1566,35 +1566,64 @@
  1))
-;%0A%09  %7D%0A%09  return isAdjacent
+) %7B%0A        return true;%0A      %7D%0A    %7D%0A%0A    return false
 ;%0A  

Fix Move adjacency check and uniqueness