import java.awt.*; public class CatAndMouseWorld implements RLWorld{ public int bx, by; public int mx, my; public int cx, cy; public int chx, chy; public int hx, hy; public boolean gotCheese = false; public int catscore = 0, mousescore = 0; public int cheeseReward=50, deathPenalty=100; static final int NUM_OBJECTS=6, NUM_ACTIONS=8, WALL_TRIALS=100; static final double INIT_VALS=0; int[] stateArray; double waitingReward; public boolean[][] walls; public CatAndMouseWorld(int x, int y, int numWalls) { bx = x; by = y; makeWalls(x,y,numWalls); resetState(); } public CatAndMouseWorld(int x, int y, boolean[][] newwalls) { bx = x; by = y; walls = newwalls; resetState(); } /******* RLWorld interface functions ***********/ public int[] getDimension() { int[] retDim = new int[NUM_OBJECTS+1]; int i; for (i=0; i1) || (y<-1) || (y>1) || ((y==0)&&(x==0))) return -1; int retVal = vals[y+1][x+1]; return retVal; } public boolean endState() { return endGame(); } public int[] resetState() { catscore = 0; mousescore = 0; setRandomPos(); return getState(); } public double getInitValues() { return INIT_VALS; } /******* end RLWorld functions **********/ public int[] getState() { // translates current state into int array stateArray = new int[NUM_OBJECTS]; stateArray[0] = mx; stateArray[1] = my; stateArray[2] = cx; stateArray[3] = cy; stateArray[4] = chx; stateArray[5] = chy; return stateArray; } public double calcReward() { double newReward = 0; if ((mx==chx)&&(my==chy)) { mousescore++; newReward += cheeseReward; } if ((cx==mx) && (cy==my)) { catscore++; newReward -= deathPenalty; } //if ((mx==hx)&&(my==hy)&&(gotCheese)) newReward += 100; return newReward; } public void setRandomPos() { Dimension d = getRandomPos(); cx = d.width; cy = d.height; d = getRandomPos(); mx = d.width; my = d.height; d = getRandomPos(); chx = d.width; chy = d.height; d = getRandomPos(); hx = d.width; hy = d.height; } boolean legal(int x, int y) { return ((x>=0) && (x=0) && (y=0) && (i=0) && (j