@BeforeClass
 public void setUp() {
   nonOverlappingExomeIntervals = new ArrayList<>(100);
   final Random rdn =
       new Random(13); // some "random" but fixed seed to make sure errors are deterministic.
   for (int i = 0; i < ExomeToolsTestUtils.REFERENCE_DICTIONARY.size(); i++) {
     int current = 0;
     final SAMSequenceRecord sequence = ExomeToolsTestUtils.REFERENCE_DICTIONARY.getSequence(i);
     while (current < sequence.getSequenceLength()) {
       int start =
           current
               + Math.max(
                   minimumExonIntergapSize,
                   (int)
                       Math.round(
                           rdn.nextGaussian() * sdExonIntergapSize + averageExonIntergapSize));
       if (start >= sequence.getSequenceLength()) {
         break;
       }
       int size =
           Math.max(
               minimumExonSize,
               (int) Math.round(rdn.nextGaussian() * sdExonSize + averageExonSize));
       int stop = start + size - 1;
       if (stop >= sequence.getSequenceLength()) {
         break;
       }
       nonOverlappingExomeIntervals.add(
           ExomeToolsTestUtils.createInterval(sequence.getSequenceName(), start, stop));
       current = stop + 1;
     }
   }
   Collections.sort(nonOverlappingExomeIntervals, IntervalUtils.LEXICOGRAPHICAL_ORDER_COMPARATOR);
   exonDB = new HashedListTargetCollection<>(nonOverlappingExomeIntervals);
 }
  @Override
  public Chart getChart() {

    List<Double> xData = new LinkedList<Double>();
    List<Double> yData = new LinkedList<Double>();
    Random random = new Random();
    int size = 1000;
    for (int i = 0; i < size; i++) {
      xData.add(random.nextGaussian() / 1000);
      yData.add(-1000000 + random.nextGaussian());
    }

    // Create Chart
    Chart chart = new Chart(800, 600);
    chart.getStyleManager().setChartType(ChartType.Scatter);

    // Customize Chart
    chart.getStyleManager().setChartTitleVisible(false);
    chart.getStyleManager().setLegendPosition(LegendPosition.InsideSW);
    chart.getStyleManager().setMarkerSize(16);

    // Series
    chart.addSeries("Gaussian Blob", xData, yData);

    return chart;
  }
 public void breakBlock(World aWorld, int aX, int aY, int aZ, Block par5, int par6) {
   GregTech_API.causeMachineUpdate(aWorld, aX, aY, aZ);
   TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ);
   if ((tTileEntity instanceof IGregTechTileEntity)) {
     IGregTechTileEntity tGregTechTileEntity = (IGregTechTileEntity) tTileEntity;
     Random tRandom = new Random();
     mTemporaryTileEntity.set(tGregTechTileEntity);
     for (int i = 0; i < tGregTechTileEntity.getSizeInventory(); i++) {
       ItemStack tItem = tGregTechTileEntity.getStackInSlot(i);
       if ((tItem != null) && (tItem.stackSize > 0) && (tGregTechTileEntity.isValidSlot(i))) {
         EntityItem tItemEntity =
             new EntityItem(
                 aWorld,
                 aX + tRandom.nextFloat() * 0.8F + 0.1F,
                 aY + tRandom.nextFloat() * 0.8F + 0.1F,
                 aZ + tRandom.nextFloat() * 0.8F + 0.1F,
                 new ItemStack(tItem.getItem(), tItem.stackSize, tItem.getItemDamage()));
         if (tItem.hasTagCompound()) {
           tItemEntity
               .getEntityItem()
               .setTagCompound((NBTTagCompound) tItem.getTagCompound().copy());
         }
         tItemEntity.motionX = (tRandom.nextGaussian() * 0.0500000007450581D);
         tItemEntity.motionY =
             (tRandom.nextGaussian() * 0.0500000007450581D + 0.2000000029802322D);
         tItemEntity.motionZ = (tRandom.nextGaussian() * 0.0500000007450581D);
         aWorld.spawnEntityInWorld(tItemEntity);
         tItem.stackSize = 0;
         tGregTechTileEntity.setInventorySlotContents(i, null);
       }
     }
   }
   super.breakBlock(aWorld, aX, aY, aZ, par5, par6);
   aWorld.removeTileEntity(aX, aY, aZ);
 }
Exemple #4
0
 public void move(int w, int h) {
   x += (float) rng.nextGaussian() * X_STD;
   y += (float) rng.nextGaussian() * Y_STD;
   x = Math.max(0.0f, Math.min((float) w - 1.0f, x));
   y = Math.max(0.0f, Math.min((float) h - 1.0f, y));
   angle += (float) rng.nextGaussian() * A_STD;
 }
Exemple #5
0
 protected void dropInventory(World world, int x, int y, int z) {
   TileEntity tileEntity = world.getTileEntity(x, y, z);
   if (!(tileEntity instanceof IInventory)) {
     return;
   }
   IInventory inventory = (IInventory) tileEntity;
   for (int i = 0; i < inventory.getSizeInventory(); i++) {
     ItemStack itemStack = inventory.getStackInSlot(i);
     if (itemStack != null && itemStack.stackSize > 0) {
       Random rand = new Random();
       float dX = rand.nextFloat() * 0.8F + 0.1F;
       float dY = rand.nextFloat() * 0.8F + 0.1F;
       float dZ = rand.nextFloat() * 0.8F + 0.1F;
       EntityItem entityItem = new EntityItem(world, x + dX, y + dY, z + dZ, itemStack.copy());
       if (itemStack.hasTagCompound()) {
         entityItem
             .getEntityItem()
             .setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy());
       }
       float factor = 0.05F;
       entityItem.motionX = rand.nextGaussian() * factor;
       entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
       entityItem.motionZ = rand.nextGaussian() * factor;
       world.spawnEntityInWorld(entityItem);
       itemStack.stackSize = 0;
     }
   }
 }
  /**
   * Perform the mutation strength strategy vector mutation for Evolution Strategies (Chapter 30) as
   * specified in Algorithm 30.8.
   *
   * @param g the existing genotype in the search space from which a slightly modified copy should
   *     be created
   * @param r the random number generator
   * @return a new genotype
   */
  @Override
  public final double[] mutate(final double[] g, final Random r) {
    final double[] gnew;
    final double t0, t, c, nu;
    int i;
    double x;

    i = g.length;

    c = 1d;

    // set tau0 according to Equation 30.12
    t0 = (c / Math.sqrt(2 * i));

    // set tau according to Equation 30.13
    t = (c / Math.sqrt(2 * Math.sqrt(i)));

    nu = Math.exp(t0 * r.nextGaussian());
    gnew = g.clone();

    // set each gene Definition D4.3 of gnew to ...
    for (; (--i) >= 0; ) {
      do {
        x = gnew[i] * nu * Math.exp(t * r.nextGaussian());
      } while ((x < this.min) || (x > this.max));
      gnew[i] = x;
    }

    return gnew;
  }
  public void ejectContents() {
    float f3 = 0.05F;
    EntityItem entityitem;
    Random rand = new Random();
    float f = rand.nextFloat() * 0.8F + 0.1F;
    float f1 = rand.nextFloat() * 2.0F + 0.4F;
    float f2 = rand.nextFloat() * 0.8F + 0.1F;

    for (int i = 0; i < getSizeInventory(); i++) {
      if (fireItemStacks[i] != null) {
        entityitem =
            new EntityItem(worldObj, xCoord + f, yCoord + f1, zCoord + f2, fireItemStacks[i]);
        entityitem.motionX = (float) rand.nextGaussian() * f3;
        entityitem.motionY = (float) rand.nextGaussian() * f3 + 0.2F;
        entityitem.motionZ = (float) rand.nextGaussian() * f3;
        worldObj.spawnEntityInWorld(entityitem);
      }
    }

    // charcoal
    if (this.charcoalCount > 0) {
      entityitem =
          new EntityItem(
              worldObj,
              xCoord + f,
              yCoord + f1,
              zCoord + f2,
              new ItemStack(TFCItems.Coal, charcoalCount, 1));
      entityitem.motionX = (float) rand.nextGaussian() * f3;
      entityitem.motionY = (float) rand.nextGaussian() * f3 + 0.2F;
      entityitem.motionZ = (float) rand.nextGaussian() * f3;
      worldObj.spawnEntityInWorld(entityitem);
    }
  }
Exemple #8
0
  public int intercept(EntityPlayer p, World world1, Loc loc, int i) {
    if (i == Block.bed.blockID) {
      return AetherBlocks.Bed.blockID;
    }
    if (i == Block.waterMoving.blockID || i == Block.waterStill.blockID) {
      if (world1.getBlockId(loc.x(), loc.y() - 1, loc.z()) == Block.glowStone.blockID
          && ((BlockAetherPortal) AetherBlocks.Portal)
              .tryToCreatePortal(world1, loc.x(), loc.y(), loc.z())) {
        return AetherBlocks.Portal.blockID;
      }
      if (p.dimension != -1) {
        return i;
      }
    }
    Random random = new Random();
    for (int j = 0; j < 10; j++) {
      world1.spawnParticle(
          "smoke",
          loc.x + 0.5D + random.nextGaussian() * 0.10000000000000001D,
          loc.y + 0.5D + random.nextGaussian() * 0.10000000000000001D,
          loc.z + 0.5D + random.nextGaussian() * 0.01D,
          random.nextGaussian() * 0.01D,
          random.nextGaussian() * 0.01D,
          random.nextGaussian() * 0.10000000000000001D);
    }

    if (i == Block.lavaMoving.blockID || i == Block.lavaStill.blockID) {
      return AetherBlocks.Aerogel.blockID;
    }
    if (p.dimension < 0 && (i == Block.waterMoving.blockID || i == Block.waterStill.blockID)) {
      return Block.cobblestone.blockID;
    } else {
      return 0;
    }
  }
  private void feedBaby(EntityAnimal animal, EntityPlayer player, ItemStack stack) {
    int currentAge = animal.getGrowingAge();
    int age = (int) (-currentAge * 0.1F);
    animal.setGrowingAge(currentAge + age);
    player.swingItem();

    Random itemRand = animal.worldObj.rand;
    for (int i = 0; i < 3; i++) {
      double d0 = itemRand.nextGaussian() * 0.02D;
      double d1 = itemRand.nextGaussian() * 0.02D;
      double d2 = itemRand.nextGaussian() * 0.02D;
      animal.worldObj.spawnParticle(
          "happyVillager",
          animal.posX + itemRand.nextFloat() * 0.5,
          animal.posY + 0.5 + itemRand.nextFloat() * 0.5,
          animal.posZ + itemRand.nextFloat() * 0.5,
          d0,
          d1,
          d2);
    }

    if (!player.capabilities.isCreativeMode)
      if (--stack.stackSize <= 0)
        player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
  }
Exemple #10
0
 private void dropItems(World world, int x, int y, int z) {
   Random rand = new Random();
   TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
   if (!(tileEntity instanceof IInventory)) {
     return;
   }
   IInventory inventory = (IInventory) tileEntity;
   for (int i = 0; i < inventory.getSizeInventory(); i++) {
     ItemStack item = inventory.getStackInSlot(i);
     if (item != null && item.stackSize > 0) {
       float rx = rand.nextFloat() * 0.8F + 0.1F;
       float ry = rand.nextFloat() * 0.8F + 0.1F;
       float rz = rand.nextFloat() * 0.8F + 0.1F;
       EntityItem entityItem =
           new EntityItem(
               world,
               x + rx,
               y + ry,
               z + rz,
               new ItemStack(item.itemID, item.stackSize, item.getItemDamage()));
       if (item.hasTagCompound()) {
         entityItem.getEntityItem().setTagCompound((NBTTagCompound) item.getTagCompound().copy());
       }
       float factor = 0.05F;
       entityItem.motionX = rand.nextGaussian() * factor;
       entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
       entityItem.motionZ = rand.nextGaussian() * factor;
       world.spawnEntityInWorld(entityItem);
       item.stackSize = 0;
     }
   }
 }
Exemple #11
0
  /* Straight from InventoryHelper in vanilla code */
  public static void spawnInWorld(World world, BlockPos pos, ItemStack itemStack) {

    float f = RANDOM.nextFloat() * 0.8F + 0.1F;
    float f1 = RANDOM.nextFloat() * 0.8F + 0.1F;
    float f2 = RANDOM.nextFloat() * 0.8F + 0.1F;

    while (itemStack.stackSize > 0) {
      int i = RANDOM.nextInt(21) + 10;

      if (i > itemStack.stackSize) i = itemStack.stackSize;

      itemStack.stackSize -= i;
      EntityItem entityitem =
          new EntityItem(
              world,
              pos.getX() + (double) f,
              pos.getY() + (double) f1,
              pos.getZ() + (double) f2,
              new ItemStack(itemStack.getItem(), i, itemStack.getMetadata()));

      if (itemStack.hasTagCompound())
        entityitem
            .getEntityItem()
            .setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy());

      float f3 = 0.05F;
      entityitem.motionX = RANDOM.nextGaussian() * (double) f3;
      entityitem.motionY = RANDOM.nextGaussian() * (double) f3 + 0.20000000298023224D;
      entityitem.motionZ = RANDOM.nextGaussian() * (double) f3;
      world.spawnEntityInWorld(entityitem);
    }
  }
Exemple #12
0
  public static void dropItem(ItemStack itemStack, World world, int x, int y, int z) {
    double posX = x + rand.nextDouble() * 0.8 + 0.1;
    double posY = y + rand.nextDouble() * 0.8 + 0.1;
    double posZ = z + rand.nextDouble() * 0.8 + 0.1;

    while (itemStack.stackSize > 0) {
      int size = Math.min(itemStack.stackSize, rand.nextInt(21) + 10);
      itemStack.stackSize -= size;
      EntityItem entity =
          new EntityItem(
              world,
              posX,
              posY,
              posZ,
              new ItemStack(itemStack.itemID, size, itemStack.getItemDamage()));
      if (itemStack.hasTagCompound()) {
        entity.getEntityItem().setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy());
      }

      entity.motionX = rand.nextGaussian() * 0.05;
      entity.motionY = rand.nextGaussian() * 0.05 + 0.2;
      entity.motionZ = rand.nextGaussian() * 0.05;
      world.spawnEntityInWorld(entity);
    }
  }
  public static void dropItem(ItemStack item, World world, int x, int y, int z) {
    if (item != null && item.stackSize > 0) {
      float rx = random.nextFloat() * 0.8F + 0.1F;
      float ry = random.nextFloat() * 0.8F + 0.1F;
      float rz = random.nextFloat() * 0.8F + 0.1F;

      EntityItem entityItem =
          new EntityItem(
              world,
              x + rx,
              y + ry,
              z + rz,
              new ItemStack(item.itemID, item.stackSize, item.getItemDamage()));

      if (item.hasTagCompound()) {
        entityItem.getEntityItem().setTagCompound((NBTTagCompound) item.getTagCompound().copy());
      }

      float factor = 0.05F;
      entityItem.motionX = random.nextGaussian() * factor;
      entityItem.motionY = random.nextGaussian() * factor + 0.2F;
      entityItem.motionZ = random.nextGaussian() * factor;
      world.spawnEntityInWorld(entityItem);
      item.stackSize = 0;
    }
  }
Exemple #14
0
  public Organism doVariation(Generation parents, Generation offspring, Selection sel) {
    GAParameters params = GAParameters.getParams();
    Random rand = params.getRandom();

    // pick a parent randomly
    StructureOrg p = (StructureOrg) (sel.doSelection(parents, 1)[0]);
    Cell pStruct = p.getCell();

    // copy the parent's data into new structures
    List<Site> pSites = pStruct.getSites();
    List<Site> newSites = new LinkedList<Site>();

    // perturbing the lattice parameters
    double[][] strain = new double[3][3];
    // initialize the strain matrix to the identity
    // then add some zero mean Gaussian random variables
    for (int i = 0; i < strain.length; i++)
      for (int j = 0; j < strain.length; j++) {
        strain[i][j] = rand.nextGaussian() * sigmaLattice;
        // allow strain matrix perturbations to be only between -1 and 1
        if (strain[i][j] > 1) strain[i][j] = 1;
        if (strain[i][j] < -1) strain[i][j] = -1;
        // add the identity
        if (i == j) strain[i][j] += 1;
      }

    // modify the basis to make newBasis
    double[][] newVectsD = new double[Constants.numDimensions][Constants.numDimensions];
    for (int i = 0; i < Constants.numDimensions; i++)
      for (int j = 0; j < Constants.numDimensions; j++)
        newVectsD[i][j] = pStruct.getLatticeVectors().get(i).getCartesianComponents().get(j);
    // newVects = MatrixMath.SquareMatrixMult(strain, newVects);
    newVectsD = (new Matrix(strain)).times(new Matrix(newVectsD)).getArray();

    List<Vect> newVects = new LinkedList<Vect>();
    for (int i = 0; i < Constants.numDimensions; i++) newVects.add(new Vect(newVectsD[i]));

    // perturb atomic positions
    for (int i = 0; i < pSites.size(); i++) {
      // perturb each site's location with probability mutRate
      List<Double> fracCoords =
          pSites.get(i).getCoords().getComponentsWRTBasis(pStruct.getLatticeVectors());
      if (rand.nextDouble() < mutRate) {
        // perturb by a Gaussian of stddev mutRadius along each axis
        for (int k = 0; k < Constants.numDimensions; k++)
          fracCoords.set(
              k, GAUtils.renormZeroOne(fracCoords.get(k) + rand.nextGaussian() * sigmaAtoms));
      }
      newSites.add(new Site(pSites.get(i).getElement(), new Vect(fracCoords, newVects)));
    }

    // make the new offspring
    StructureOrg result = new StructureOrg(new Cell(newVects, newSites));

    GAOut.out().stdout("StructureMut created new StructureOrg:", GAOut.DEBUG, result.getID());
    GAOut.out().stdout(result.toString(), GAOut.DEBUG, result.getID());

    return result;
  }
  private void spawnParticles() {
    double var8 = posX;
    double var10 = posY;
    double var12 = posZ;
    String var14 = "iconcrack_" + Item.potion.itemID;
    Random var7 = rand;
    for (int var15 = 0; var15 < 8; ++var15) {
      worldObj.spawnParticle(
          var14,
          var8,
          var10,
          var12,
          var7.nextGaussian() * 0.15D,
          var7.nextDouble() * 0.2D,
          var7.nextGaussian() * 0.15D);
    }

    float red = 0.3F;
    float green = 1.0F;
    float blue = 0.1F;
    String var19 = "spell";

    for (int var20 = 0; var20 < 100; ++var20) {
      double var39 = var7.nextDouble() * 4.0D;
      double var23 = var7.nextDouble() * Math.PI * 2.0D;
      double var25 = Math.cos(var23) * var39;
      double var27 = 0.01D + var7.nextDouble() * 0.5D;
      double var29 = Math.sin(var23) * var39;
      if (worldObj.isRemote) {
        EntityFX var31 =
            Minecraft.getMinecraft()
                .renderGlobal
                .doSpawnParticle(
                    var19,
                    var8 + var25 * 0.1D,
                    var10 + 0.3D,
                    var12 + var29 * 0.1D,
                    var25,
                    var27,
                    var29);
        if (var31 != null) {
          float var32 = 0.75F + var7.nextFloat() * 0.25F;
          var31.setRBGColorF(red * var32, green * var32, blue * var32);
          var31.multiplyVelocity((float) var39);
        }
      }
    }

    worldObj.playSoundEffect(
        posX + 0.5D,
        posY + 0.5D,
        posZ + 0.5D,
        "random.glass",
        1.0F,
        worldObj.rand.nextFloat() * 0.1F + 0.9F);
  }
  /**
   * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack,
   * world, entityPlayer
   */
  public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) {
    world.playSoundAtEntity(entityplayer, "morecreeps:firegem", 1.0F, 1.0F);
    itemstack.damageItem(1, entityplayer);
    entityplayer.swingItem();
    List list =
        world.getEntitiesWithinAABB(
            EntityLivingBase.class,
            new AxisAlignedBB(
                    entityplayer.posX,
                    entityplayer.posY,
                    entityplayer.posZ,
                    entityplayer.posX + 1.0D,
                    entityplayer.posY + 1.0D,
                    entityplayer.posZ + 1.0D)
                .expand(10D, 10D, 10D));

    for (int i = 0; i < list.size(); i++) {
      Entity entity = (Entity) list.get(i);

      if (!(entity instanceof EntityLivingBase)) {
        continue;
      }

      EntityLivingBase entityliving = (EntityLivingBase) entity;

      if ((entityliving instanceof CREEPSEntityHotdog)
          || (entityliving instanceof CREEPSEntityHunchback)
          || (entityliving instanceof EntityPlayer)
          || (entityliving instanceof CREEPSEntityGuineaPig)
          || (entityliving instanceof CREEPSEntityPreacher)) {
        continue;
      }

      if (world.isRemote) {
        for (int j = 0; j < 10; j++) {
          double d = random.nextGaussian() * 0.02D;
          double d1 = random.nextGaussian() * 0.02D;
          double d2 = random.nextGaussian() * 0.02D;
          world.spawnParticle(
              EnumParticleTypes.SMOKE_NORMAL,
              entityliving.posX + (double) (random.nextFloat() * 1.5F),
              entityliving.posY + 0.5D + (double) (random.nextFloat() * 2.5F),
              entityliving.posZ + (double) (random.nextFloat() * 1.5F),
              d,
              d1,
              d2);
        }
      }

      entityliving.attackEntityFrom(DamageSource.inFire, 2F);
      entityliving.motionY += 0.5D;
      entityliving.setFire(15);
    }

    return itemstack;
  }
Exemple #17
0
 @Override
 public void randomDisplayTick(World world, int x, int y, int z, Random r) {
   double fx = r.nextGaussian();
   double dx = -0.5 + r.nextDouble() * 2;
   double fz = r.nextGaussian();
   double dz = -0.5 + r.nextDouble() * 2;
   // TODO fix particle rotation
   // Minecraft.getMinecraft().effectRenderer.addEffect(new WormholeParticleFX(world , x + fx + dx
   // , y , z + fz + dz ));
 }
  @Test
  public void testProcessNoNoise() {

    int width = 100;
    int height = 100;
    final int nspots = 4;

    long[] dimensions = new long[] {width, height};
    ArrayImg<UnsignedByteType, ByteArray> img = ArrayImgs.unsignedBytes(dimensions);

    final double[] A0 = new double[nspots];
    final double[] x0 = new double[nspots];
    final double[] y0 = new double[nspots];
    final double[] sigma_x = new double[nspots];
    final double[] sigma_y = new double[nspots];

    Random rangen = new Random(1);
    for (int i = 0; i < nspots; i++) {

      A0[i] = 100 + 10 * rangen.nextGaussian();
      x0[i] = 20 + (width - 20) * rangen.nextDouble();
      y0[i] = 20 + (height - 20) * rangen.nextDouble();
      sigma_x[i] = 2 + 0.5 * rangen.nextGaussian();
      sigma_y[i] = 2 + 0.5 * rangen.nextGaussian();

      double[] params =
          new double[] {
            A0[i], x0[i], y0[i], 1 / sigma_x[i] / sigma_x[i], 1 / sigma_y[i] / sigma_y[i]
          };
      LocalizationUtils.addGaussianSpotToImage(img, params);
    }

    // Instantiate fitter once
    final GaussianPeakFitterND<UnsignedByteType> fitter =
        new GaussianPeakFitterND<UnsignedByteType>(img);

    // No multithreading in the test
    for (int j = 0; j < nspots; j++) {

      Localizable point = new Point(new int[] {(int) x0[j], (int) y0[j]});
      double[] results = fitter.process(point, new double[] {sigma_x[j], sigma_y[j]});

      double A = results[0];
      double x = results[1];
      double y = results[2];
      double sx = 1 / Math.sqrt(results[3]);
      double sy = 1 / Math.sqrt(results[4]);

      assertEq("x", x0[j], x, LOCALIZATION_TOLERANCE_NO_NOISE);
      assertEq("y", y0[j], y, LOCALIZATION_TOLERANCE_NO_NOISE);
      assertEq("σx", sigma_x[j], sx, SIGMA_TOLERANCE_NO_NOISE);
      assertEq("σy", sigma_y[j], sy, SIGMA_TOLERANCE_NO_NOISE);
      assertEq("A", A0[j], A, 20d);
    }
  }
  /** Called whenever the block is removed. */
  @Override
  public void remove(World par1World, int par2, int par3, int par4) {
    if (!c) {
      TileEntityIronFurnace tileentityfurnace =
          (TileEntityIronFurnace) par1World.getTileEntity(par2, par3, par4);

      if (tileentityfurnace != null) {
        label0:
        for (int i = 0; i < tileentityfurnace.getSize(); i++) {
          ItemStack itemstack = tileentityfurnace.getItem(i);

          if (itemstack == null) {
            continue;
          }

          float f = a.nextFloat() * 0.8F + 0.1F;
          float f1 = a.nextFloat() * 0.8F + 0.1F;
          float f2 = a.nextFloat() * 0.8F + 0.1F;

          do {
            if (itemstack.count <= 0) {
              continue label0;
            }

            int j = a.nextInt(21) + 10;

            if (j > itemstack.count) {
              j = itemstack.count;
            }

            itemstack.count -= j;
            EntityItem entityitem =
                new EntityItem(
                    par1World,
                    par2 + f,
                    par3 + f1,
                    par4 + f2,
                    new ItemStack(itemstack.id, j, itemstack.getData()));

            if (itemstack.hasTag()) {
              entityitem.itemStack.setTag((NBTTagCompound) itemstack.getTag().clone());
            }

            float f3 = 0.05F;
            entityitem.motX = (float) a.nextGaussian() * f3;
            entityitem.motY = (float) a.nextGaussian() * f3 + 0.2F;
            entityitem.motZ = (float) a.nextGaussian() * f3;
            par1World.addEntity(entityitem);
          } while (true);
        }
      }
    }

    super.remove(par1World, par2, par3, par4);
  }
  private void spawnBaby() {
    EntityAgeable var1 = this.theAnimal.createChild(this.targetMate);
    if (var1 != null) {
      EntityPlayer var2 = this.theAnimal.func_146083_cb();
      if (var2 == null && this.targetMate.func_146083_cb() != null) {
        var2 = this.targetMate.func_146083_cb();
      }

      if (var2 != null) {
        var2.triggerAchievement(StatList.animalsBredStat);
        if (this.theAnimal instanceof EntityCow) {
          var2.triggerAchievement(AchievementList.breedCow);
        }
      }

      this.theAnimal.setGrowingAge(6000);
      this.targetMate.setGrowingAge(6000);
      this.theAnimal.resetInLove();
      this.targetMate.resetInLove();
      var1.setGrowingAge(-24000);
      var1.setLocationAndAngles(
          this.theAnimal.posX, this.theAnimal.posY, this.theAnimal.posZ, 0.0F, 0.0F);
      this.theWorld.spawnEntityInWorld(var1);
      Random var3 = this.theAnimal.getRNG();

      for (int var4 = 0; var4 < 7; ++var4) {
        double var5 = var3.nextGaussian() * 0.02D;
        double var7 = var3.nextGaussian() * 0.02D;
        double var9 = var3.nextGaussian() * 0.02D;
        this.theWorld.spawnParticle(
            EnumParticleTypes.HEART,
            this.theAnimal.posX
                + (double) (var3.nextFloat() * this.theAnimal.width * 2.0F)
                - (double) this.theAnimal.width,
            this.theAnimal.posY + 0.5D + (double) (var3.nextFloat() * this.theAnimal.height),
            this.theAnimal.posZ
                + (double) (var3.nextFloat() * this.theAnimal.width * 2.0F)
                - (double) this.theAnimal.width,
            var5,
            var7,
            var9,
            new int[0]);
      }

      if (this.theWorld.getGameRules().getGameRuleBooleanValue("doMobLoot")) {
        this.theWorld.spawnEntityInWorld(
            new EntityXPOrb(
                this.theWorld,
                this.theAnimal.posX,
                this.theAnimal.posY,
                this.theAnimal.posZ,
                var3.nextInt(7) + 1));
      }
    }
  }
 private void dropItemStack(ItemStack stack) {
   Random random = BetterStorage.random;
   float x = random.nextFloat() * 0.8F + 0.1F;
   float y = random.nextFloat() * 0.8F + 0.1F;
   float z = random.nextFloat() * 0.8F + 0.1F;
   EntityItem item = new EntityItem(worldObj, xCoord + x, yCoord + y, zCoord + z, stack);
   item.motionX = random.nextGaussian() * 0.05F;
   item.motionY = random.nextGaussian() * 0.05F + 0.2F;
   item.motionZ = random.nextGaussian() * 0.05F;
   worldObj.spawnEntityInWorld(item);
 }
  @Override
  public void checkStack(
      World par1World,
      int par2,
      int par3,
      int par4,
      Entity triggerer,
      ArrayList<ItemStack> stacks) {
    if (stacks.isEmpty()) {
      return;
    }

    if (this.arrayContainsEqualStack(stacks, new ItemStack(Item.firework))
        && this.arrayContainsEqualStack(stacks, new ItemStack(Item.fireballCharge))) {
      int index0 = this.arrayIndexOfStack(stacks, new ItemStack(Item.firework));
      int index1 = this.arrayIndexOfStack(stacks, new ItemStack(Item.fireballCharge));
      EnumFacing face = getFacing(par1World, par2, par3, par4);

      while (stacks.get(index0).stackSize > 0 && stacks.get(index1).stackSize > 0) {
        double d0 = par2 + (double) ((float) face.getFrontOffsetX() * 0.3F);
        double d1 = par3 + (double) ((float) face.getFrontOffsetX() * 0.3F);
        double d2 = par4 + (double) ((float) face.getFrontOffsetZ() * 0.3F);
        Random random = par1World.rand;
        double d3 = random.nextGaussian() * 0.05D + (double) face.getFrontOffsetX();
        double d4 = random.nextGaussian() * 0.05D + (double) face.getFrontOffsetY();
        double d5 = random.nextGaussian() * 0.05D + (double) face.getFrontOffsetZ();
        EntityFireball fireball = new EntityLargeFireball(par1World, d0, d1, d2, d3, d4, d5);
        par1World.spawnEntityInWorld(fireball);

        if (triggerer instanceof EntityLivingBase) {
          boolean shouldRun = true;
          if (triggerer instanceof EntityPlayer) {
            EntityPlayer player = (EntityPlayer) triggerer;
            if (player.capabilities.isCreativeMode) {
              // Remove the bellow comment to make the player in
              // creative mode not get launched
              // shouldRun = false;
            }
          }

          if (shouldRun) {
            triggerer.mountEntity(fireball);
          }
        }

        this.removeItemFromInventory(par1World, par2, par3, par4, new ItemStack(Item.firework, 1));
        stacks.get(index0).stackSize--;
        this.removeItemFromInventory(
            par1World, par2, par3, par4, new ItemStack(Item.fireballCharge, 1));
        stacks.get(index1).stackSize--;
      }
    }
  }
 void initWeights(Random r) {
   double dev = Math.max(0.3, 1.0 / weights.rows());
   for (int i = 0; i < weights.rows(); i++) {
     double[] row = weights.row(i);
     for (int j = 0; j < weights.cols(); j++) {
       row[j] = dev * r.nextGaussian();
     }
   }
   for (int j = 0; j < weights.cols(); j++) {
     bias[j] = dev * r.nextGaussian();
   }
 }
Exemple #24
0
 /**
  * Moves the particle's position
  *
  * @param turn turn value, in degrees
  * @param forward move value, must be >= 0
  */
 public void move(float turn, float forward) throws Exception {
   if (forward < 0) {
     throw new Exception("Robot cannot move backwards");
   }
   orientation += turn + (float) random.nextGaussian() * turnNoise;
   orientation = circle(orientation, 2f * (float) Math.PI);
   double dist = forward + random.nextGaussian() * forwardNoise;
   x += Math.cos(orientation) * dist;
   y += Math.sin(orientation) * dist;
   x = circle(x, worldWidth);
   y = circle(y, worldHeight);
 }
Exemple #25
0
  public static String getPrefix(Random rand, float grade) {
    if (rand.nextGaussian() * grade > 1) {
      int prefixID = (int) (Math.abs(rand.nextGaussian()) * grade / 10f);

      if (prefixID >= prefix.length) {
        prefixID = prefix.length - 1;
      }

      return prefix[prefixID];
    }

    return "";
  }
Exemple #26
0
  /**
   * Modify a constant value
   *
   * @param orig the original value
   * @param r the randomizer
   * @return the new value
   */
  protected static final double modify(final double orig, final Random r) {
    double scale, v;

    scale = Math.abs(orig);
    if (scale <= 0d) {
      scale = 1e-10;
    }

    do {
      v = (r.nextGaussian() * scale * Math.exp(r.nextGaussian() - 4));
    } while (v == 0d);

    return (orig + v);
  }
/**
 * A processor that generates sensor readings. You do not need to understand the internal working of
 * this class. You should understand how to use it though. See the process method {@link
 * SensorReadingGenerator} {@link #process(StartSignal)}.
 *
 * @author fmma
 */
public class SensorReadingGenerator implements Processor<StartSignal, SensorReading> {

  private Random random = new Random();

  private float humidity = (float) (random.nextGaussian() * 25 + 75);
  private float temperature = (float) (random.nextGaussian() * 25 + 25);

  private float dh = 0;
  private float dt = 0;
  private int tick = 0;

  /**
   * {@inheritDoc}
   *
   * <p>A sensor reading generator receives a single start signal returns an infinite iterator that
   * generates sensor readings. The start signal should be manually pushed to the sensor node.
   */
  @Override
  public Iterator<SensorReading> process(StartSignal in) {
    return new Iterator<SensorReading>() {

      @Override
      public boolean hasNext() {
        return true;
      }

      @Override
      public SensorReading next() {
        SensorReading reading = new SensorReading();

        if (tick++ == 100000) {
          dh = 0.0001f * (float) (random.nextGaussian() - 0.01f * (humidity - 75));
          dt = 0.0001f * (float) (random.nextGaussian() - 0.01f * (temperature - 25));
          tick = 0;
        }

        humidity += dh;
        temperature += dt;
        reading.setHumidity(humidity);
        reading.setTemperature(temperature);
        return reading;
      }

      @Override
      public void remove() {
        throw new UnsupportedOperationException();
      }
    };
  }
}
  private void g() {
    EntityAgeable var1 = this.d.createChild((EntityAgeable) this.e);
    if (var1 != null) {
      EntityHuman var2 = this.d.cF();
      if (var2 == null && this.e.cF() != null) {
        var2 = this.e.cF();
      }

      if (var2 != null) {
        var2.b(StatisticList.A);
        if (this.d instanceof EntityCow) {
          var2.b((class_my) class_mt.H);
        }
      }

      this.d.b(6000);
      this.e.b(6000);
      this.d.cH();
      this.e.cH();
      var1.b(-24000);
      var1.setPositionRotation(this.d.locX, this.d.locY, this.d.locZ, 0.0F, 0.0F);
      this.a.addEntity((Entity) var1);
      Random var3 = this.d.getRandom();

      for (int var4 = 0; var4 < 7; ++var4) {
        double var5 = var3.nextGaussian() * 0.02D;
        double var7 = var3.nextGaussian() * 0.02D;
        double var9 = var3.nextGaussian() * 0.02D;
        double var11 = var3.nextDouble() * (double) this.d.width * 2.0D - (double) this.d.width;
        double var13 = 0.5D + var3.nextDouble() * (double) this.d.length;
        double var15 = var3.nextDouble() * (double) this.d.width * 2.0D - (double) this.d.width;
        this.a.addParticle(
            EnumParticle.HEART,
            this.d.locX + var11,
            this.d.locY + var13,
            this.d.locZ + var15,
            var5,
            var7,
            var9,
            new int[0]);
      }

      if (this.a.R().getBooleanValue("doMobLoot")) {
        this.a.addEntity(
            (Entity)
                (new EntityExperienceOrb(
                    this.a, this.d.locX, this.d.locY, this.d.locZ, var3.nextInt(7) + 1)));
      }
    }
  }
  @Override
  public void breakBlock(World par1World, int par2, int par3, int par4, Block par5, int par6) {
    TileEntity tile = par1World.getTileEntity(par2, par3, par4);
    if (!(tile instanceof TileSimpleInventory)) return;

    TileSimpleInventory inv = (TileSimpleInventory) tile;

    if (inv != null) {
      for (int j1 = 0; j1 < inv.getSizeInventory(); ++j1) {
        ItemStack itemstack = inv.getStackInSlot(j1);

        if (itemstack != null) {
          float f = random.nextFloat() * 0.8F + 0.1F;
          float f1 = random.nextFloat() * 0.8F + 0.1F;
          EntityItem entityitem;

          for (float f2 = random.nextFloat() * 0.8F + 0.1F;
              itemstack.stackSize > 0;
              par1World.spawnEntityInWorld(entityitem)) {
            int k1 = random.nextInt(21) + 10;

            if (k1 > itemstack.stackSize) k1 = itemstack.stackSize;

            itemstack.stackSize -= k1;
            entityitem =
                new EntityItem(
                    par1World,
                    par2 + f,
                    par3 + f1,
                    par4 + f2,
                    new ItemStack(itemstack.getItem(), k1, itemstack.getItemDamage()));
            float f3 = 0.05F;
            entityitem.motionX = (float) random.nextGaussian() * f3;
            entityitem.motionY = (float) random.nextGaussian() * f3 + 0.2F;
            entityitem.motionZ = (float) random.nextGaussian() * f3;

            if (itemstack.hasTagCompound())
              entityitem
                  .getEntityItem()
                  .setTagCompound((NBTTagCompound) itemstack.getTagCompound().copy());
          }
        }
      }

      par1World.func_147453_f(par2, par3, par4, par5);
    }

    super.breakBlock(par1World, par2, par3, par4, par5, par6);
  }
 public ItemStack func_82487_b(IBlockSource p_82487_1_, ItemStack p_82487_2_) {
   EnumFacing var3 = BlockDispenser.func_100009_j_(p_82487_1_.func_82620_h());
   IPosition var4 = BlockDispenser.func_82525_a(p_82487_1_);
   double var5 = var4.func_82615_a() + (double) ((float) var3.func_82601_c() * 0.3F);
   double var7 = var4.func_82617_b() + (double) ((float) var3.func_82601_c() * 0.3F);
   double var9 = var4.func_82616_c() + (double) ((float) var3.func_82599_e() * 0.3F);
   World var11 = p_82487_1_.func_82618_k();
   Random var12 = var11.field_73012_v;
   double var13 = var12.nextGaussian() * 0.05D + (double) var3.func_82601_c();
   double var15 = var12.nextGaussian() * 0.05D + (double) var3.func_96559_d();
   double var17 = var12.nextGaussian() * 0.05D + (double) var3.func_82599_e();
   var11.func_72838_d(new EntitySmallFireball(var11, var5, var7, var9, var13, var15, var17));
   p_82487_2_.func_77979_a(1);
   return p_82487_2_;
 }