From 8b76ea88a71c7f0d734e769af7761d2d8aaa3f2f Mon Sep 17 00:00:00 2001 From: kurisu Date: Fri, 18 Jul 2025 17:31:07 +0900 Subject: [PATCH 1/3] =?UTF-8?q?paiza=E3=81=AEB137=E3=81=AE=E5=9B=9E?= =?UTF-8?q?=E7=AD=94=E3=81=A8=E3=83=86=E3=82=B9=E3=83=88=E3=82=B3=E3=83=BC?= =?UTF-8?q?=E3=83=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kurisu/src/B137.java | 130 +++++++++++++++++++++++++++++++++++++++ kurisu/src/B137Test.java | 98 +++++++++++++++++++++++++++++ 2 files changed, 228 insertions(+) create mode 100644 kurisu/src/B137.java create mode 100644 kurisu/src/B137Test.java diff --git a/kurisu/src/B137.java b/kurisu/src/B137.java new file mode 100644 index 0000000..e942992 --- /dev/null +++ b/kurisu/src/B137.java @@ -0,0 +1,130 @@ +import java.util.ArrayList; +import java.util.Scanner; + +public class B137 { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + final int vertical = sc.nextInt(); + final int horizontal = sc.nextInt(); + //paizaの問題を解く場合には必要になるが、実行時には影響なし + //final int colorType = sc.nextInt(); + ArrayList> areaSizes = new ArrayList>(); + for (int i = 0; i < vertical; i++) { + ArrayList blockData = new ArrayList(); + for (int j = 0; j < horizontal; j++) { + blockData.add(sc.next()); + } + areaSizes.add(blockData); + } + + sc.close(); + + ErasingBlock block = new ErasingBlock(vertical, horizontal, areaSizes); + block.eraseAdjacentBlocks(); + block.fallBlock(); + ArrayList> blockStates = block.getBlockStates(); + + BlockResult result = new BlockResult(); + System.out.println(result.output(blockStates)); + } +} + + +class ErasingBlock { + private ArrayList> blockSizes = new ArrayList>(); + private ArrayList> blockSwitches = new ArrayList>(); + private int vertical; + private int horizontal; + + ErasingBlock(int vertical, int horizontal, ArrayList> blockSizes) { + this.vertical = vertical; + this.horizontal = horizontal; + this.blockSizes = blockSizes; + setBlockSwitches(); + } + + // blockSwitchの初期化 + private void setBlockSwitches() { + for (int i = 0; i < vertical; i++) { + ArrayList blockSwitch = new ArrayList<>(); + for (int j = 0; j < horizontal; j++) { + blockSwitch.add(false); + } + blockSwitches.add(blockSwitch); + } + } + + public ArrayList> getBlockStates() { + return blockSizes; + } + + public ArrayList> getBlockSwitches() { + return blockSwitches; + } + + // 同じブロックの色がつながっているならそのブロック全てを#に置き換える + public void eraseAdjacentBlocks() { + for (int i = 0; i < vertical; i++) { + for (int j = 0; j < horizontal; j++) { + String adjacentBlock = blockSizes.get(i).get(j); + + if (j + 1 < horizontal) { + if (adjacentBlock.equals(blockSizes.get(i).get(j + 1))) { + blockSwitches.get(i).set(j, true); + blockSwitches.get(i).set(j + 1, true); + } + } + if (i + 1 < vertical) { + if (adjacentBlock.equals(blockSizes.get(i + 1).get(j))) { + blockSwitches.get(i).set(j, true); + blockSwitches.get(i + 1).set(j, true); + } + } + } + } + for (int i = 0; i < vertical; i++) { + for (int j = 0; j < horizontal; j++) { + if (blockSwitches.get(i).get(j)) { + blockSizes.get(i).set(j, "#"); + } + } + } + } + + // 残ったブロックを落下させて地面に置く + public void fallBlock() { + for (int j = 0; j < horizontal; j++) { + ArrayList columnBlock = new ArrayList<>(); + ArrayList columnEmpty = new ArrayList<>(); + for (int i = vertical - 1; i >= 0; i--) { + String block = blockSizes.get(i).get(j); + if (!block.equals("#")) { + columnBlock.add(block); + } else { + columnEmpty.add("#"); + } + } + columnBlock.addAll(columnEmpty); + + for (int i = 0; i < vertical; i++) { + blockSizes.get(i).set(j, columnBlock.get((vertical - 1) - i)); + } + } + } +} + + +class BlockResult { + public String output(ArrayList> blockStates) { + String allBlocksString = ""; + for (int i = 0; i < blockStates.size(); i++) { + ArrayList row = blockStates.get(i); + String rowString = String.join(" ", row); + allBlocksString += rowString; + if(i < blockStates.size() - 1) { + allBlocksString += System.lineSeparator(); + } + } + return allBlocksString; + } +} diff --git a/kurisu/src/B137Test.java b/kurisu/src/B137Test.java new file mode 100644 index 0000000..d5ddb7e --- /dev/null +++ b/kurisu/src/B137Test.java @@ -0,0 +1,98 @@ +import static org.junit.Assert.*; +import java.util.ArrayList; +import java.util.Arrays; +import org.junit.Test; + +public class B137Test { + final int vertical = 3; + final int horizontal = 3; + + + public ArrayList> template(){ + ArrayList> areaSizes = new ArrayList<>(); + areaSizes.add(new ArrayList(Arrays.asList("g","b","g"))); + areaSizes.add(new ArrayList(Arrays.asList("g","r","b"))); + areaSizes.add(new ArrayList(Arrays.asList("g","r","r"))); + + return areaSizes; + } + + @Test + public void testErasingBlock() { + ArrayList> areaSizes = template(); + + ErasingBlock block = new ErasingBlock(vertical, horizontal, areaSizes); + assertEquals(vertical, areaSizes.size()); + assertEquals(horizontal, areaSizes.get(0).size()); + assertEquals("g", areaSizes.get(0).get(0)); + assertEquals("b", areaSizes.get(0).get(1)); + assertEquals("g", areaSizes.get(0).get(2)); + assertEquals("g", areaSizes.get(1).get(0)); + assertEquals("r", areaSizes.get(1).get(1)); + assertEquals("b", areaSizes.get(1).get(2)); + assertEquals("g", areaSizes.get(2).get(0)); + assertEquals("r", areaSizes.get(2).get(1)); + assertEquals("r", areaSizes.get(2).get(2)); + + //blockSwitchesの初期化ができているか + ArrayList> blockSwitches = block.getBlockSwitches(); + assertEquals(vertical, blockSwitches.size()); + assertEquals(horizontal,blockSwitches.get(0).size()); + for(ArrayList row : blockSwitches) { + for(Boolean sut : row) { + assertEquals(false, sut); + } + } + } + + @Test + public void testEraseAdjacentBlocks() { + ArrayList> areaSizes = template(); + + ErasingBlock block = new ErasingBlock(vertical, horizontal, areaSizes); + block.eraseAdjacentBlocks(); + ArrayList> adjacentBlocks = block.getBlockStates(); + assertEquals("#", adjacentBlocks.get(0).get(0)); + assertEquals("b", adjacentBlocks.get(0).get(1)); + assertEquals("g", adjacentBlocks.get(0).get(2)); + assertEquals("#", adjacentBlocks.get(1).get(0)); + assertEquals("#", adjacentBlocks.get(1).get(1)); + assertEquals("b", adjacentBlocks.get(1).get(2)); + assertEquals("#", adjacentBlocks.get(2).get(0)); + assertEquals("#", adjacentBlocks.get(2).get(1)); + assertEquals("#", adjacentBlocks.get(2).get(2)); + } + + @Test + public void testFallBlocks() { + ArrayList> areaSizes = template(); + ErasingBlock block = new ErasingBlock(vertical, horizontal, areaSizes); + block.eraseAdjacentBlocks(); + block.fallBlock(); + ArrayList> adjacentBlocks = block.getBlockStates(); + assertEquals("#", adjacentBlocks.get(0).get(0)); + assertEquals("#", adjacentBlocks.get(0).get(1)); + assertEquals("#", adjacentBlocks.get(0).get(2)); + assertEquals("#", adjacentBlocks.get(1).get(0)); + assertEquals("#", adjacentBlocks.get(1).get(1)); + assertEquals("g", adjacentBlocks.get(1).get(2)); + assertEquals("#", adjacentBlocks.get(2).get(0)); + assertEquals("b", adjacentBlocks.get(2).get(1)); + assertEquals("b", adjacentBlocks.get(2).get(2)); + } + + @Test + public void testOutput(){ + ArrayList> areaSizes = template(); + ErasingBlock block = new ErasingBlock(vertical, horizontal, areaSizes); + block.eraseAdjacentBlocks(); + block.fallBlock(); + ArrayList> blockStates = block.getBlockStates(); + + BlockResult result = new BlockResult(); + String expected = "# # #" + System.lineSeparator() + + "# # g" + System.lineSeparator() + + "# b b"; + assertEquals(expected, result.output(blockStates)); + } +} -- GitLab From a59e571e167c7b6814e2a046e71cf022ce547627 Mon Sep 17 00:00:00 2001 From: kurisu Date: Tue, 22 Jul 2025 14:18:37 +0900 Subject: [PATCH 2/3] =?UTF-8?q?paizaB137=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kurisu/src/B137.java | 91 +++++++++++++++++++--------------------- kurisu/src/B137Test.java | 23 +++++----- 2 files changed, 56 insertions(+), 58 deletions(-) diff --git a/kurisu/src/B137.java b/kurisu/src/B137.java index e942992..7e2bf04 100644 --- a/kurisu/src/B137.java +++ b/kurisu/src/B137.java @@ -1,4 +1,5 @@ import java.util.ArrayList; +import java.util.List; import java.util.Scanner; public class B137 { @@ -6,12 +7,12 @@ public class B137 { Scanner sc = new Scanner(System.in); final int vertical = sc.nextInt(); final int horizontal = sc.nextInt(); - //paizaの問題を解く場合には必要になるが、実行時には影響なし - //final int colorType = sc.nextInt(); - ArrayList> areaSizes = new ArrayList>(); - for (int i = 0; i < vertical; i++) { - ArrayList blockData = new ArrayList(); - for (int j = 0; j < horizontal; j++) { + // paizaの問題を解く場合には必要になるが、実行時には影響なし + // final int colorType = sc.nextInt(); + List> areaSizes = new ArrayList<>(); + for (int row = 0; row < vertical; row++) { + List blockData = new ArrayList(); + for (int column = 0; column < horizontal; column++) { blockData.add(sc.next()); } areaSizes.add(blockData); @@ -22,7 +23,7 @@ public class B137 { ErasingBlock block = new ErasingBlock(vertical, horizontal, areaSizes); block.eraseAdjacentBlocks(); block.fallBlock(); - ArrayList> blockStates = block.getBlockStates(); + List> blockStates = block.getBlockStates(); BlockResult result = new BlockResult(); System.out.println(result.output(blockStates)); @@ -31,61 +32,57 @@ public class B137 { class ErasingBlock { - private ArrayList> blockSizes = new ArrayList>(); - private ArrayList> blockSwitches = new ArrayList>(); + private List> blockSizes = new ArrayList<>(); + private List> blockSwitches = new ArrayList<>(); private int vertical; private int horizontal; - ErasingBlock(int vertical, int horizontal, ArrayList> blockSizes) { + ErasingBlock(int vertical, int horizontal, List> blockSizes) { this.vertical = vertical; this.horizontal = horizontal; this.blockSizes = blockSizes; setBlockSwitches(); } - + // blockSwitchの初期化 private void setBlockSwitches() { - for (int i = 0; i < vertical; i++) { - ArrayList blockSwitch = new ArrayList<>(); - for (int j = 0; j < horizontal; j++) { + for (int row = 0; row < vertical; row++) { + List blockSwitch = new ArrayList<>(); + for (int column = 0; column < horizontal; column++) { blockSwitch.add(false); } blockSwitches.add(blockSwitch); } } - - public ArrayList> getBlockStates() { + + public List> getBlockStates() { return blockSizes; } - public ArrayList> getBlockSwitches() { + public List> getBlockSwitches() { return blockSwitches; } // 同じブロックの色がつながっているならそのブロック全てを#に置き換える public void eraseAdjacentBlocks() { - for (int i = 0; i < vertical; i++) { - for (int j = 0; j < horizontal; j++) { - String adjacentBlock = blockSizes.get(i).get(j); - - if (j + 1 < horizontal) { - if (adjacentBlock.equals(blockSizes.get(i).get(j + 1))) { - blockSwitches.get(i).set(j, true); - blockSwitches.get(i).set(j + 1, true); - } + for (int row = 0; row < vertical; row++) { + for (int column = 0; column < horizontal; column++) { + String adjacentBlock = blockSizes.get(row).get(column); + + if (column + 1 < horizontal && adjacentBlock.equals(blockSizes.get(row).get(column + 1))) { + blockSwitches.get(row).set(column, true); + blockSwitches.get(row).set(column + 1, true); } - if (i + 1 < vertical) { - if (adjacentBlock.equals(blockSizes.get(i + 1).get(j))) { - blockSwitches.get(i).set(j, true); - blockSwitches.get(i + 1).set(j, true); - } + if (row + 1 < vertical && adjacentBlock.equals(blockSizes.get(row + 1).get(column))) { + blockSwitches.get(row).set(column, true); + blockSwitches.get(row + 1).set(column, true); } } } - for (int i = 0; i < vertical; i++) { - for (int j = 0; j < horizontal; j++) { - if (blockSwitches.get(i).get(j)) { - blockSizes.get(i).set(j, "#"); + for (int row = 0; row < vertical; row++) { + for (int column = 0; column < horizontal; column++) { + if (blockSwitches.get(row).get(column)) { + blockSizes.get(row).set(column, "#"); } } } @@ -93,11 +90,11 @@ class ErasingBlock { // 残ったブロックを落下させて地面に置く public void fallBlock() { - for (int j = 0; j < horizontal; j++) { - ArrayList columnBlock = new ArrayList<>(); - ArrayList columnEmpty = new ArrayList<>(); - for (int i = vertical - 1; i >= 0; i--) { - String block = blockSizes.get(i).get(j); + for (int column = 0; column < horizontal; column++) { + List columnBlock = new ArrayList<>(); + List columnEmpty = new ArrayList<>(); + for (int row = vertical - 1; row >= 0; row--) { + String block = blockSizes.get(row).get(column); if (!block.equals("#")) { columnBlock.add(block); } else { @@ -106,8 +103,8 @@ class ErasingBlock { } columnBlock.addAll(columnEmpty); - for (int i = 0; i < vertical; i++) { - blockSizes.get(i).set(j, columnBlock.get((vertical - 1) - i)); + for (int row = 0; row < vertical; row++) { + blockSizes.get(row).set(column, columnBlock.get((vertical - 1) - row)); } } } @@ -115,13 +112,13 @@ class ErasingBlock { class BlockResult { - public String output(ArrayList> blockStates) { + public String output(List> blockStates) { String allBlocksString = ""; - for (int i = 0; i < blockStates.size(); i++) { - ArrayList row = blockStates.get(i); - String rowString = String.join(" ", row); + for (int row = 0; row < blockStates.size(); row++) { + List rowBlocks = blockStates.get(row); + String rowString = String.join(" ", rowBlocks); allBlocksString += rowString; - if(i < blockStates.size() - 1) { + if (row < blockStates.size() - 1) { allBlocksString += System.lineSeparator(); } } diff --git a/kurisu/src/B137Test.java b/kurisu/src/B137Test.java index d5ddb7e..6ac2ea2 100644 --- a/kurisu/src/B137Test.java +++ b/kurisu/src/B137Test.java @@ -1,6 +1,7 @@ import static org.junit.Assert.*; import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import org.junit.Test; public class B137Test { @@ -8,8 +9,8 @@ public class B137Test { final int horizontal = 3; - public ArrayList> template(){ - ArrayList> areaSizes = new ArrayList<>(); + public List> template(){ + List> areaSizes = new ArrayList<>(); areaSizes.add(new ArrayList(Arrays.asList("g","b","g"))); areaSizes.add(new ArrayList(Arrays.asList("g","r","b"))); areaSizes.add(new ArrayList(Arrays.asList("g","r","r"))); @@ -19,7 +20,7 @@ public class B137Test { @Test public void testErasingBlock() { - ArrayList> areaSizes = template(); + List> areaSizes = template(); ErasingBlock block = new ErasingBlock(vertical, horizontal, areaSizes); assertEquals(vertical, areaSizes.size()); @@ -35,10 +36,10 @@ public class B137Test { assertEquals("r", areaSizes.get(2).get(2)); //blockSwitchesの初期化ができているか - ArrayList> blockSwitches = block.getBlockSwitches(); + List> blockSwitches = block.getBlockSwitches(); assertEquals(vertical, blockSwitches.size()); assertEquals(horizontal,blockSwitches.get(0).size()); - for(ArrayList row : blockSwitches) { + for(List row : blockSwitches) { for(Boolean sut : row) { assertEquals(false, sut); } @@ -47,11 +48,11 @@ public class B137Test { @Test public void testEraseAdjacentBlocks() { - ArrayList> areaSizes = template(); + List> areaSizes = template(); ErasingBlock block = new ErasingBlock(vertical, horizontal, areaSizes); block.eraseAdjacentBlocks(); - ArrayList> adjacentBlocks = block.getBlockStates(); + List> adjacentBlocks = block.getBlockStates(); assertEquals("#", adjacentBlocks.get(0).get(0)); assertEquals("b", adjacentBlocks.get(0).get(1)); assertEquals("g", adjacentBlocks.get(0).get(2)); @@ -65,11 +66,11 @@ public class B137Test { @Test public void testFallBlocks() { - ArrayList> areaSizes = template(); + List> areaSizes = template(); ErasingBlock block = new ErasingBlock(vertical, horizontal, areaSizes); block.eraseAdjacentBlocks(); block.fallBlock(); - ArrayList> adjacentBlocks = block.getBlockStates(); + List> adjacentBlocks = block.getBlockStates(); assertEquals("#", adjacentBlocks.get(0).get(0)); assertEquals("#", adjacentBlocks.get(0).get(1)); assertEquals("#", adjacentBlocks.get(0).get(2)); @@ -83,11 +84,11 @@ public class B137Test { @Test public void testOutput(){ - ArrayList> areaSizes = template(); + List> areaSizes = template(); ErasingBlock block = new ErasingBlock(vertical, horizontal, areaSizes); block.eraseAdjacentBlocks(); block.fallBlock(); - ArrayList> blockStates = block.getBlockStates(); + List> blockStates = block.getBlockStates(); BlockResult result = new BlockResult(); String expected = "# # #" + System.lineSeparator() + -- GitLab From 63768ad376913ebcc7d410fc10172ecb9ed557ef Mon Sep 17 00:00:00 2001 From: kurisu Date: Tue, 22 Jul 2025 14:35:21 +0900 Subject: [PATCH 3/3] =?UTF-8?q?Revert=20"paizaB137=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 This reverts commit a59e571e167c7b6814e2a046e71cf022ce547627. --- kurisu/src/B137.java | 91 +++++++++++++++++++++------------------- kurisu/src/B137Test.java | 23 +++++----- 2 files changed, 58 insertions(+), 56 deletions(-) diff --git a/kurisu/src/B137.java b/kurisu/src/B137.java index 7e2bf04..e942992 100644 --- a/kurisu/src/B137.java +++ b/kurisu/src/B137.java @@ -1,5 +1,4 @@ import java.util.ArrayList; -import java.util.List; import java.util.Scanner; public class B137 { @@ -7,12 +6,12 @@ public class B137 { Scanner sc = new Scanner(System.in); final int vertical = sc.nextInt(); final int horizontal = sc.nextInt(); - // paizaの問題を解く場合には必要になるが、実行時には影響なし - // final int colorType = sc.nextInt(); - List> areaSizes = new ArrayList<>(); - for (int row = 0; row < vertical; row++) { - List blockData = new ArrayList(); - for (int column = 0; column < horizontal; column++) { + //paizaの問題を解く場合には必要になるが、実行時には影響なし + //final int colorType = sc.nextInt(); + ArrayList> areaSizes = new ArrayList>(); + for (int i = 0; i < vertical; i++) { + ArrayList blockData = new ArrayList(); + for (int j = 0; j < horizontal; j++) { blockData.add(sc.next()); } areaSizes.add(blockData); @@ -23,7 +22,7 @@ public class B137 { ErasingBlock block = new ErasingBlock(vertical, horizontal, areaSizes); block.eraseAdjacentBlocks(); block.fallBlock(); - List> blockStates = block.getBlockStates(); + ArrayList> blockStates = block.getBlockStates(); BlockResult result = new BlockResult(); System.out.println(result.output(blockStates)); @@ -32,57 +31,61 @@ public class B137 { class ErasingBlock { - private List> blockSizes = new ArrayList<>(); - private List> blockSwitches = new ArrayList<>(); + private ArrayList> blockSizes = new ArrayList>(); + private ArrayList> blockSwitches = new ArrayList>(); private int vertical; private int horizontal; - ErasingBlock(int vertical, int horizontal, List> blockSizes) { + ErasingBlock(int vertical, int horizontal, ArrayList> blockSizes) { this.vertical = vertical; this.horizontal = horizontal; this.blockSizes = blockSizes; setBlockSwitches(); } - + // blockSwitchの初期化 private void setBlockSwitches() { - for (int row = 0; row < vertical; row++) { - List blockSwitch = new ArrayList<>(); - for (int column = 0; column < horizontal; column++) { + for (int i = 0; i < vertical; i++) { + ArrayList blockSwitch = new ArrayList<>(); + for (int j = 0; j < horizontal; j++) { blockSwitch.add(false); } blockSwitches.add(blockSwitch); } } - - public List> getBlockStates() { + + public ArrayList> getBlockStates() { return blockSizes; } - public List> getBlockSwitches() { + public ArrayList> getBlockSwitches() { return blockSwitches; } // 同じブロックの色がつながっているならそのブロック全てを#に置き換える public void eraseAdjacentBlocks() { - for (int row = 0; row < vertical; row++) { - for (int column = 0; column < horizontal; column++) { - String adjacentBlock = blockSizes.get(row).get(column); - - if (column + 1 < horizontal && adjacentBlock.equals(blockSizes.get(row).get(column + 1))) { - blockSwitches.get(row).set(column, true); - blockSwitches.get(row).set(column + 1, true); + for (int i = 0; i < vertical; i++) { + for (int j = 0; j < horizontal; j++) { + String adjacentBlock = blockSizes.get(i).get(j); + + if (j + 1 < horizontal) { + if (adjacentBlock.equals(blockSizes.get(i).get(j + 1))) { + blockSwitches.get(i).set(j, true); + blockSwitches.get(i).set(j + 1, true); + } } - if (row + 1 < vertical && adjacentBlock.equals(blockSizes.get(row + 1).get(column))) { - blockSwitches.get(row).set(column, true); - blockSwitches.get(row + 1).set(column, true); + if (i + 1 < vertical) { + if (adjacentBlock.equals(blockSizes.get(i + 1).get(j))) { + blockSwitches.get(i).set(j, true); + blockSwitches.get(i + 1).set(j, true); + } } } } - for (int row = 0; row < vertical; row++) { - for (int column = 0; column < horizontal; column++) { - if (blockSwitches.get(row).get(column)) { - blockSizes.get(row).set(column, "#"); + for (int i = 0; i < vertical; i++) { + for (int j = 0; j < horizontal; j++) { + if (blockSwitches.get(i).get(j)) { + blockSizes.get(i).set(j, "#"); } } } @@ -90,11 +93,11 @@ class ErasingBlock { // 残ったブロックを落下させて地面に置く public void fallBlock() { - for (int column = 0; column < horizontal; column++) { - List columnBlock = new ArrayList<>(); - List columnEmpty = new ArrayList<>(); - for (int row = vertical - 1; row >= 0; row--) { - String block = blockSizes.get(row).get(column); + for (int j = 0; j < horizontal; j++) { + ArrayList columnBlock = new ArrayList<>(); + ArrayList columnEmpty = new ArrayList<>(); + for (int i = vertical - 1; i >= 0; i--) { + String block = blockSizes.get(i).get(j); if (!block.equals("#")) { columnBlock.add(block); } else { @@ -103,8 +106,8 @@ class ErasingBlock { } columnBlock.addAll(columnEmpty); - for (int row = 0; row < vertical; row++) { - blockSizes.get(row).set(column, columnBlock.get((vertical - 1) - row)); + for (int i = 0; i < vertical; i++) { + blockSizes.get(i).set(j, columnBlock.get((vertical - 1) - i)); } } } @@ -112,13 +115,13 @@ class ErasingBlock { class BlockResult { - public String output(List> blockStates) { + public String output(ArrayList> blockStates) { String allBlocksString = ""; - for (int row = 0; row < blockStates.size(); row++) { - List rowBlocks = blockStates.get(row); - String rowString = String.join(" ", rowBlocks); + for (int i = 0; i < blockStates.size(); i++) { + ArrayList row = blockStates.get(i); + String rowString = String.join(" ", row); allBlocksString += rowString; - if (row < blockStates.size() - 1) { + if(i < blockStates.size() - 1) { allBlocksString += System.lineSeparator(); } } diff --git a/kurisu/src/B137Test.java b/kurisu/src/B137Test.java index 6ac2ea2..d5ddb7e 100644 --- a/kurisu/src/B137Test.java +++ b/kurisu/src/B137Test.java @@ -1,7 +1,6 @@ import static org.junit.Assert.*; import java.util.ArrayList; import java.util.Arrays; -import java.util.List; import org.junit.Test; public class B137Test { @@ -9,8 +8,8 @@ public class B137Test { final int horizontal = 3; - public List> template(){ - List> areaSizes = new ArrayList<>(); + public ArrayList> template(){ + ArrayList> areaSizes = new ArrayList<>(); areaSizes.add(new ArrayList(Arrays.asList("g","b","g"))); areaSizes.add(new ArrayList(Arrays.asList("g","r","b"))); areaSizes.add(new ArrayList(Arrays.asList("g","r","r"))); @@ -20,7 +19,7 @@ public class B137Test { @Test public void testErasingBlock() { - List> areaSizes = template(); + ArrayList> areaSizes = template(); ErasingBlock block = new ErasingBlock(vertical, horizontal, areaSizes); assertEquals(vertical, areaSizes.size()); @@ -36,10 +35,10 @@ public class B137Test { assertEquals("r", areaSizes.get(2).get(2)); //blockSwitchesの初期化ができているか - List> blockSwitches = block.getBlockSwitches(); + ArrayList> blockSwitches = block.getBlockSwitches(); assertEquals(vertical, blockSwitches.size()); assertEquals(horizontal,blockSwitches.get(0).size()); - for(List row : blockSwitches) { + for(ArrayList row : blockSwitches) { for(Boolean sut : row) { assertEquals(false, sut); } @@ -48,11 +47,11 @@ public class B137Test { @Test public void testEraseAdjacentBlocks() { - List> areaSizes = template(); + ArrayList> areaSizes = template(); ErasingBlock block = new ErasingBlock(vertical, horizontal, areaSizes); block.eraseAdjacentBlocks(); - List> adjacentBlocks = block.getBlockStates(); + ArrayList> adjacentBlocks = block.getBlockStates(); assertEquals("#", adjacentBlocks.get(0).get(0)); assertEquals("b", adjacentBlocks.get(0).get(1)); assertEquals("g", adjacentBlocks.get(0).get(2)); @@ -66,11 +65,11 @@ public class B137Test { @Test public void testFallBlocks() { - List> areaSizes = template(); + ArrayList> areaSizes = template(); ErasingBlock block = new ErasingBlock(vertical, horizontal, areaSizes); block.eraseAdjacentBlocks(); block.fallBlock(); - List> adjacentBlocks = block.getBlockStates(); + ArrayList> adjacentBlocks = block.getBlockStates(); assertEquals("#", adjacentBlocks.get(0).get(0)); assertEquals("#", adjacentBlocks.get(0).get(1)); assertEquals("#", adjacentBlocks.get(0).get(2)); @@ -84,11 +83,11 @@ public class B137Test { @Test public void testOutput(){ - List> areaSizes = template(); + ArrayList> areaSizes = template(); ErasingBlock block = new ErasingBlock(vertical, horizontal, areaSizes); block.eraseAdjacentBlocks(); block.fallBlock(); - List> blockStates = block.getBlockStates(); + ArrayList> blockStates = block.getBlockStates(); BlockResult result = new BlockResult(); String expected = "# # #" + System.lineSeparator() + -- GitLab