Ejemplo n.º 1
0
  /** @param args */
  public static void main(String[] args) {

    int maxSteps; // maximum number of steps in a walk
    int maxCoord; // the maximum x and y coordinate
    int numDrunks;
    int numfall = 0;
    Scanner scan = new Scanner(System.in);

    System.out.println("\nDrunks Walk  Program");
    System.out.println();

    System.out.print("Enter the boundary for the square: ");
    maxCoord = scan.nextInt();

    System.out.print("Enter the maximum number of steps: ");
    maxSteps = scan.nextInt();

    System.out.print("Enter the number of drunks: ");
    numDrunks = scan.nextInt();

    for (int i = 1; i <= numDrunks; i++) {
      RandomWalk drunk = new RandomWalk(maxSteps, maxCoord);
      drunk.walk();
      System.out.println(drunk);
      if (!drunk.inBounds()) {
        numfall++;
      }
    }
    System.out.println("The times of the drunks falling off is " + numfall);
  }
Ejemplo n.º 2
0
 @Test
 public void testComputeSolution() {
   RandomWalk sp = new RandomWalk(new Random(0));
   FSGAgentState state = new FSGAgentState(sp);
   double[] solution = state.computeSolution(sp.policy(), 0.9, 0.0);
   checkEquals(sp.expectedDiscountedSolution(), solution);
   checkEquals(
       new double[] {1 / 6.0, 2 / 6.0, 3 / 6.0, 4 / 6.0, 5 / 6.0},
       state.computeSolution(sp.policy(), 1.0, 0.5));
 }
Ejemplo n.º 3
0
  public static void main(String[] args) {
    int maxSteps; // maximum number of steps in a walk
    int maxCoord; // the maximum x and y coordinate
    int x, y; // starting x and y coordinates for a walk
    Scanner scan = new Scanner(System.in);
    System.out.println("\nRandom Walk Test Program");
    System.out.println();
    System.out.print("Enter the boundary for the square: ");
    maxCoord = scan.nextInt();
    System.out.print("Enter the maximum number of steps: ");
    maxSteps = scan.nextInt();
    System.out.print("Enter the starting x and y coordinates with " + "a space between: ");
    x = scan.nextInt();
    y = scan.nextInt();

    RandomWalk rw1 = new RandomWalk(10, 5);
    RandomWalk rw2 = new RandomWalk(maxSteps, maxCoord, x, y);

    for (int i = 1; i <= 5; i++) {
      rw1.takeStep();
      rw2.takeStep();
      System.out.println(rw1);
      System.out.println(rw2);
    }

    System.out.println(rw1.getMaxDistance());
    System.out.println(rw2.getMaxDistance());

    //        RandomWalk rw3 = new RandomWalk(200,10);
    //        rw3.walk();
    //        System.out.println(rw3);

  }
Ejemplo n.º 4
0
 @Test
 public void testRandomWalkLeftTrajectory() {
   RandomWalk sp = new RandomWalk(leftPolicy);
   assertEquals(new StepData(0, null, null, RandomWalk.C, 0.0, RandomWalk.left), sp.step());
   assertEquals(
       new StepData(1, RandomWalk.C, RandomWalk.left, RandomWalk.B, 0.0, RandomWalk.left),
       sp.step());
   assertEquals(
       new StepData(2, RandomWalk.B, RandomWalk.left, RandomWalk.A, 0.0, RandomWalk.left),
       sp.step());
   assertEquals(new StepData(3, RandomWalk.A, RandomWalk.left, null, 0.0, null), sp.step());
   assertEquals(new StepData(4, null, null, RandomWalk.C, 0.0, RandomWalk.left), sp.step());
   assertEquals(
       new StepData(5, RandomWalk.C, RandomWalk.left, RandomWalk.B, 0.0, RandomWalk.left),
       sp.step());
 }
Ejemplo n.º 5
0
 @Test
 public void testRandomWalkRightTrajectory() {
   RandomWalk sp = new RandomWalk(rightPolicy);
   assertEquals(new StepData(0, null, null, RandomWalk.C, 0.0, RandomWalk.right), sp.step());
   assertEquals(
       new StepData(1, RandomWalk.C, RandomWalk.right, RandomWalk.D, 0.0, RandomWalk.right),
       sp.step());
   assertEquals(
       new StepData(2, RandomWalk.D, RandomWalk.right, RandomWalk.E, 0.0, RandomWalk.right),
       sp.step());
   assertEquals(new StepData(3, RandomWalk.E, RandomWalk.right, null, 1.0, null), sp.step());
   assertEquals(new StepData(4, null, null, RandomWalk.C, 0.0, RandomWalk.right), sp.step());
   assertEquals(
       new StepData(5, RandomWalk.C, RandomWalk.right, RandomWalk.D, 0.0, RandomWalk.right),
       sp.step());
 }