Hello, I am having a problem getting cars in my simulation to move. When cars move in my simulation, they can choose to take a short road, long road, or one of two equidistant medium roads. The cars that go on the short road are fine and make it to the house(PointB in the code), but all the other ones stop in place.
I use a list of x and y coordinates to make them move, using turnToward() and move(). The code used to make all the cars move correctly but now it doesn't for some reason. Here is my relevant code
How do I stop the other cars from being stuck?
I use a list of x and y coordinates to make them move, using turnToward() and move(). The code used to make all the cars move correctly but now it doesn't for some reason. Here is my relevant code
public Car() {
a = new Attitude();
kc = new KnowledgeableChoice();
ilc = new IllogicalChoice();
lr = 0;
sr = 0;
erb = 0;
ert = 0;
hun = 100;
double one = 1;
XLongRoad = new int[5];
XLongRoad[0] = 96;
XLongRoad[1] = 371;
XLongRoad[2] = 548;
XLongRoad[3] = 563;
XLongRoad[4] = 490;
YLongRoad = new int [5];
YLongRoad[0] = 301;
YLongRoad[1] = 383;
YLongRoad[2] = 334;
YLongRoad[3] = 254;
YLongRoad[4] = 185;
XEqRoadBottom = new int [3];
XEqRoadBottom[0] = 336;
XEqRoadBottom[1] = 478;
XEqRoadBottom[2] = 490;
YEqRoadBottom = new int [3];
YEqRoadBottom[0] = 305;
YEqRoadBottom[1] = 241;
YEqRoadBottom[2] = 185;
XEqRoadTop = new int [3];
XEqRoadTop[0] = 315;
XEqRoadTop[1] = 497;
XEqRoadTop[2] = 490;
YEqRoadTop = new int [3];
YEqRoadTop[0] = 75;
YEqRoadTop[1] = 184;
YEqRoadTop[2] = 185;
XShortRoad = new int [2];
XShortRoad[0] = 335;
XShortRoad[1] = 490;
YShortRoad = new int [2];
YShortRoad[0] = 206;
YShortRoad[1] = 185;
}
public void act()
{if (a.IsLogical() == true) {
turnTowards(XShortRoad[sr], YShortRoad[sr]);
move(1);
if (this.getX() == XShortRoad[sr] && this.getY() == YShortRoad[sr] && sr < 1){
sr = sr + 1;
}
}
if (a.IsKnowledgeable() == true && kc.ChooseBottom() == true) {
turnTowards(XEqRoadBottom[erb], YEqRoadBottom[erb]);
move(1);
if (this.getX() == XEqRoadBottom[erb] && this.getY() == YEqRoadBottom[erb] && erb < 2){
erb = erb + 1;
turnTowards(XEqRoadBottom[erb], YEqRoadBottom[erb]);
}
}
if (a.IsKnowledgeable() == true && kc.ChooseTop() == true) {
turnTowards(XEqRoadTop[ert], YEqRoadTop[ert]);
move(1);
if (this.getX() == XEqRoadTop[ert] && this.getY() == YEqRoadTop[ert] && ert < 2){
ert = ert + 1;
}
}
if (a.IsIllogical() && ilc.chooseLong()){
turnTowards(XLongRoad[lr], YLongRoad[lr]);
move(1);
if (this.getX() == XLongRoad[lr] && this.getY() == YLongRoad[lr] && lr < 4){
lr = lr + 1;
}
}
if (a.IsIllogical() == true && ilc.chooseEqTop() == true) {
turnTowards(XEqRoadTop[ert], YEqRoadTop[ert]);
move(1);
if (this.getX() == XEqRoadTop[ert] && this.getY() == YEqRoadTop[ert] && ert < 2){
ert = ert + 1;
}
}
if (a.IsIllogical() == true && ilc.chooseShort() == true) {
turnTowards(XShortRoad[sr], YShortRoad[sr]);
move(1);
if (this.getX() == XShortRoad[sr] && this.getY() == YShortRoad[sr] && sr < 1){
sr = sr + 1;
}
}
if (a.IsIllogical() == true && ilc.chooseEqBottom() == true) {
turnTowards(XEqRoadBottom[erb], YEqRoadBottom[erb]);
move(1);
if (this.getX() == XEqRoadBottom[erb] && this.getY() == YEqRoadBottom[erb] && erb < 2){
erb = erb + 1;
}
}
}
}
class Attitude {
int AttitudeSelect = Greenfoot.getRandomNumber(11);
boolean IsLogical(){
return AttitudeSelect >= 0;
}
boolean IsIllogical(){
return AttitudeSelect == 1;
}
boolean IsKnowledgeable(){
return AttitudeSelect == 0;
}
}
class KnowledgeableChoice {
int kChoice = Greenfoot.getRandomNumber(2);
boolean ChooseTop(){
return kChoice == 1;
}
boolean ChooseBottom(){
return kChoice == 0;
}
}
class IllogicalChoice {
int iChoice = Greenfoot.getRandomNumber(3);
boolean chooseEqTop(){
return iChoice == 0;
}
boolean chooseEqBottom(){
return iChoice == 1;
}
boolean chooseLong(){
return iChoice == 2;
}
boolean chooseShort(){
return iChoice == 3;
}
}

