package pacman; import games.math.Vector2d; import java.util.Collection; import java.util.ArrayList; import java.awt.*; public class GameState implements Drawable { static int strokeWidth = 5; static Stroke stroke = new BasicStroke(strokeWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER); Board gameBoard; Agent agent; Vector2d closestPill; Vector2d closestPowerPill; Vector2d secondPill; Vector2d closestGhost; Vector2d secondGhost; Vector2d thirdGhost; Vector2d fourthGhost; Vector2d closestEdible; Vector2d secondEdible; Vector2d thirdEdible; Vector2d fourthEdible; Vector2d tmp; Vector2d blinky; Vector2d inky; Vector2d pinky; Vector2d sue; static double safety=0; static int pillsLeft=754; static int pillsEaten=0; static int powerPillsLeft=4; static int region; boolean edible=false; static ArrayList pacmode=new ArrayList(); public GameState(Board board) { agent = new Agent(); tmp = new Vector2d(); this.gameBoard=board; } public double calculateSafety(){ int nearGhostCount=0; double total=0; if (blinky !=null ){//blinky if(agent !=null){ total=total+blinky.dist(agent.cur); if(blinky.dist(agent.cur) < 20){ System.out.println("Blinky is close to pacman"); nearGhostCount++; } } } if (pinky !=null ){//pinky if(agent !=null){ total=total+pinky.dist(agent.cur); if(pinky.dist(agent.cur) < 20){ System.out.println("Pinky is close to pacman"); nearGhostCount++; } } } if (inky !=null ){//inky if(agent !=null){ total=total+inky.dist(agent.cur); if(inky.dist(agent.cur) < 20){ System.out.println("Inky is close to pacman"); nearGhostCount++; } } } if (sue !=null ){//Sue if(agent !=null){ total=total+sue.dist(agent.cur); if(sue.dist(agent.cur) < 20){ System.out.println("Sue is close to pacman"); nearGhostCount++; } } } double temp= total; //2332.3807579381201883496611510182 max e fasele *4 return temp/2332.380757; } public void reset() { closestPill = null; closestPowerPill=null; closestEdible=null; secondEdible=null; thirdEdible=null; fourthEdible=null; closestGhost=null; secondGhost=null; thirdGhost=null; fourthGhost=null; } public void update(ConnectedSet cs, int[] pix) { // System.out.println("UPDATE IS CALLED"); if (cs.isPacMan()) { agent.update(cs, pix); } else if (cs.ghostLike()) { edible=false; tmp.set(cs.x, cs.y); if (closestGhost == null) closestGhost = new Vector2d(tmp); else if (gameBoard.distance(tmp,agent.cur) < gameBoard.distance(closestGhost,agent.cur)) closestGhost.set(tmp); else if (secondGhost == null) secondGhost = new Vector2d(tmp); else if(gameBoard.distance(tmp,agent.cur) < gameBoard.distance(secondGhost,agent.cur)) secondGhost.set(tmp); else if (thirdGhost == null) thirdGhost = new Vector2d(tmp); else if(gameBoard.distance(tmp,agent.cur) < gameBoard.distance(thirdGhost,agent.cur)) thirdGhost.set(tmp); else if (fourthGhost == null) fourthGhost = new Vector2d(tmp); else { fourthGhost.set(tmp); } } else if(cs.edibleGhost()){ edible=true; safety=1; tmp.set(cs.x, cs.y); if (closestEdible == null) closestEdible = new Vector2d(tmp); else if (gameBoard.distance(tmp,agent.cur) < gameBoard.distance(closestEdible,agent.cur)) closestEdible.set(tmp); else if (secondEdible == null) secondEdible = new Vector2d(tmp); else if(gameBoard.distance(tmp,agent.cur) < gameBoard.distance(secondEdible,agent.cur)) secondEdible.set(tmp); else if (thirdEdible == null) thirdEdible = new Vector2d(tmp); else if(gameBoard.distance(tmp,agent.cur) < gameBoard.distance(thirdEdible,agent.cur)) thirdEdible.set(tmp); else if (fourthEdible == null) fourthEdible = new Vector2d(tmp); else { fourthEdible.set(tmp); } }else if (cs.pill()) { // keep track of the position of the closest pill tmp.set(cs.x, cs.y); if (closestPill == null) { closestPill = new Vector2d(tmp); } else if (gameBoard.distance(tmp,agent.cur) < gameBoard.distance(closestPill,agent.cur)) { closestPill.set(tmp); } else if (secondPill == null) secondPill = new Vector2d(tmp); else if (gameBoard.distance(tmp,agent.cur) < gameBoard.distance(secondPill,agent.cur)) secondPill.set(tmp); }else if(cs.powerPill()){ tmp.set(cs.x, cs.y); if (closestPowerPill == null) { closestPowerPill = new Vector2d(tmp); } else if (gameBoard.distance(tmp,agent.cur) < gameBoard.distance(closestPowerPill,agent.cur)) { closestPowerPill.set(tmp); } } } public boolean storeAlarm(Vector2d a,Vector2d b){ // Stores a in b if(b == null){ b=new Vector2d(a); return false; } else{ if(gameBoard.distance(a,agent.cur)