/************************************ * Umass Amherst * CS377 Operating System * Lab2: * Author: Qi Li, Andrew Fagg * Date: 9/22/2002 * * Class in this file: Abstract_Robot * Compile: javac Abstract_Robot.java * Run: n/a ***********************************/ import java.util.*; import java.lang.*; /*********************************** * ClassName: Abstract_Robot * SuperClass: Thread * Description: Beginnings of the Robot Thread * Methods: * GetPosRow() GetPosCol(): get the robot Row position * SetPosRow() SetPosCol(): set the robot Col position * getNofEat(): Return the number of edible goals * * Methods required to be implemented: * run(): Top level thread code * ************************************/ abstract class Abstract_Robot extends Thread { private int Row; //the robot's Row Position private int Col; //the robot's Col Position char cColor; //the Robot 's Color int id; //Identity of the robot Map_Data myGrid; // Reference to the Map_Data in which the robot lives Abstract_Distance myDist; // Reference to the distance matrix for this robot public void setColor(char inC){ cColor=inC ;} //set color to the robots int nMaxRow,nMaxCol; // the size of map, which is equal to nSizeRow,nSizeCol in Map //int nEatable; // the number of edible goals for this robot. boolean bDead=false; // True if the robot is dead final int GetPosRow(){return Row;} //get row final int GetPosCol(){return Col;} //get column final char GetColor(){return cColor;} //get color // Set the Row of the robot final void SetPosRow(int new_row) { // Do not remove this sleep try { sleep(1); } catch(InterruptedException e){}; Row = new_row; }; // Set the Col of the robot final void SetPosCol(int new_col) { // Do not remove this sleep try { sleep(1); } catch(InterruptedException e){}; Col = new_col; }; ////////////////////////////////////////////////////////////////////// // Get the number of current edible goals by this color robot ///////////////////////////////////////// public int getNofEat(){ int nCanEat=0; for (int i=0;i