Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private ArrayList<Move> withinGroup(Move inGroup, Player[][] localBoard) {
- //'whose' contains a 'Player' enumeration that represents whether the group is of white or black stones.
- Player whose = localBoard[inGroup.y][inGroup.x];
- int whoseInt;
- if (whose.equals(Player.BLACK)){
- whoseInt = 1;
- }else if(whose.equals(Player.WHITE)) {
- whoseInt = 2;
- }else return null;
- //'whoseInt' contains an integer value, either 1 or 2, that represents which color the group is, 1 for black, and 2 for white
- ArrayList<Move> toVisit = new ArrayList<Move>();
- //toVisit will contain all unvisited stones in the group
- ArrayList<Move> visited = new ArrayList<Move>();
- //visited will contain all visited stones in the group
- Move currentMove = inGroup;
- toVisit.add(inGroup);
- //this loop finds all stones within the group, and adds them to the arraylists.
- while(toVisit.size() > 0) {
- currentMove = toVisit.get(0);
- int[] adjTiles = adjacentTiles(currentMove, localBoard);
- Move moveToCheck = new Move(currentMove.x + 1,currentMove.y);
- if (adjTiles[0] == whoseInt && !toVisit.contains(moveToCheck) && !visited.contains(moveToCheck)){
- toVisit.add(moveToCheck);
- }
- moveToCheck = new Move(currentMove.x,currentMove.y - 1);
- if (adjTiles[1] == whoseInt && !toVisit.contains(moveToCheck) && !visited.contains(moveToCheck)){
- toVisit.add(moveToCheck);
- }
- moveToCheck = new Move(currentMove.x - 1,currentMove.y);
- if (adjTiles[2] == whoseInt && !toVisit.contains(moveToCheck) && !visited.contains(moveToCheck)){
- toVisit.add(moveToCheck);
- }
- moveToCheck = new Move(currentMove.x,currentMove.y + 1);
- if (adjTiles[3] == whoseInt && !toVisit.contains(moveToCheck) && !visited.contains(moveToCheck)){
- toVisit.add(moveToCheck);
- }
- visited.add(currentMove);
- toVisit.remove(toVisit.indexOf(currentMove));
- }
- return visited;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement