User:Mehtratan/sandbox

/* * To change this template, choose Tools | Templates * and open the template in the editor. */

/** * * @author Student@Clab */ public class tictac { public static final int boardSize = 3; public static char[][] board =new char [boardSize][boardSize]; public static int count =0; public static void initBoard(char arr[][]) {     for (int i=0; i<boardSize; i++) for(int j=0; j<boardSize; j++) {                arr[i][j] = ' '; }     //updatePos; } public static void dispBoard (char[][] arr) {     //updatePos; System.out.println("Displaying board"); for (int i=0; i<boardSize; i++) {            for(int j=0; j<boardSize; j++) {                 System.out.print("  "+arr[i][j]+"  "); if(j<boardSize-1) {                     System.out.print("|"); }            }             System.out.println; if(i<boardSize-1) {                for(int k=0; k<boardSize; k++) System.out.print(" "); }             System.out.println; }

}

public static int empty1(int row, int col,char board1[][]) {   if (board1[row][col]!= ' ') return 1; else return 0; }

public static int boardFull {   for (int i=0; i<boardSize; i++) {       for (int j=0; j<boardSize; j++) {           if (board[i][j] == ' ') return 0; }   }    return 1; }

public static void dfs(int row,int col,char[][] board) {  // char[][] board1 =new char [boardSize][boardSize]; /* for(int p=0; p<boardSize; p++) for(int q=0; q<boardSize; q++) board1[p][q]=arr[p][q];*/ if(boardFull == 1) return; for(int m=0; m<boardSize; m++) {       for (int j=0; j<boardSize; j++) {           if (empty1(m,j,board)==1) board[m][j]='X'; dispBoard(board); System.out.println("count is = "+ (++count)); // dfs(i,j,board1); }   }

/*if (col==boardSize) return 0; if (row==boardSize) dfs(0,col+1); else {       board[row][col]=' '; dfs(row+1,col); }   return 0;*/

}

public static void main(String args[]) {     //initBoard(board); // dfs(0,0,board); //dispBoard(board); //placeQueen(0); char[][] b2 =new char [boardSize][boardSize]; for (int i=0; i<3; i++) for(int j=0; j<3; j++) if (i==j) b2[i][j]='H'; dispBoard(b2); int emp = empty1(0,0,b2); int emp2 = empty1(0,1,b2); System.out.println("(0,0) = "+emp); System.out.println("(0,1) = "+emp2);

} }