浏览代码

on tictactow

mpierse 6 年前
父节点
当前提交
2aeea33e53

+ 14
- 1
src/main/java/rocks/zipcode/io/quiz3/arrays/SquareArrayAnalyzer.java 查看文件

@@ -1,10 +1,23 @@
1 1
 package rocks.zipcode.io.quiz3.arrays;
2 2
 
3
+import java.util.ArrayList;
4
+import java.util.Arrays;
5
+
3 6
 /**
4 7
  * @author leon on 09/12/2018.
5 8
  */
6 9
 public class SquareArrayAnalyzer {
7 10
     public static Boolean compare(Integer[] input, Integer[] squaredValues) {
8
-        return null;
11
+
12
+        if(input.length != squaredValues.length) return false;
13
+
14
+        ArrayList<Integer> arrList = new ArrayList<>(Arrays.asList(input));
15
+        ArrayList<Integer> squarelist = new ArrayList<>(Arrays.asList(squaredValues));
16
+
17
+        for (Integer i: arrList) {
18
+            if (!squarelist.contains(i*i)) return false;
19
+        }
20
+
21
+        return true;
9 22
     }
10 23
 }

+ 21
- 4
src/main/java/rocks/zipcode/io/quiz3/arrays/TicTacToe.java 查看文件

@@ -5,23 +5,40 @@ package rocks.zipcode.io.quiz3.arrays;
5 5
  */
6 6
 public class TicTacToe {
7 7
 
8
+    private String[][] board;
9
+
8 10
     public TicTacToe(String[][] board) {
11
+        this.board=board;
9 12
     }
10 13
 
11 14
     public String[] getRow(Integer value) {
12
-        return null;
15
+        String[] result = new String[3];
16
+        result[0]= board[value][0];
17
+        result[1]= board[value][1];
18
+        result[2]= board[value][2];
19
+        return result;
13 20
     }
14 21
 
15 22
     public String[] getColumn(Integer value) {
16
-        return null;
23
+        String[] result = new String[3];
24
+        result[0]= board[0][value];
25
+        result[1]= board[1][value];
26
+        result[2]= board[2][value];
27
+        return result;
17 28
     }
18 29
 
19 30
     public Boolean isRowHomogenous(Integer rowIndex) {
20
-        return null;
31
+        String[] row = getRow(rowIndex);
32
+        if(row[0].equals(row[1]) && row[1].equals(row[2]))
33
+            return true;
34
+        return false;
21 35
     }
22 36
 
23 37
     public Boolean isColumnHomogeneous(Integer columnIndex) {
24
-        return null;
38
+        String[] column = getColumn(columnIndex);
39
+        if(column[0].equals(column[1]) && column[1].equals(column[2]))
40
+            return true;
41
+        return false;
25 42
     }
26 43
 
27 44
     public String getWinner() {