汎用リストに格納されている座標のリストがあります。リストを反復処理して、座標が互いに隣接しているかどうかを確認できるようにしたいと考えています。もしそうなら、私はそれが同じグループからのものであるのか、そうでない場合であるのかを知っています. これを適切に行う方法を知っている人はいますか?
更新: これまでの私の更新されたコードは次のとおりです。新しい汎用リストで座標をグループ化し、それらが隣接していて同じタイプである場合はそれらを辞書に追加しています。
Dictionary にグループ内の座標が既に含まれているかどうかを知りたいと思います。したがって、同じプロセスを再度実行することはありません。ディクショナリ内のジェネリック リストの値にアクセスするにはどうすればよいですか?
private void groupMatchTile(List<int[]> matchTile){
int i = 0;
Dictionary<int, List<int[]>> groups = new Dictionary<int, List<int[]>>();
foreach(int[] coord in matchTile){
if(groups.ContainsValue(
// How do you check if the coords already belong in a group
)) return;
groups.Add(i, new List<int[]>());
groups[i].Add(coord);
foreach(int[] nextCoord in matchTile){
if (coord == nextCoord) return;
else {
if ( isAdjacent(coord[0], coord[1], nextCoord[0], nextCoord[1]) &&
level.grid[coord[0], coord[1]] == level.grid[nextCoord[0], nextCoord[1]]
){
groups[i].Add(nextCoord);
}
}
}
i++;
}
}