// Algo to find loop of particular colour Initialise visited[][] to false while there is an unvisited tile { // Record the starting tile set x0 := x; set y0 := y; set e := pick an edge of the desired colour; loopSize := 0; while (still on board && current tile still has edges this colour) { // if appropriate edge of this tile is of wrong colour; break; // if current tile has no lines of this colour break - not a loop; break; // if current tile is off the board, not a loop; break; // if current tile has already been visited, not a loop; break; // mark current tile as visited visited[x][y] = true; // find the next tile based on the edge details for this tile // set x:=x1, y:=y1 // loopSize++; // if we have reached the starting point (x==x0) & (y==y0) { // record the length of this loop // break from inner while } } } orientation of this tile is boardOrient[x][y] // two cases: in violation, not in violation