Gridworld案例研究:如何使小动物吃掉多个地方的虫子?

时间:2019-03-23 03:03:57

标签: java gridworld

我的小动物基本上应该吃掉最多3个空间中的虫子,而不会跳动它们。我知道我应该做些什么使程序认为小生物的位置在其实际位置周围的每个空间中,但是我对如何做到这一点感到困惑。

public void processActors(ArrayList<Actor> actors){
Location loc = getLocation();
ArrayList<Integer> row = new ArrayList<Integer>();
ArrayList<Integer> col= new ArrayList<Integer>();
for(int i = 0; i <= 8; i++){
   row.add(loc.getRow());
   //Something to put that changes the critters row location
    for(int j = 0; j<= 8; j++){
        col.add(loc.getCol());
        //Something to put that changes the critters column location
    }
}


}

我试图通过getRow()和getCol()方法使用两个数组从远处吃掉虫子,但是这样做似乎无效,并且stil只吃掉与之相邻的虫子它。

0 个答案:

没有答案