Package wolf.city.road

Examples of wolf.city.road.Road


    s.executeUpdate("CREATE TABLE ROADS (id, a, b, type, width);");
    {
      PreparedStatement p = con.prepareStatement("INSERT INTO ROADS VALUES (?, ?, ?, ?, ?);");
      ArrayList<Road> roadList = (ArrayList<Road>) c.rm.roads.queryAll();
      for(int i=0; i<roadList.size(); i++){
        Road r = roadList.get(i);
        p.setInt(1, i);
        p.setInt(2, r.a.id);
        p.setInt(3, r.b.id);
        p.setString(4, r.getType().toString());
        p.setDouble(5, r.width);
        p.addBatch();
      }

      p.executeBatch();
View Full Code Here


      }
    }
    */
    List<Road> roads = rm.roads.queryAll();
    for(int i=roads.size()-1; i>=0; i--){
      Road r = roads.get(i);
      int width;
      int red;
      int green;
      int blue;
      switch(r.getType()){
      case BRIDGE:{ //grey
        width=r.getType().getWidth();
        red = 70;
        green = 70;
        blue = 70;
        break;
      }
      case HIGHWAY:{ //blue
        width=r.getType().getWidth();
        red = 50;
        green = 50;
        blue = 50;
        break;
      }
      case STREET:{ //green
        width=r.getType().getWidth();
        red = 55;
        green = 55;
        blue = 55;
        break;
      }
      case MAIN:{ //green
        width=r.getType().getWidth();
        red = 45;
        green = 45;
        blue = 45;
        break;
      }
      case DEFAULT:{ //red
        width=r.getType().getWidth();
        red = 255;
        green = 0;
        blue = 0;
        break;
      }
View Full Code Here

  public OffRamp(City c){
    this.c = c;
  }
  @Override
  public Road globalGoals(City city, Road road, Direction d) { //0 - left, 1 - forward, 2 - right, 3 - backward
    Road returnRoad = null;

    float previousAngle = (float)Math.toDegrees(Angle.angle(road.a.pos, road.b.pos));
    double nextRoadLength = 64;
    //System.out.println(nextRoadLength);
    if(road.getType() == RoadType.HIGHWAY || road.getType() == RoadType.BRIDGE){
      RoadType nextRoadType = RoadType.STREET;
      Turtle t = new Turtle(road.b.pos, 0);
      float angle = 0;

      t = new Turtle(road.b.pos, 0);
      double roadLength = nextRoadLength;
      switch(d){
      case LEFT: //left
        angle = 90+previousAngle;//RandomHelper.random(city.random.nextFloat(), 50, 20);
        roadLength = nextRoadLength;
        break;
      case FORWARD: //forward
        angle = previousAngle;
        roadLength = nextRoadLength;
        break;
      case RIGHT: //right
        angle = 270+previousAngle;//RandomHelper.random(city.random.nextFloat(), -20, -50);
        roadLength = nextRoadLength;
        break;
      case BACKWARD: //backward
        angle = 180+previousAngle;
        roadLength = nextRoadLength;
        break;
      default:
        //invalid direction
        break;
      }

      t.angle = angle;
      t.move((float)roadLength);
     
      returnRoad = new Road(road.b, new Intersection(new Coordinate(t.pos)), nextRoadType, new Basic(c), road);
    }
    return returnRoad;
  }
View Full Code Here

    this.c = c;
  }

  @Override
  public Road globalGoals(City city, Road road, Direction d) { //0 - left, 1 - forward, 2 - right, 3 - backward
    Road returnRoad = null;

    float previousAngle = (float)Math.toDegrees(Angle.angle(road.a.pos, road.b.pos));
    //double nextRoadLength = (road.a.pos.distance(road.b.pos)*.5) + (idealLength *.5); //used for determining size of new road
    double nextRoadLength = idealLength;
    double nextRoadLengthStreet = 32;
    //System.out.println(nextRoadLength);



    //ramp forward
    //left 50 to 20, forward 20 to -20, right -20 to -50
    RoadType nextRoadType = RoadType.DEFAULT;
    Turtle t = new Turtle(road.b.pos, 0);
    float angle = 0;
    float bestPopulation = 0;
    Coordinate bestPosition = null;
    for(int i = 0;i<numberTests ;i++){
      t = new Turtle(road.b.pos, 0);
      double roadLength = nextRoadLength;
      switch(d){
      case LEFT: //left
        angle = RandomHelper.random(city.random.nextFloat(), turnRateLeftRight, -turnRateLeftRight)+previousAngle+90;
        nextRoadType = RoadType.MAIN;
        roadLength = nextRoadLengthStreet;
        break;
      case FORWARD: //forward
        angle = RandomHelper.random(city.random.nextFloat(), turnRateForward, -turnRateForward)+previousAngle;
        nextRoadType = RoadType.HIGHWAY;
        roadLength = nextRoadLength;//Math.abs(Math.cos(Math.toRadians((previousAngle-angle)%360))*nextRoadLength); //sin approximates how long next road should be
        break;
      case RIGHT: //right
        angle = RandomHelper.random(city.random.nextFloat(), turnRateLeftRight, -turnRateLeftRight)+previousAngle+270;
        nextRoadType = RoadType.MAIN;
        roadLength = nextRoadLengthStreet;
        break;
      case BACKWARD: //backward
        angle = -RandomHelper.random(city.random.nextFloat(), turnRateForward, -turnRateForward)+previousAngle;
        nextRoadType = RoadType.HIGHWAY;
        roadLength = nextRoadLength;
        break;
      default:
        //invalid direction
        break;
      }

      t.angle = angle;
      t.move((float)roadLength);
      float population = city.pop.get((int)t.pos.x, (int)t.pos.y);
      if(population>=bestPopulation ){ //&& water < .7
        bestPopulation = population;
        bestPosition = new Coordinate(t.pos);
      }
    }
    if(bestPosition == null){
      //same as forward
      t = new Turtle(road.b.pos, 0);
      angle = RandomHelper.random(city.random.nextFloat(), 20, -20);
      nextRoadType = RoadType.HIGHWAY;
      double roadLength = Math.abs(Math.sin(Math.toRadians((previousAngle-angle)%360))*nextRoadLength); //sin approximates how long next road should be
      t.angle = angle;
      t.move((float)roadLength);
      returnRoad = new Road(road.b, new Intersection(new Coordinate(t.pos)), nextRoadType, this, road); //roads set to default should die.
    }else{
      returnRoad = new Road(road.b, new Intersection(bestPosition), nextRoadType, this, road); //roads set to default should die.
    }
    return returnRoad;
  }
View Full Code Here

    c = g.c;
  }
  @Override
  public Road globalGoals(City city, Road road, Direction d) {
    double previousAngle = Math.toDegrees(Angle.angle(road.a.pos, road.b.pos));
    Road r = new Road(road.b, new Intersection(road.b.pos), RoadType.STREET, this, road);
    Turtle t;
    if(road.getType() == RoadType.HIGHWAY){// || road.type == RoadType.MAIN){
      t = new Turtle(r.a.pos, previousAngle);
    }else{
      double angle = (Math.floor((previousAngle+45)/90)*90+direction);
 
View Full Code Here

  private City c;
  private Road testedRoad;
 
  public LCPanel(){
    roads = new LinkedList<Road>();
    testRoad = new Road(new Intersection(new Coordinate(10,100)),new Intersection(new Coordinate(400,400)), RoadType.HIGHWAY, null);
    roads.add(new Road(new Intersection(new Coordinate(100,10)),new Intersection(new Coordinate(400,300)), RoadType.HIGHWAY, null));
    roads.add(new Road(new Intersection(new Coordinate(50,25)),new Intersection(new Coordinate(400,200)), RoadType.HIGHWAY, null));
    c = new City(windowHeight*4, windowHeight*4, 0);
    rm = new Roadmap(c);
    for(Road r: roads){
      rm.roads.insert(r.getEnvelope(), r);
    }
View Full Code Here

      moveIntersection();
    }else{
      movingIntersection = null;
    }
   
    testedRoad = rm.localConstraints(new Road(testRoad));
   
    for(int i=0;i<roads.size(); i++){//render roads
      Geometry g = roads.get(i).getGeometry();
     
      gr.setColor(Color.DARK_GRAY);
View Full Code Here

TOP

Related Classes of wolf.city.road.Road

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.