0 Members and 1 Guest are viewing this topic.
int[][][] myArray;//orint[][][] myArray2 = {{{0,0}, {0,0}}, {{0,0}, {0,0}}};//Creates a 2x2x2 array filled with 0
int[3][3] my2DArray;int[3][3][3] my3DArray;for(int[][] i : my3DArray[]){ compare(i, my2DArray);}
int[][][] winpattern2 = new int[][][] {{{0, 2, 2}, {2, 0, 2}, {2, 2, 0}}, {{2, 2, 0}, {2, 0, 2}, {0, 2, 2}}, {{0, 0, 0}, {2, 2, 2}, {2, 2, 2}}, {{2, 2, 2}, {0, 0, 0}, {2, 2, 2}}, {{2, 2, 2}, {2, 2, 2}, {0, 0, 0}}
int sr = 0; for(int[][] farray : winpattern2) { for(int bb = 0; bb <= 2; bb++) { for (int c = 0; c <= 2; c++) { if ((ss[c][bb] == 0) && (farray[c][bb] == 0)) { sr += 1; } } } }
for(int[][] farray : winpattern2)
int sr = 0; for(int i = 0; i < winpattern2.length; i++) { for(int bb = 0; bb <= 2; bb++) { for (int c = 0; c <= 2; c++) { if ((ss[c][bb] == 0) && (winpattern2[i][c][bb] == 0)) { sr += 1; } } } }
package cwk09;/** * * @author HOMER-16 */public class TicTac { private String[][] grid; public String[][] getGrid() { return grid; } public void setGrid(String[][] grid) { boolean valid = true; if(grid.length == 3){ for(String[] i : grid){ if(i.length != 3){ valid = false; } for(String n : i){ if(!(n == "X" || n == "O" || n == " ")){ valid = false; } } } if(valid){ for(int i = 0; i < grid.length; i++){ System.arraycopy(grid[i], 0, this.grid[i], 0, grid[i].length); } } } } public TicTac(){ grid = new String[3][3]; for(String[] i : grid){//i holds a pointer to a String array for(int n = 0; n < i.length; n++){ i[n] = " "; } } } public void set(int x, int y, String character){ if((x >=0 && x < 3 && y >=0 && y < 3) && (character == "X" || character == "O")){ if(grid[x][y] == " "){ grid[x][y] = character; } } } public String ticTacWin(){ for(int i = 0; i < grid.length; i++){ String val = grid[i][0]; if(grid[i][1] == val && grid[i][2] == val){ return val; } } for(int i = 0; i < grid.length; i++){ String val = grid[0][i]; if(grid[1][i] == val && grid[2][i] == val){ return val; } } if((grid[0][0] == grid[1][1] && grid[2][2] == grid[1][1]) || (grid[0][2] == grid[1][1] && grid[2][0] == grid[1][1])){ return grid[1][1]; } return " "; } public String toString(){ String gridString = ""; for(int i = 0; i < grid.length; i++){ for(int n = 0; n < grid[i].length; n++){ gridString += grid[i][n] + ((n < 2) ? "|" : "\n");//Conditional for formatting purposes only } gridString += ((i < 2) ? "-----\n" : "");//Conditional for formatting purposes only } return gridString; }}