From 290614c9c5edd2e365dd95b14474669da18c7359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=8A=E8=97=A4=20=E8=81=96=E5=A4=9C?= Date: Thu, 25 Jul 2024 14:18:52 +0900 Subject: [PATCH 1/3] =?UTF-8?q?paiza=E3=81=AEB142=E3=81=AE=E5=9B=9E?= =?UTF-8?q?=E7=AD=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sitou/src/B142_Reversi.java | 332 ++++++++++++++++++++++++++++++++++++ 1 file changed, 332 insertions(+) create mode 100644 sitou/src/B142_Reversi.java diff --git a/sitou/src/B142_Reversi.java b/sitou/src/B142_Reversi.java new file mode 100644 index 0000000..aaa1f54 --- /dev/null +++ b/sitou/src/B142_Reversi.java @@ -0,0 +1,332 @@ +package src; + +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +public class B142_Reversi { + public static void main(String[] args) { + B142_Reversi b142 = new B142_Reversi(); + b142.execute(); + } + + void execute() { + final InputData inputData = input(); + final Result result = solveReversi(inputData); + output(result); + } + + private static class InputData { + final int boardSize; + final List boardOfOrigin; + + public InputData(final int boardSize, List boardOfOrigin) { + this.boardSize = boardSize; + this.boardOfOrigin = boardOfOrigin; + } + } + + private static InputData input() { + Scanner scan = new Scanner(System.in); + final int boardSize = scan.nextInt(); + List boardOfOrigin = new ArrayList(); + + for (int i = 0; i < boardSize; i++) { + boardOfOrigin.add(scan.next()); + } + + scan.close(); + return new InputData(boardSize, boardOfOrigin); + } + + static Result solveReversi(InputData inputData) { + Reversi reversi = new Reversi(inputData); + int result = reversi.countPutStonePlace(); + + return new Result(result); + } + + private void output(final Result result) { + System.out.println(result.getNumOfPutStonePlace()); + } + + private static class Result { + final int numOfPutStonePlace; + + public Result(final int numOfPutStonePlace) { + this.numOfPutStonePlace = numOfPutStonePlace; + } + + int getNumOfPutStonePlace() { + return numOfPutStonePlace; + } + } + + private static class Reversi { + final int boardSize; + final static List> boardList = new ArrayList>(); + + public Reversi(InputData inputData) { + boardSize = inputData.boardSize; + + // 盤を1マスずつに分割 + for (int i = 0; i < boardSize; i++) { + final List row = new ArrayList<>(); + final String s = inputData.boardOfOrigin.get(i); + for (int j = 0; j < boardSize; j++) { + row.add(s.substring(j, j + 1)); + } + + boardList.add(row); + } + } + + public int countPutStonePlace() { + int result = 0; + for (int height = 0; height < boardSize; height++) { + for (int width = 0; width < boardSize; width++) { + if (hasPutStone(height, width)) { + result++; + } + } + } + + return result; + } + + public boolean hasPutStone(final int height, final int width) { + if (boardList.get(height).get(width).equals(".")) { + if (hasTurnLeftUp(height, width)) { + return true; + } + if (hasTurnUp(height, width)) { + return true; + } + if (hasTurnRightUp(height, width)) { + return true; + } + if (hasTurnLeft(height, width)) { + return true; + } + if (hasTurnRight(height, width)) { + return true; + } + if (hasTurnLeftDown(height, width)) { + return true; + } + if (hasTurnDown(height, width)) { + return true; + } + if (hasTurnRightDown(height, width)) { + return true; + } + } + return false; + } + + public boolean hasTurnLeftUp(final int height, final int width) { + if (height > 1 && width > 1) { + // 左上隣の駒 + String next = boardList.get(height - 1).get(width - 1); + + if (next.equals("W")) { + // さらに左上隣の駒を確認 + for (int i = 2; i < boardSize; i++) { + if ((height - i < 0 + || width - i < 0) + || boardList.get(height - i).get(width - i).equals(".")) { + // 駒がないとき + return false; + + } else if (boardList.get(height - i).get(width - i).equals("B")) { + // 自分の駒のとき + return true; + + } + // 相手の駒のとき、さらに左上隣の駒を確認する + } + } + } + return false; + } + + public boolean hasTurnUp(final int height, final int width) { + if (height > 1) { + // 上隣の駒 + String next = boardList.get(height - 1).get(width); + + if (next.equals("W")) { + // さらに上隣の駒を確認 + for (int i = 2; i < boardSize; i++) { + + if (height - i < 0 + || boardList.get(height - i).get(width).equals(".")) { + // 駒がないとき + return false; + + } else if (boardList.get(height - i).get(width).equals("B")) { + // 自分の駒のとき + return true; + + } + // 相手の駒のとき、さらに上隣の駒を確認する + } + } + } + return false; + } + + public boolean hasTurnRightUp(final int height, final int width) { + if (height > 1 && width < boardSize - 2) { + // 右上隣の駒 + String next = boardList.get(height - 1).get(width + 1); + + if (next.equals("W")) { + // さらに右上隣の駒を確認 + for (int i = 2; i < boardSize; i++) { + if ((height - i < 0 + || width + i > boardSize - 1) + || boardList.get(height - i).get(width + i).equals(".")) { + // 駒がないとき + return false; + + } else if (boardList.get(height - i).get(width + i).equals("B")) { + // 自分の駒のとき + return true; + + } + // 相手の駒のとき、さらに右上隣の駒を確認する + } + } + } + return false; + } + + public boolean hasTurnLeft(final int height, final int width) { + if (width > 1) { + // 左隣の駒 + String next = boardList.get(height).get(width - 1); + + if (next.equals("W")) { + // さらに右上隣の駒を確認 + for (int i = 2; i < boardSize; i++) { + if (width - i < 0 + || boardList.get(height).get(width - i).equals(".")) { + // 駒がないとき + return false; + + } else if (boardList.get(height).get(width - i).equals("B")) { + // 自分の駒のとき + return true; + + } + // 相手の駒のとき、さらに右上隣の駒を確認する + } + } + } + return false; + } + + public boolean hasTurnRight(final int height, final int width) { + if (width < boardSize - 2) { + // 右隣の駒 + String next = boardList.get(height).get(width + 1); + + if (next.equals("W")) { + // さらに右隣の駒を確認 + for (int i = 2; i < boardSize; i++) { + if (width + i > boardSize - 1 + || boardList.get(height).get(width + i).equals(".")) { + // 駒がないとき + return false; + } else if (boardList.get(height).get(width + i).equals("B")) { + // 自分の駒のとき + return true; + } + // 相手の駒のとき、さらに右上隣の駒を確認する + } + } + } + return false; + } + + public boolean hasTurnLeftDown(final int height, final int width) { + if (height < boardSize - 2 && width > 1) { + // 左下隣の駒 + String next = boardList.get(height + 1).get(width - 1); + + if (next.equals("W")) { + // さらに左下隣の駒を確認 + for (int i = 2; i < boardSize; i++) { + if ((height + i > boardSize + || width - i < 0) + || boardList.get(height + i).get(width - i).equals(".")) { + // 駒がないとき + return false; + + } else if (boardList.get(height + i).get(width - i).equals("B")) { + // 自分の駒のとき + return true; + + } + // 相手の駒のとき、さらに左上隣の駒を確認する + } + } + } + return false; + } + + public boolean hasTurnDown(final int height, final int width) { + if (height < boardSize - 2) { + // 下隣の駒 + String next = boardList.get(height + 1).get(width); + + if (next.equals("W")) { + // さらに下隣の駒を確認 + for (int i = 2; i < boardSize; i++) { + + if (height + i > boardSize + || boardList.get(height + i).get(width).equals(".")) { + // 駒がないとき + return false; + + } else if (boardList.get(height + i).get(width).equals("B")) { + // 自分の駒のとき + return true; + + } + // 相手の駒のとき、さらに上隣の駒を確認する + } + } + } + return false; + } + + public boolean hasTurnRightDown(final int height, final int width) { + if (height < boardSize - 2 && width < boardSize - 2) { + // 右上隣の駒 + String next = boardList.get(height + 1).get(width + 1); + + if (next.equals("W")) { + // さらに右上隣の駒を確認 + for (int i = 2; i < boardSize; i++) { + if ((height + i > boardSize - 1 + || width + i > boardSize - 1) + || boardList.get(height + i).get(width + i).equals(".")) { + // 駒がないとき + return false; + + } else if (boardList.get(height + i).get(width + i).equals("B")) { + // 自分の駒のとき + return true; + + } + // 相手の駒のとき、さらに右上隣の駒を確認する + } + } + } + return false; + } + + } +} -- GitLab From ff9a69cde41c956640f7abeec0a36fa4b4871b05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=8A=E8=97=A4=20=E8=81=96=E5=A4=9C?= Date: Mon, 29 Jul 2024 16:45:58 +0900 Subject: [PATCH 2/3] =?UTF-8?q?paiza=E3=81=AEB142=E3=81=AE=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sitou/src/B142_Reversi.java | 228 ++++++++++++++++++++---------------- 1 file changed, 124 insertions(+), 104 deletions(-) diff --git a/sitou/src/B142_Reversi.java b/sitou/src/B142_Reversi.java index aaa1f54..2727d80 100644 --- a/sitou/src/B142_Reversi.java +++ b/sitou/src/B142_Reversi.java @@ -4,88 +4,106 @@ import java.util.ArrayList; import java.util.List; import java.util.Scanner; -public class B142_Reversi { - public static void main(String[] args) { +final public class B142_Reversi { + final public static void main(String[] args) { B142_Reversi b142 = new B142_Reversi(); b142.execute(); } - void execute() { + final void execute() { final InputData inputData = input(); final Result result = solveReversi(inputData); output(result); } - private static class InputData { - final int boardSize; - final List boardOfOrigin; + final private static class InputData { + final int sideLength; + final List boardStatus; - public InputData(final int boardSize, List boardOfOrigin) { - this.boardSize = boardSize; - this.boardOfOrigin = boardOfOrigin; + public InputData(final int sideLength, List boardStatus) { + this.sideLength = sideLength; + this.boardStatus = boardStatus; } } - private static InputData input() { + final private static InputData input() { Scanner scan = new Scanner(System.in); - final int boardSize = scan.nextInt(); - List boardOfOrigin = new ArrayList(); + final int sideLength = scan.nextInt(); + List boardStatus = new ArrayList(); - for (int i = 0; i < boardSize; i++) { - boardOfOrigin.add(scan.next()); + for (int i = 0; i < sideLength; i++) { + boardStatus.add(scan.next()); } scan.close(); - return new InputData(boardSize, boardOfOrigin); + return new InputData(sideLength, boardStatus); } + + - static Result solveReversi(InputData inputData) { + final static Result solveReversi(InputData inputData) { Reversi reversi = new Reversi(inputData); - int result = reversi.countPutStonePlace(); + final int result = reversi.countPutStonePlace(); return new Result(result); } - private void output(final Result result) { + final private void output(final Result result) { System.out.println(result.getNumOfPutStonePlace()); } - private static class Result { + final private static class Result { final int numOfPutStonePlace; public Result(final int numOfPutStonePlace) { this.numOfPutStonePlace = numOfPutStonePlace; } - int getNumOfPutStonePlace() { + final int getNumOfPutStonePlace() { return numOfPutStonePlace; } } - private static class Reversi { - final int boardSize; + final private static class Reversi { + public static enum stoneStatus{ + BLACK("B"), + WHITE("W"), + EMPTY("."); + + private final String stone; + + private stoneStatus(String stone) { + this.stone = stone; + } + + final public String getStone() { + return this.stone; + } + } + + final int sideLength; final static List> boardList = new ArrayList>(); public Reversi(InputData inputData) { - boardSize = inputData.boardSize; + sideLength = inputData.sideLength; // 盤を1マスずつに分割 - for (int i = 0; i < boardSize; i++) { + for (int i = 0; i < sideLength; i++) { final List row = new ArrayList<>(); - final String s = inputData.boardOfOrigin.get(i); - for (int j = 0; j < boardSize; j++) { - row.add(s.substring(j, j + 1)); + final String stone = inputData.boardStatus.get(i); + for (int j = 0; j < sideLength; j++) { + row.add(stone.substring(j, j + 1)); } boardList.add(row); } } - public int countPutStonePlace() { + final public int countPutStonePlace() { int result = 0; - for (int height = 0; height < boardSize; height++) { - for (int width = 0; width < boardSize; width++) { - if (hasPutStone(height, width)) { + for (int height = 0; height < sideLength; height++) { + for (int width = 0; width < sideLength; width++) { + if (canPutStone(height, width)) { result++; } } @@ -94,51 +112,53 @@ public class B142_Reversi { return result; } - public boolean hasPutStone(final int height, final int width) { - if (boardList.get(height).get(width).equals(".")) { - if (hasTurnLeftUp(height, width)) { + final public boolean canPutStone(final int height, final int width) { + if (stoneStatus.EMPTY.getStone().equals(boardList.get(height).get(width))) { + if (canTurnLeftUp(height, width)) { return true; } - if (hasTurnUp(height, width)) { + if (canTurnUp(height, width)) { return true; } - if (hasTurnRightUp(height, width)) { + if (canTurnRightUp(height, width)) { return true; } - if (hasTurnLeft(height, width)) { + if (canTurnLeft(height, width)) { return true; } - if (hasTurnRight(height, width)) { + if (canTurnRight(height, width)) { return true; } - if (hasTurnLeftDown(height, width)) { + if (canTurnLeftDown(height, width)) { return true; } - if (hasTurnDown(height, width)) { + if (canTurnDown(height, width)) { return true; } - if (hasTurnRightDown(height, width)) { + if (canTurnRightDown(height, width)) { return true; } } return false; } - public boolean hasTurnLeftUp(final int height, final int width) { + final String myStone = stoneStatus.BLACK.getStone(); + final String opponentStone = stoneStatus.WHITE.getStone(); + final public boolean canTurnLeftUp(final int height, final int width) { if (height > 1 && width > 1) { // 左上隣の駒 - String next = boardList.get(height - 1).get(width - 1); + final String next = boardList.get(height - 1).get(width - 1); - if (next.equals("W")) { + if (opponentStone.equals(next)) { // さらに左上隣の駒を確認 - for (int i = 2; i < boardSize; i++) { - if ((height - i < 0 - || width - i < 0) - || boardList.get(height - i).get(width - i).equals(".")) { + for (int i = 2; i < sideLength; i++) { + if (height - i < 0 + || width - i < 0 + || stoneStatus.EMPTY.getStone().equals(boardList.get(height - i).get(width - i))) { // 駒がないとき return false; - } else if (boardList.get(height - i).get(width - i).equals("B")) { + } else if (myStone.equals(boardList.get(height - i).get(width - i))) { // 自分の駒のとき return true; @@ -150,21 +170,21 @@ public class B142_Reversi { return false; } - public boolean hasTurnUp(final int height, final int width) { + final public boolean canTurnUp(final int height, final int width) { if (height > 1) { // 上隣の駒 - String next = boardList.get(height - 1).get(width); + final String next = boardList.get(height - 1).get(width); - if (next.equals("W")) { + if (opponentStone.equals(next)) { // さらに上隣の駒を確認 - for (int i = 2; i < boardSize; i++) { + for (int i = 2; i < sideLength; i++) { if (height - i < 0 - || boardList.get(height - i).get(width).equals(".")) { + || stoneStatus.EMPTY.getStone().equals(boardList.get(height - i).get(width))) { // 駒がないとき return false; - } else if (boardList.get(height - i).get(width).equals("B")) { + } else if (myStone.equals(boardList.get(height - i).get(width))) { // 自分の駒のとき return true; @@ -176,21 +196,21 @@ public class B142_Reversi { return false; } - public boolean hasTurnRightUp(final int height, final int width) { - if (height > 1 && width < boardSize - 2) { + final public boolean canTurnRightUp(final int height, final int width) { + if (height > 1 && width < sideLength - 2) { // 右上隣の駒 - String next = boardList.get(height - 1).get(width + 1); + final String next = boardList.get(height - 1).get(width + 1); - if (next.equals("W")) { + if (opponentStone.equals(next)) { // さらに右上隣の駒を確認 - for (int i = 2; i < boardSize; i++) { - if ((height - i < 0 - || width + i > boardSize - 1) - || boardList.get(height - i).get(width + i).equals(".")) { + for (int i = 2; i < sideLength; i++) { + if (height - i < 0 + || width + i > sideLength - 1 + || stoneStatus.EMPTY.getStone().equals(boardList.get(height - i).get(width + i))) { // 駒がないとき return false; - } else if (boardList.get(height - i).get(width + i).equals("B")) { + } else if (myStone.equals(boardList.get(height - i).get(width + i))) { // 自分の駒のとき return true; @@ -202,20 +222,20 @@ public class B142_Reversi { return false; } - public boolean hasTurnLeft(final int height, final int width) { + final public boolean canTurnLeft(final int height, final int width) { if (width > 1) { // 左隣の駒 - String next = boardList.get(height).get(width - 1); + final String next = boardList.get(height).get(width - 1); - if (next.equals("W")) { + if (opponentStone.equals(next)) { // さらに右上隣の駒を確認 - for (int i = 2; i < boardSize; i++) { + for (int i = 2; i < sideLength; i++) { if (width - i < 0 - || boardList.get(height).get(width - i).equals(".")) { + || stoneStatus.EMPTY.getStone().equals(boardList.get(height).get(width - i))) { // 駒がないとき return false; - } else if (boardList.get(height).get(width - i).equals("B")) { + } else if (myStone.equals(boardList.get(height).get(width - i))) { // 自分の駒のとき return true; @@ -227,19 +247,19 @@ public class B142_Reversi { return false; } - public boolean hasTurnRight(final int height, final int width) { - if (width < boardSize - 2) { + final public boolean canTurnRight(final int height, final int width) { + if (width < sideLength - 2) { // 右隣の駒 - String next = boardList.get(height).get(width + 1); + final String next = boardList.get(height).get(width + 1); - if (next.equals("W")) { + if (opponentStone.equals(next)) { // さらに右隣の駒を確認 - for (int i = 2; i < boardSize; i++) { - if (width + i > boardSize - 1 - || boardList.get(height).get(width + i).equals(".")) { + for (int i = 2; i < sideLength; i++) { + if (width + i > sideLength - 1 + || stoneStatus.EMPTY.getStone().equals(boardList.get(height).get(width + i))) { // 駒がないとき return false; - } else if (boardList.get(height).get(width + i).equals("B")) { + } else if (myStone.equals(boardList.get(height).get(width + i))) { // 自分の駒のとき return true; } @@ -250,21 +270,21 @@ public class B142_Reversi { return false; } - public boolean hasTurnLeftDown(final int height, final int width) { - if (height < boardSize - 2 && width > 1) { + final public boolean canTurnLeftDown(final int height, final int width) { + if (height < sideLength - 2 && width > 1) { // 左下隣の駒 - String next = boardList.get(height + 1).get(width - 1); + final String next = boardList.get(height + 1).get(width - 1); - if (next.equals("W")) { + if (opponentStone.equals(next)) { // さらに左下隣の駒を確認 - for (int i = 2; i < boardSize; i++) { - if ((height + i > boardSize - || width - i < 0) - || boardList.get(height + i).get(width - i).equals(".")) { + for (int i = 2; i < sideLength; i++) { + if (height + i > sideLength + || width - i < 0 + || stoneStatus.EMPTY.getStone().equals(boardList.get(height + i).get(width - i))) { // 駒がないとき return false; - } else if (boardList.get(height + i).get(width - i).equals("B")) { + } else if (myStone.equals(boardList.get(height + i).get(width - i))) { // 自分の駒のとき return true; @@ -276,21 +296,21 @@ public class B142_Reversi { return false; } - public boolean hasTurnDown(final int height, final int width) { - if (height < boardSize - 2) { + final public boolean canTurnDown(final int height, final int width) { + if (height < sideLength - 2) { // 下隣の駒 - String next = boardList.get(height + 1).get(width); + final String next = boardList.get(height + 1).get(width); - if (next.equals("W")) { + if (opponentStone.equals(next)) { // さらに下隣の駒を確認 - for (int i = 2; i < boardSize; i++) { + for (int i = 2; i < sideLength; i++) { - if (height + i > boardSize - || boardList.get(height + i).get(width).equals(".")) { + if (height + i > sideLength + || stoneStatus.EMPTY.getStone().equals(boardList.get(height + i).get(width))) { // 駒がないとき return false; - } else if (boardList.get(height + i).get(width).equals("B")) { + } else if (myStone.equals(boardList.get(height + i).get(width))) { // 自分の駒のとき return true; @@ -302,21 +322,21 @@ public class B142_Reversi { return false; } - public boolean hasTurnRightDown(final int height, final int width) { - if (height < boardSize - 2 && width < boardSize - 2) { + final public boolean canTurnRightDown(final int height, final int width) { + if (height < sideLength - 2 && width < sideLength - 2) { // 右上隣の駒 - String next = boardList.get(height + 1).get(width + 1); + final String next = boardList.get(height + 1).get(width + 1); - if (next.equals("W")) { + if (opponentStone.equals(next)) { // さらに右上隣の駒を確認 - for (int i = 2; i < boardSize; i++) { - if ((height + i > boardSize - 1 - || width + i > boardSize - 1) - || boardList.get(height + i).get(width + i).equals(".")) { + for (int i = 2; i < sideLength; i++) { + if (height + i > sideLength - 1 + || width + i > sideLength - 1 + || stoneStatus.EMPTY.getStone().equals(boardList.get(height + i).get(width + i))) { // 駒がないとき return false; - } else if (boardList.get(height + i).get(width + i).equals("B")) { + } else if (myStone.equals(boardList.get(height + i).get(width + i))) { // 自分の駒のとき return true; -- GitLab From dc7cd88a21bdefafbf09cac8179b03fe54c064c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=8A=E8=97=A4=20=E8=81=96=E5=A4=9C?= Date: Mon, 29 Jul 2024 17:30:50 +0900 Subject: [PATCH 3/3] =?UTF-8?q?paiza=E3=81=AEB142=E3=81=AE=E4=BF=AE?= =?UTF-8?q?=E6=AD=A32?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sitou/src/B142_Reversi.java | 40 ++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/sitou/src/B142_Reversi.java b/sitou/src/B142_Reversi.java index 2727d80..f1e5fcb 100644 --- a/sitou/src/B142_Reversi.java +++ b/sitou/src/B142_Reversi.java @@ -6,7 +6,7 @@ import java.util.Scanner; final public class B142_Reversi { final public static void main(String[] args) { - B142_Reversi b142 = new B142_Reversi(); + final B142_Reversi b142 = new B142_Reversi(); b142.execute(); } @@ -27,7 +27,7 @@ final public class B142_Reversi { } final private static InputData input() { - Scanner scan = new Scanner(System.in); + final Scanner scan = new Scanner(System.in); final int sideLength = scan.nextInt(); List boardStatus = new ArrayList(); @@ -142,14 +142,14 @@ final public class B142_Reversi { return false; } - final String myStone = stoneStatus.BLACK.getStone(); - final String opponentStone = stoneStatus.WHITE.getStone(); + final String MYSTONE = stoneStatus.BLACK.getStone(); + final String OPPONENT_STONE = stoneStatus.WHITE.getStone(); final public boolean canTurnLeftUp(final int height, final int width) { if (height > 1 && width > 1) { // 左上隣の駒 final String next = boardList.get(height - 1).get(width - 1); - if (opponentStone.equals(next)) { + if (OPPONENT_STONE.equals(next)) { // さらに左上隣の駒を確認 for (int i = 2; i < sideLength; i++) { if (height - i < 0 @@ -158,7 +158,7 @@ final public class B142_Reversi { // 駒がないとき return false; - } else if (myStone.equals(boardList.get(height - i).get(width - i))) { + } else if (MYSTONE.equals(boardList.get(height - i).get(width - i))) { // 自分の駒のとき return true; @@ -175,7 +175,7 @@ final public class B142_Reversi { // 上隣の駒 final String next = boardList.get(height - 1).get(width); - if (opponentStone.equals(next)) { + if (OPPONENT_STONE.equals(next)) { // さらに上隣の駒を確認 for (int i = 2; i < sideLength; i++) { @@ -184,7 +184,7 @@ final public class B142_Reversi { // 駒がないとき return false; - } else if (myStone.equals(boardList.get(height - i).get(width))) { + } else if (MYSTONE.equals(boardList.get(height - i).get(width))) { // 自分の駒のとき return true; @@ -201,7 +201,7 @@ final public class B142_Reversi { // 右上隣の駒 final String next = boardList.get(height - 1).get(width + 1); - if (opponentStone.equals(next)) { + if (OPPONENT_STONE.equals(next)) { // さらに右上隣の駒を確認 for (int i = 2; i < sideLength; i++) { if (height - i < 0 @@ -210,7 +210,7 @@ final public class B142_Reversi { // 駒がないとき return false; - } else if (myStone.equals(boardList.get(height - i).get(width + i))) { + } else if (MYSTONE.equals(boardList.get(height - i).get(width + i))) { // 自分の駒のとき return true; @@ -227,7 +227,7 @@ final public class B142_Reversi { // 左隣の駒 final String next = boardList.get(height).get(width - 1); - if (opponentStone.equals(next)) { + if (OPPONENT_STONE.equals(next)) { // さらに右上隣の駒を確認 for (int i = 2; i < sideLength; i++) { if (width - i < 0 @@ -235,7 +235,7 @@ final public class B142_Reversi { // 駒がないとき return false; - } else if (myStone.equals(boardList.get(height).get(width - i))) { + } else if (MYSTONE.equals(boardList.get(height).get(width - i))) { // 自分の駒のとき return true; @@ -252,14 +252,14 @@ final public class B142_Reversi { // 右隣の駒 final String next = boardList.get(height).get(width + 1); - if (opponentStone.equals(next)) { + if (OPPONENT_STONE.equals(next)) { // さらに右隣の駒を確認 for (int i = 2; i < sideLength; i++) { if (width + i > sideLength - 1 || stoneStatus.EMPTY.getStone().equals(boardList.get(height).get(width + i))) { // 駒がないとき return false; - } else if (myStone.equals(boardList.get(height).get(width + i))) { + } else if (MYSTONE.equals(boardList.get(height).get(width + i))) { // 自分の駒のとき return true; } @@ -275,7 +275,7 @@ final public class B142_Reversi { // 左下隣の駒 final String next = boardList.get(height + 1).get(width - 1); - if (opponentStone.equals(next)) { + if (OPPONENT_STONE.equals(next)) { // さらに左下隣の駒を確認 for (int i = 2; i < sideLength; i++) { if (height + i > sideLength @@ -284,7 +284,7 @@ final public class B142_Reversi { // 駒がないとき return false; - } else if (myStone.equals(boardList.get(height + i).get(width - i))) { + } else if (MYSTONE.equals(boardList.get(height + i).get(width - i))) { // 自分の駒のとき return true; @@ -301,7 +301,7 @@ final public class B142_Reversi { // 下隣の駒 final String next = boardList.get(height + 1).get(width); - if (opponentStone.equals(next)) { + if (OPPONENT_STONE.equals(next)) { // さらに下隣の駒を確認 for (int i = 2; i < sideLength; i++) { @@ -310,7 +310,7 @@ final public class B142_Reversi { // 駒がないとき return false; - } else if (myStone.equals(boardList.get(height + i).get(width))) { + } else if (MYSTONE.equals(boardList.get(height + i).get(width))) { // 自分の駒のとき return true; @@ -327,7 +327,7 @@ final public class B142_Reversi { // 右上隣の駒 final String next = boardList.get(height + 1).get(width + 1); - if (opponentStone.equals(next)) { + if (OPPONENT_STONE.equals(next)) { // さらに右上隣の駒を確認 for (int i = 2; i < sideLength; i++) { if (height + i > sideLength - 1 @@ -336,7 +336,7 @@ final public class B142_Reversi { // 駒がないとき return false; - } else if (myStone.equals(boardList.get(height + i).get(width + i))) { + } else if (MYSTONE.equals(boardList.get(height + i).get(width + i))) { // 自分の駒のとき return true; -- GitLab