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

import tileworld.Parameters;

/**
 *
 * @author Jakub
 */
public class TWSector implements Comparable{
    int x,y;
    int tiles,holes,obstacles,unex;
    int visits;

    public TWSector(int x, int y) {
        this.x = x;
        this.y = y;
        tiles=0;
        holes=0;
        obstacles=0;
        visits=0;
        unex=Parameters.sectorXSize*Parameters.sectorYSize;
    }

    public int getHoles() {
        return holes;
    }

    public void setHoles(int holes) {
        this.holes = holes;
    }

    public int getObstacles() {
        return obstacles;
    }

    public void setObstacles(int obstacles) {
        this.obstacles = obstacles;
    }

    public int getTiles() {
        return tiles;
    }

    public void setTiles(int tiles) {
        this.tiles = tiles;
    }

    public int getUnex() {
        return unex;
    }

    public void setUnex(int unex) {
        this.unex = unex;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }
    
    
    
    public void incr(Class<?> type) {
        if(type.isInstance(TWTile.class)) tiles++;
        else if(type.isInstance(TWHole.class)) holes++;
        else if(type.isInstance(TWObstacle.class)) obstacles++;
        
    }
    
    public void decr(Class<?> type) {
        if(type.isInstance(TWTile.class)) tiles--;
        else if(type.isInstance(TWHole.class)) holes--;
        else if(type.isInstance(TWObstacle.class)) obstacles--;
        else unex--;
        
    }
    
    public void decreaseUnknown(){
        unex--;
    }
    public void increaseUnknown(){
        unex++;
    }
    
   
    public double getScore(int agentX, int agentY){
        return 100/Math.sqrt((agentX-x)*(agentX-x)+(agentY-y)*(agentY-y))*(5*tiles+5*holes-8*obstacles+unex);
    }
    
    public double getScore(){
        return (5*tiles+5*holes-8*obstacles+unex);
    }

    public int compareTo(Object o) {
        //return (int)Math.round(this.getScore(x,y)-((TWSector)o).getScore(x,y));
        if(o.equals(this)) return 0;
        
        if(this.getVisits()> ((TWSector)o).getVisits()) return -1;
        else return 1;
        //return ;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final TWSector other = (TWSector) obj;
        if (this.x != other.x) {
            return false;
        }
        if (this.y != other.y) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        return hash;
    }
    
    

    public int getVisits() {
        return visits;
    }

    public void increaseVisits() {
        this.visits+=300;
    }
    public void decreaseVisits(){
        this.visits--;
    }
    
    
    
    
}
