Chaser
RoadSegments
class RoadSeg {
int FromNode ;
int ToNode ;
int i_Category ;
RoadSeg( int from, int to, int Cat) {
FromNode = from ;
ToNode = to ;
i_Category = Cat ;
}
public void draw(Graphics g, City[] cities) {
switch (i_Category) {
case 3: g.setColor(Color.blue) ;
break ;
case 2: g.setColor(Color.green) ;
break ;
case 4: g.setColor(Color.orange) ;
break ;
default: g.setColor(Color.gray) ;
}
g.drawLine(cities[FromNode].p_Location.x,
cities[FromNode].p_Location.y,
cities[ToNode].p_Location.x,
cities[ToNode].p_Location.y) ;
}
} // End of RoadSeg Class
Cities
class City {
int Print ;
String s_Name ;
Point p_Location ;
City(){
Print = 0;
s_Name = new String("") ;
p_Location = new Point(0,0) ;
}
City( String s, int x, int y, int c) {
Print = c ;
s_Name = new String(s) ;
p_Location = new Point(x,y) ;
}
public void show(Graphics g) {
if (Print == 0) return ;
g.setColor(Color.black) ;
g.drawString(s_Name, p_Location.x, p_Location.y) ;
}
} // End of City Class
Storm
class Storm {
boolean isValid = true;
int uncertainty = 5 ;
Point p_Pos ;
Point p_Vect ;
Point p_Intercept ;
int torHorz = 15 ;
int torVert = 20 ;
Storm( int PX, int PY, int VX, int VY) {
p_Pos = new Point(PX,PY) ;
p_Vect = new Point(VX, VY) ;
p_Intercept = new Point(PX, PY) ;
}
public void draw( Image smtor, Graphics g, Applet a) {
if (isValid) {
g.setColor(Color.yellow) ;
g.drawString("S", p_Pos.x - 4 , p_Pos.y + 4) ;
g.setColor(Color.red) ;
g.drawOval(p_Intercept.x, p_Intercept.y,uncertainty,uncertainty) ;
}
}
public void update(int Width, int Height) {
// Update StormPosition and Vector
p_Pos.y += p_Vect.y ;
p_Pos.x += p_Vect.x ;
if ( (p_Pos.y < 0 ) || (p_Pos.x < 0) ||
(p_Pos.x > Width) || (p_Pos.y > Height) )
isValid = false ;
}
public Point predict( int Time) {
int Px = p_Pos.x + (p_Vect.x * Time) ;
int Py = p_Pos.y + (p_Vect.y * Time) ;
p_Intercept.x = Px ;
p_Intercept.y = Py ;
Point rv = new Point(Px, Py) ;
return rv ;
}
public void setPosition(Point here) {
p_Pos.y = here.y ;
p_Pos.x = here.x ;
isValid = true;
}
public void setVect(Point here, int VectorScale) {
p_Vect.y = (here.y - p_Pos.y) / VectorScale ;
p_Vect.x = (here.x - p_Pos.x) / VectorScale ;
}
public int Speed() {
return (int) (12 * Math.sqrt( (p_Vect.x*p_Vect.x) + (p_Vect.y*p_Vect.y)));
}
} // end of Storm Class
Chaser
class Chaser {
Point p_Position ;
Point p_Target ;
double d_Speed;
Chaser( int x, int y) {
p_Position = new Point(x ,y) ;
p_Target = new Point(x,y) ;
d_Speed = 12.0 ;
}
public int driveTime(Point P) {
double x = (P.x - p_Position.x) * (P.x - p_Position.x) ;
double y = (P.y - p_Position.y) * (P.y - p_Position.y) ;
double speed = d_Speed / 2 ;
return (int)(Math.sqrt(x+y) / speed) ;
}
public void draw(Graphics g) {
g.setColor(Color.red) ;
g.drawString("C",p_Position.x-4, p_Position.y+4);
}
public void move(int RoadCond) {
// Move ChaseCar
int dx = p_Position.x - p_Target.x ;
int dy = p_Position.y - p_Target.y ;
int mmx = 0 ;
int mmy = 0 ;
double vel = d_Speed / RoadCond ;
double hyp = 0.0 ;
if ((dx!=0) || (dy!=0)) {
hyp = Math.sqrt((dx*dx) + (dy*dy));
// get maxmove components
// If we would overshoot the target, just go there.
mmx = (int)(vel * (dx / hyp));
p_Position.x -= mmx;
mmy = (int)(vel * (dy / hyp));
p_Position.y -= mmy;
}
}
public void retarget( Point target ) {
p_Target = target ;
}
} // End of Chaser Class
Data Set
// Set up Cities
c_Cities[0] = new City("Norman", 213,183,1);
c_Cities[1] = new City("Ok. City", 209, 154,1) ;
c_Cities[2] = new City("Tulsa", 352, 91,1) ;
c_Cities[3] = new City("Enid", 177, 63,1) ;
c_Cities[4] = new City("Lawton", 136, 246,1) ;
c_Cities[5] = new City("Ardmore", 240, 290,1) ;
c_Cities[6] = new City("Muskogee", 386, 128,1) ;
c_Cities[7] = new City("I35x194", 223,62,0) ;
c_Cities[8] = new City("I40x240", 338, 160, 0) ;
c_Cities[9] = new City("I40x286", 405, 153, 0) ;
c_Cities[10] = new City("I35X231", 223,0,0) ;
c_Cities[11] = new City("Fort Smith", 466, 162, 0) ;
c_Cities[12] = new City("Joplin", 443, 0, 1) ;
c_Cities[13] = new City("Pauls Valley", 232, 233, 2) ;
c_Cities[14] = new City("Chickasha", 174, 199, 2) ;
c_Cities[15] = new City("Clinton", 82, 153, 2) ;
c_Cities[16] = new City("Snyder", 90, 242, 3) ;
c_Cities[17] = new City("Fairview", 127, 74, 3) ;
c_Cities[18] = new City("McAlester", 355, 210, 1) ;
c_Cities[19] = new City("Hugo", 383, 306, 1) ;
c_Cities[20] = new City("Ada", 283, 226, 1) ;
c_Cities[21] = new City("Shawnee", 258, 170, 1) ;
c_Cities[22] = new City("Chandler", 260, 132, 2) ;
c_Cities[23] = new City("Asher", 260, 205, 0) ;
c_Cities[24] = new City("Purcell", 222, 205, 0) ;
c_Cities[25] = new City("El Reno", 172, 152, 2) ;
c_Cities[26] = new City("Seiling", 90, 87, 0) ;
c_Cities[27] = new City("Guthrie", 216, 115, 0) ;
c_Cities[28] = new City("Kingfisher", 173, 117, 0) ;
c_Cities[29] = new City("Stillwater", 245, 91, 1) ;
c_Cities[30] = new City("Antlers", 371, 283, 0) ;
c_Cities[31] = new City("Talihina", 420, 230, 0) ;
c_Cities[32] = new City("Wewoka", 295, 190, 0) ;
c_Cities[33] = new City("Watonga", 132, 119, 0) ;
c_Cities[34] = new City("Hobart", 76, 203, 0) ;
c_Cities[35] = new City("Durant", 308, 310, 0) ;
c_Cities[36] = new City("Atoka", 329, 268, 0) ;
c_Cities[37] = new City("I40x82", 110, 151, 0) ;
c_Cities[38] = new City("I40x101", 139, 150, 0) ;
c_Cities[39] = new City("Putnam", 87, 117, 0) ;
// assume we start in Ardmore
TargetNodeID = 5 ;
car = new Chaser(c_Cities[TargetNodeID].p_Location.x,
c_Cities[TargetNodeID].p_Location.y);
// Set up Roads and DriveTimes
for ( i= 0; i < MAXCITY; i++) {
for ( int j=0; j< MAXCITY; j++) drivetime[i][j] = 1.0E9 ;
}
initRoadSeg(0,0,1,2); // OKC to Norman
initRoadSeg(1,1,22,3) ; // OKC to Chandler
initRoadSeg(2,4,14,3) ; // Lawton to Chickasha
initRoadSeg(3,13,24,2) ; // Pauls to purcell
initRoadSeg(4,3,7,3) ; // Enid to I35X194
initRoadSeg(5,1,27,2) ; // Guthrie to OKC
initRoadSeg(6,7,10,2) ; // I-35 Exit 194 to StateLine
initRoadSeg(7,1,21,2) ; // OKC to Shawnee
initRoadSeg(8,8,2,3) ; // I40X240 to Tulsa
initRoadSeg(9,7,29,3) ; // I35X194 to stillwater
initRoadSeg(10,8,9,2) ; // I40X240 to I40X286
initRoadSeg(11,9,11,2) ; // I40X286 to I40X330
initRoadSeg(12,9,6,3) ; // I40X286 to Muskegee
initRoadSeg(13,6,2,3) ; // Muskegee to Tulsa
initRoadSeg(14,2,12,2) ; // Tulsa to Missouri
initRoadSeg(15,5,13,2) ; // Ardmore to Pauls
initRoadSeg(16,14,1,2) ; // Chic to OKC
initRoadSeg(17,14,0,4) ; // chic to norman
initRoadSeg(18,25,1,2) ; // elreno to okc
initRoadSeg(19,4,16,4) ; // lawton to snyder
initRoadSeg(20,15,34,3) ; // clinton to snyder
initRoadSeg(21,15,39,3) ; // clinton to putnam
initRoadSeg(22,17,3,3) ; // fv to enid
initRoadSeg(23,8,18,3) ; // i40x240 to macalester
initRoadSeg(24,18,30,3) ; // macalester to antlers
initRoadSeg(25,5,35,4) ; // ardmore to hugo
initRoadSeg(26,30,31,4) ; // antlers to fort talihina
initRoadSeg(27,20,36,4) ; // ada to atoka
initRoadSeg(28,0,23,4) ; // norman to asher
initRoadSeg(29,5,20,4) ; // ardmore to ada
initRoadSeg(30,0,24,2) ; // norman to purcell
initRoadSeg(31,22,2,3) ; // chandler to tulsa
initRoadSeg(32,21,22,4) ; // Shawnee to chandler
initRoadSeg(33,21,8,2) ; // shawnee to i40x240
initRoadSeg(34,21,23,3) ; // shawnee to asher
initRoadSeg(35,23,20,3) ; // asher to ada
initRoadSeg(36,20,18,4) ; // ada to macalester
initRoadSeg(37,20,13,4) ; // ada to pauls
initRoadSeg(38,24,23,3) ; // purcell to asher
initRoadSeg(39,14,13,6) ; // chickasha to pauls
initRoadSeg(40,25,3,3) ; // elreno to enid
initRoadSeg(41,15,37,2) ; // clinton to i40x82
initRoadSeg(42,33,26,3) ; // watonga to seiling
initRoadSeg(43,26,17,3) ; // seiling to fairview
initRoadSeg(44,21,32,6) ; // shawnee to wewoka
initRoadSeg(45,0,21,3) ; // norman to shawnee
initRoadSeg(47,27,2,3) ; // guthrie to tulsa
initRoadSeg(46,7,27,2) ; // Guthrie to I35X194
initRoadSeg(48,28,27,3) ; // kingfisher to guthrie
initRoadSeg(49,29,2,2) ; // stillwater to tulsa
initRoadSeg(50,27,29,4) ; // guthrie to stillwater
initRoadSeg(51,30,19,3) ; // antlers to hugo
initRoadSeg(52,18,31,6) ; // macalester to talihina
initRoadSeg(53,31,11,4) ; // talihina to fort smith
initRoadSeg(54,32,18,6) ; // wewoka to macalester
initRoadSeg(55,26,33,4) ; // watonga to seiling
initRoadSeg(56,33,28,4) ; // watonga to kingfisher
initRoadSeg(57,34,16,4) ; // hobart to snyder
initRoadSeg(58,35,19,4) ; // durant to hugo
initRoadSeg(59,36,30,4) ; // atoka to antlers
initRoadSeg(60,35,36,4) ; // durant to atoka
initRoadSeg(61,36,18,4) ; // atoka to macalester
initRoadSeg(62,34,14,4) ; // hobart to chickasha
initRoadSeg(63,37,38,2) ; // i40x82 to i40x101
initRoadSeg(64,38,25,2) ; // i40x101 to elreno
initRoadSeg(65,39,26,3) ; // putnam to seiling
Tagger
Back To Jim's Storm Page
Back To Jim's Home Page
Send E-mail