package main;

import domain.BlockType;
import domain.fluents.BlockAt;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static main.JavaAgent.*;

//All fields are case sensitive in relation to their json counterparts
public class Observations {
    public int TimeAlive;
    public float XPos;
    public float YPos;
    public float ZPos;
    public float Yaw;
    public float Pitch;
    public boolean IsAlive;
    public List<String> CellObs;
    public List<Integer> nbItems;
    public List<String> items;

    public BlockAt blockAt(float x, float y, float z){
        return new BlockAt(x,y,z,BlockType.air); //TODO: Julian, I will leave this for you.
    }

    public List<BlockAt> findBlockType(BlockType blockType) {
        List<BlockAt> blocks = new ArrayList<BlockAt>();
        int i = 0;
        int xRelative;
        int yRelative;
        int zRelative;
        for (String block : CellObs) {
            if (blockType.compareTo(BlockType.valueOf(block)) == 0) {
                // calculate position in the grid
                xRelative = i % X_OBSERVATION_SIZE;
                yRelative = (i % (X_OBSERVATION_SIZE * Y_OBSERVATION_SIZE)) / X_OBSERVATION_SIZE;
                zRelative = i / (X_OBSERVATION_SIZE * Y_OBSERVATION_SIZE);
                // calculate position relative to us
                xRelative += X_START_OBSERVATION;
                yRelative += Y_START_OBSERVATION;
                zRelative += Z_START_OBSERVATION;
                // add new block at with absolute position to list
                blocks.add(new BlockAt(XPos + xRelative, YPos + yRelative, ZPos + zRelative, blockType));
            }
            i++;
        }
        if (blocks.size() == 0) {
            // no blocks of given type found
            return Arrays.asList();
        }
        return blocks;
    }

    public int numberOf(String item) {
        int index = 0;
        int total = 0;
        for (String s : items) {
            if (s.equals(item)) {
                total += nbItems.get(index);
            }
            ++index;
        }
        return total;
    }
}

@@ -595,18 +595,416 @@
 float z)
+ 
 %7B%0A
+        // to test for any block just see that there is no air%0A        int i = 0;%0A        for (String block : CellObs) %7B%0A            int nX = i %25 X_OBSERVATION_SIZE;%0A            int nY = (i %25 (X_OBSERVATION_SIZE * Y_OBSERVATION_SIZE)) / X_OBSERVATION_SIZE;%0A            int nZ = i / (X_OBSERVATION_SIZE * Y_OBSERVATION_SIZE);%0A            if (nX == (int)x && nY == (int)y && nZ == (int)z) %7B%0A        
         
@@ -1028,12 +1028,15 @@
 t(x,
+ 
 y,
+ 
 z,
+ 
 Bloc
@@ -1045,56 +1045,117 @@
 ype.
-air); //TODO: Julian, I will leave this for you.
+valueOf(block));%0A            %7D%0A            i++;%0A        %7D%0A        return new BlockAt(x, y, z, BlockType.Any);
 %0A   

Add BlockAt to Observations