/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.wiieditor.other;
import com.wiieditor.neuralnetwork.NeuralData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author zohaibrauf
*/
public class Grid {
private static final int TRUE_VAL=1;
private static final int FALSE_VAL=0;
private boolean [][]grid;
private int width;
private int height;
public int getHeight() {
return height;
}
public int getWidth() {
return width;
}
public void clear(){
for ( int x=0;x<grid.length;x++ )
for ( int y=0;y<grid[0].length;y++ )
grid[x][y]=false;
}
public Grid(int width,int height){
this.width=width;
this.height=height;
grid=new boolean[height][width];
for(int i=0;i<height;++i){
for(int j=0;j<width;++j){
grid[i][j]=false;
}
}
}
public void enableBlock(int row,int column){
if(row<0 || row>= height || column<0 || column>=width){
Logger log=LoggerFactory.getLogger(Grid.class);
log.error("Invalid row or column");
return;
}
grid[row][column]=true;
}
public void disableBlock(int row,int column){
if(row<0 || row>= height || column<0 || column>=width){
Logger log=LoggerFactory.getLogger(Grid.class);
log.error("Invalid row or column");
return;
}
grid[row][column]=false;
}
public void setBlock(int row,int column,boolean value){
if(row<0 || row>= height || column<0 || column>=width){
Logger log=LoggerFactory.getLogger(Grid.class);
log.error("Invalid row or column");
return;
}
grid[row][column]=value;
}
public boolean getBlock(int row,int column){
if(row<0 || row>= height || column<0 || column>=width){
Logger log=LoggerFactory.getLogger(Grid.class);
log.error("Invalid row or column");
return false;
}
return grid[row][column];
}
public NeuralData getConvertedNeuralData(){
NeuralData nd=new NeuralData(width*height,0);
for(int i=0;i<height;i++){
for(int j=0;j<width;j++){
nd.setInputVectorAtIndex(i*j, ((grid[i][j])?TRUE_VAL:FALSE_VAL) );
}
}
return nd;
}
}