Пример #1
0
int math_randomseed(lua_State *L){
	switch (lua_gettop(L)){
		case 0:{
			intgen.seed(ndrng());
			break;
		}
		case 1:{
			DWORD seed_value = luaL_checkint(L, 1);
			intgen.seed(seed_value);
			break;
		}
		default: return luaL_error(L, "math_randomseed: wrong number of arguments");
	}
	return 0;
}
Пример #2
0
int main(int argc, char **argv) {
    // Number of random expressions to test.
    const int count = 1000;
    // Depth of the randomly generated expression trees.
    const int depth = 5;
    // Number of samples to test the generated expressions for.
    const int samples = 3;

    // We want different fuzz tests every time, to increase coverage.
    // We also report the seed to enable reproducing failures.
    int fuzz_seed = argc > 1 ? atoi(argv[1]) : time(nullptr);
    rng.seed(fuzz_seed);
    std::cout << "Simplify fuzz test seed: " << fuzz_seed << std::endl;

    int max_fuzz_vector_width = 4;

    for (int i = 0; i < fuzz_type_count; i++) {
        Type T = fuzz_types[i];
        for (int w = 1; w < max_fuzz_vector_width; w *= 2) {
            Type VT = T.with_lanes(w);
            for (int n = 0; n < count; n++) {
                // Generate a random expr...
                Expr test = random_expr(VT, depth);
                if (!test_expression(test, samples)) {
                    return -1;
                }
            }
        }
    }
    std::cout << "Success!" << std::endl;
    return 0;
}
Пример #3
0
double getDummyLoopClock(size_t n, size_t bitLen)
{
	uint64_t ret = 0;
	Xbyak::util::Clock clk;
#ifdef USE_C11
	g_rg.seed(0);
	std::uniform_int_distribution<uint64_t> dist(0, (1ULL << bitLen) - 1);
#else
	XorShift128 r;
	const uint64_t mask = (1ULL << bitLen) - 1;
#endif
	const int lp = 5;
	for (int i = 0; i < lp; i++) {
		clk.begin();
		for (size_t i = 0; i < n; i++) {
#ifdef USE_C11
			uint64_t v = dist(g_rg);
#else
			uint64_t v = r.get64();
			v += r.get() >> 5;
			v &= mask;
#endif
			ret += v;
		}
		clk.end();
	}
	printf("(%llx)", (long long)ret);
	return clk.getClock() / double(n) / lp;
}
Пример #4
0
void init(dynamo::Simulation& Sim, const double density)
{
  RNG.seed(std::random_device()());
  Sim.ranGenerator.seed(std::random_device()());
  Sim.dynamics = dynamo::shared_ptr<dynamo::Dynamics>(new dynamo::DynGravity(&Sim, dynamo::Vector(0,-1,0)));
  Sim.BCs = dynamo::shared_ptr<dynamo::BoundaryCondition>(new dynamo::BCNone(&Sim));
  Sim.ptrScheduler = dynamo::shared_ptr<dynamo::SNeighbourList>(new dynamo::SNeighbourList(&Sim, new dynamo::FELCBT()));
  Sim.primaryCellSize = dynamo::Vector(52,52,52);

  Sim.addSpecies(dynamo::shared_ptr<dynamo::Species>(new dynamo::SpPoint(&Sim, new dynamo::IDRangeRange(0, 0), 1.0, "Bulk", 0)));
  Sim.addSpecies(dynamo::shared_ptr<dynamo::Species>(new dynamo::SpFixedCollider(&Sim, new dynamo::IDRangeRange(1, 8), "FixedColliders", 1)));

  Sim.interactions.push_back(dynamo::shared_ptr<dynamo::Interaction>(new dynamo::IHardSphere(&Sim, 1.0, 1, new dynamo::IDPairRangeAll(), "Bulk")));
  
  Sim.locals.push_back(dynamo::shared_ptr<dynamo::Local>(new dynamo::LWall(&Sim, 1.0, 1.0, dynamo::Vector(0,1,0), dynamo::Vector(0,-2.67753263802375e+01,0), "GroundPlate", new dynamo::IDRangeAll(&Sim))));
  
  Sim.particles.push_back(dynamo::Particle(dynamo::Vector(0, 4, 0), dynamo::Vector(0,0,0), Sim.particles.size()));
  Sim.particles.push_back(dynamo::Particle(dynamo::Vector(0.6, 1, 0), dynamo::Vector(0,0,0), Sim.particles.size()));
  Sim.particles.push_back(dynamo::Particle(dynamo::Vector(-1.51, 1, 0), dynamo::Vector(0,0,0), Sim.particles.size()));
  Sim.particles.push_back(dynamo::Particle(dynamo::Vector(-2.51, 1.5, 0), dynamo::Vector(0,0,0), Sim.particles.size()));
  Sim.particles.push_back(dynamo::Particle(dynamo::Vector(-3.51, 2, 0), dynamo::Vector(0,0,0), Sim.particles.size()));
  Sim.particles.push_back(dynamo::Particle(dynamo::Vector(-3.51, 3.5, 0), dynamo::Vector(0,0,0), Sim.particles.size()));
  Sim.particles.push_back(dynamo::Particle(dynamo::Vector(1.6, 2, 0), dynamo::Vector(0,0,0), Sim.particles.size()));
  Sim.particles.push_back(dynamo::Particle(dynamo::Vector(2, 3.5, 0), dynamo::Vector(0,0,0), Sim.particles.size()));
  Sim.particles.push_back(dynamo::Particle(dynamo::Vector(-0.75, 0.5, 0), dynamo::Vector(0,0,0), Sim.particles.size()));

  Sim.ensemble = dynamo::Ensemble::loadEnsemble(Sim);
}
Пример #5
0
void runTest()
{
  dynamo::Simulation Sim;

  RNG.seed(std::random_device()());
  Sim.ranGenerator.seed(std::random_device()());

  Sim.dynamics = dynamo::shared_ptr<dynamo::Dynamics>(new dynamo::DynNewtonian(&Sim));
  Sim.BCs = dynamo::shared_ptr<dynamo::BoundaryCondition>(new dynamo::BCPeriodic(&Sim));
  Sim.ptrScheduler = dynamo::shared_ptr<dynamo::Scheduler>(new Scheduler(&Sim, new Sorter()));
  Sim.primaryCellSize = dynamo::Vector(11,11,11);
  Sim.interactions.push_back(dynamo::shared_ptr<dynamo::Interaction>(new dynamo::IHardSphere(&Sim, 1.0, 1.0, new dynamo::IDPairRangeAll(), "Bulk")));
  Sim.addSpecies(dynamo::shared_ptr<dynamo::Species>(new dynamo::SpPoint(&Sim, new dynamo::IDRangeAll(&Sim), 1.0, "Bulk", 0)));

  Sim.particles.push_back(dynamo::Particle(dynamo::Vector{0.1,0,0}, dynamo::Vector{0,0,0}, Sim.particles.size()));
  Sim.particles.push_back(dynamo::Particle(dynamo::Vector{1.1,0,0}, dynamo::Vector{1,0,0}, Sim.particles.size()));
  Sim.particles.push_back(dynamo::Particle(dynamo::Vector{3.1,0,0}, dynamo::Vector{0,0,0}, Sim.particles.size()));
  Sim.particles.push_back(dynamo::Particle(dynamo::Vector{5.1,0,0}, dynamo::Vector{0,0,0}, Sim.particles.size()));
  Sim.particles.push_back(dynamo::Particle(dynamo::Vector{7.1,0,0}, dynamo::Vector{0,0,0}, Sim.particles.size()));
  Sim.particles.push_back(dynamo::Particle(dynamo::Vector{9.1,0,0}, dynamo::Vector{0,0,0}, Sim.particles.size()));

  Sim.ensemble = dynamo::Ensemble::loadEnsemble(Sim);
  Sim.endEventCount = 1000;
  Sim.addOutputPlugin("Misc");
  Sim.initialise();
  while (Sim.runSimulationStep()) {}  

  //Grab the output plugins
  dynamo::OPMisc& opMisc = *Sim.getOutputPlugin<dynamo::OPMisc>();

  //Check the mean free time is roughly what is expected
  double MFT = opMisc.getMFT();
  BOOST_CHECK_CLOSE(MFT, 3, 0.000001);
  BOOST_CHECK_MESSAGE(Sim.checkSystem() <= 1, "There are more than one invalid states in the final configuration");
}
Пример #6
0
int main(int argc, char *argv[]) {
  const int test_size = 4096 * 2;
  std::normal_distribution<float> dist(0.5f, 0.5f);
  rng.seed(0);
  float *r_values = nullptr;
  float *ret = nullptr;
  float *ret2 = nullptr;
  double sum = 0.0f;
  std::function<float()> rnd = std::bind(dist, rng);

  r_values = static_cast<float*>(_mm_malloc(sizeof(float) * test_size, 32));

  ret = static_cast<float*>(_mm_malloc(sizeof(float) * test_size, 32));
  ret2 = static_cast<float*>(_mm_malloc(sizeof(float) * test_size, 32));

  if (!(r_values && ret && ret2))
    goto exit;

  std::generate_n(r_values, test_size, rnd);
  for (int i = 0; i < 100000; ++i) {
    polynomial(ret, r_values, test_size);
    // polynomial(ret2, ret, test_size);
    sum = std::accumulate(ret, ret + test_size, sum);
  }
  std::cout << sum << std::endl;


exit:
  _mm_free(r_values);
  _mm_free(ret);
  _mm_free(ret2);
}
Пример #7
0
 /**
  * Create and seed the RNG
  */
 RandomGenerator() {
     std::random_device rd;
     std::mt19937::result_type random_data[std::mt19937::state_size];
     std::generate(std::begin(random_data), std::end(random_data), std::ref(rd));
     std::seed_seq seeds(std::begin(random_data), std::end(random_data));
     _mt.seed(seeds);
 }
Пример #8
0
INLINE void SeedRNG()
{
	if (!s_rngSeeded)
	{
		s_randomNumberGenerator.seed((unsigned long)getMSTime());
		s_rngSeeded = true;
	}
}
Пример #9
0
void init(v8::Local<v8::Object> target)
{
    gen.seed(static_cast<unsigned long>(
                 std::chrono::high_resolution_clock::now().time_since_epoch().count()));

    target->Set(Nan::New("rand").ToLocalChecked(),
                Nan::New<v8::FunctionTemplate>(rand)->GetFunction());
    target->Set(Nan::New("srand").ToLocalChecked(),
                Nan::New<v8::FunctionTemplate>(srand)->GetFunction());
}
Пример #10
0
float randfloat()
{
	if (!init_rand)
	{
		device.seed(time(0));
		init_rand = true;
	}
	
	return (float)distribution(device);
}
Пример #11
0
			void 
			initialize(
				uint32_t seed
				)
			{
				TRACE_MESSAGE(TRACE_LEVEL_VERBOSE, "+sola::component::random::initialize");

				SERIALIZE_CALL(std::recursive_mutex, __random_lock);

				std::srand((uint32_t) std::time(NULL));

				if(seed == GENERATE_RANDOM_SEED) {
					__random_generator.seed(rand());
				} else {
					__random_generator.seed(seed);
				}
				__random_initialized = true;

				TRACE_MESSAGE(TRACE_LEVEL_VERBOSE, "-sola::component::random::initialize");
			}
Пример #12
0
/**
 * Set the random seed used by the random functions (Random() and RandInt()).
 * The seed is casted to a 32-bit integer before being given to the random
 * number generator, but a size_t is taken as a parameter for API consistency.
 *
 * @param seed Seed for the random number generator.
 */
inline void RandomSeed(const size_t seed)
{
  randGen.seed((uint32_t) seed);
  srand((unsigned int) seed);
#if ARMA_VERSION_MAJOR > 3 || \
    (ARMA_VERSION_MAJOR == 3 && ARMA_VERSION_MINOR >= 930)
  // Armadillo >= 3.930 has its own random number generator internally that we
  // need to set the seed for also.
  arma::arma_rng::set_seed(seed);
#endif
}
Пример #13
0
int GameMain()
{
	s_rng.seed(1729);

	TestConstructors();
	TestMembers();
	TestNonMembers();
	TestOperators();

	Sleep(1000);
	return 0;
}
Пример #14
0
int randint(int min, int max)
{
	if (!init_rand)
	{
		device.seed(time(0));
		init_rand = true;
	}	
	
	if (min>max) return 0;
	std::uniform_int_distribution<int> uni(min, max);
	return uni(device);
}
Пример #15
0
int main(){
    const int seed=3,n=100;
    const double tol=std::numeric_limits<float>::min();
    std::mt19937 mt;
    mt.seed(seed);
    float x[n];
    for (int i=0; i<n; i++) x[i]=moare_random(9)*1.0f;
    int j=0;
    for(int i=0;i<n;i++)    j+=abs(x[i])<tol;
    std::cout<< j << std::endl;
    return 0;
}
Пример #16
0
void init(dynamo::Simulation& Sim, const double density)
{
  RNG.seed(std::random_device()());
  Sim.ranGenerator.seed(std::random_device()());

  const double elasticity = 1.0;
  const size_t cells = 7;
  const double wallkT = 1.0;

  std::unique_ptr<dynamo::UCell> packptr(new dynamo::CUFCC(std::array<long, 3>{{cells, cells, cells}}, dynamo::Vector(1,1,1), new dynamo::UParticle()));
  packptr->initialise();
  std::vector<dynamo::Vector> latticeSites(packptr->placeObjects(dynamo::Vector(0,0,0)));
  const size_t N = latticeSites.size();
  const double boxL = std::cbrt(N / density);
  Sim.primaryCellSize = dynamo::Vector(boxL, boxL, boxL);

  dynamo::shared_ptr<dynamo::ParticleProperty> D(new dynamo::ParticleProperty(N, dynamo::Property::Units::Length(), "D", 1.0));
  dynamo::shared_ptr<dynamo::ParticleProperty> M(new dynamo::ParticleProperty(N, dynamo::Property::Units::Mass(), "M", 1.0));
  Sim._properties.push(D);
  Sim._properties.push(M);

  Sim.dynamics = dynamo::shared_ptr<dynamo::Dynamics>(new dynamo::DynGravity(&Sim, dynamo::Vector(0, -1, 0)));
  Sim.BCs = dynamo::shared_ptr<dynamo::BoundaryCondition>(new dynamo::BCNone(&Sim));
  Sim.ptrScheduler = dynamo::shared_ptr<dynamo::SNeighbourList>(new dynamo::SNeighbourList(&Sim, new dynamo::FELBoundedPQ<dynamo::PELMinMax<3> >()));

  Sim.interactions.push_back(dynamo::shared_ptr<dynamo::Interaction>(new dynamo::IHardSphere(&Sim, "D", elasticity, new dynamo::IDPairRangeAll(), "Bulk")));
  Sim.addSpecies(dynamo::shared_ptr<dynamo::Species>(new dynamo::SpPoint(&Sim, new dynamo::IDRangeAll(&Sim), "M", "Bulk", 0)));

  Sim.locals.push_back(dynamo::shared_ptr<dynamo::Local>(new dynamo::LWall(&Sim, elasticity, "D", dynamo::Vector(1, 0, 0), dynamo::Vector(-0.5 * Sim.primaryCellSize[0] - 1, 0, 0), "XwallLow", new dynamo::IDRangeAll(&Sim))));
  Sim.locals.push_back(dynamo::shared_ptr<dynamo::Local>(new dynamo::LWall(&Sim, elasticity, "D", dynamo::Vector(-1, 0, 0), dynamo::Vector(0.5 * Sim.primaryCellSize[0] + 1, 0, 0), "XwallHigh", new dynamo::IDRangeAll(&Sim))));

  Sim.locals.push_back(dynamo::shared_ptr<dynamo::Local>(new dynamo::LWall(&Sim, elasticity, "D", dynamo::Vector(0, 0, 1), dynamo::Vector(0, 0, -0.5 * Sim.primaryCellSize[2] - 1), "ZwallLow", new dynamo::IDRangeAll(&Sim))));
  Sim.locals.push_back(dynamo::shared_ptr<dynamo::Local>(new dynamo::LWall(&Sim, elasticity, "D", dynamo::Vector(0, 0, -1), dynamo::Vector(0, 0, 0.5 * Sim.primaryCellSize[2] + 1), "ZwallHigh", new dynamo::IDRangeAll(&Sim))));

  Sim.locals.push_back(dynamo::shared_ptr<dynamo::Local>(new dynamo::LWall(&Sim, elasticity, "D", dynamo::Vector(0, 1, 0), dynamo::Vector(0, - 0.5 * Sim.primaryCellSize[1] - 1, 0), "GroundPlate", new dynamo::IDRangeAll(&Sim), wallkT)));
  
  for (size_t i(0); i < latticeSites.size(); ++i)
    {
      Sim.particles.push_back(dynamo::Particle(boxL * latticeSites[i], getRandVelVec(), Sim.particles.size()));
      D->getProperty(i) = (i < 100) ? 1 : 0.5;
      M->getProperty(i) = (i < 100) ? 1 : 0.5 * 0.5 * 0.5;
    }

  Sim.ensemble = dynamo::Ensemble::loadEnsemble(Sim);

  dynamo::InputPlugin(&Sim, "Rescaler").zeroMomentum();
  dynamo::InputPlugin(&Sim, "Rescaler").rescaleVels(1.0);

  BOOST_CHECK_EQUAL(Sim.N(), 1372);
  BOOST_CHECK_CLOSE(Sim.getNumberDensity() * Sim.units.unitVolume(), density, 0.000000001);
}
Пример #17
0
void init(dynamo::Simulation& Sim, const double density)
{
  RNG.seed(std::random_device()());
  Sim.ranGenerator.seed(std::random_device()());

  Sim.dynamics = dynamo::shared_ptr<dynamo::Dynamics>(new dynamo::DynNewtonian(&Sim));
  Sim.BCs = dynamo::shared_ptr<dynamo::BoundaryCondition>(new dynamo::BCPeriodic(&Sim));
  Sim.ptrScheduler = dynamo::shared_ptr<dynamo::SNeighbourList>(new dynamo::SNeighbourList(&Sim, new DefaultSorter()));

  std::unique_ptr<dynamo::UCell> packptr(new dynamo::CUSC(std::array<long, 3>{{128, 128, 1}}, dynamo::Vector{1,1,1}, new dynamo::UParticle()));
  packptr->initialise();
  std::vector<dynamo::Vector> latticeSites(packptr->placeObjects(dynamo::Vector{0,0,0}));
  
  //As we're in 2D we need to take the square root
  double particleDiam = std::sqrt(density / latticeSites.size());
  Sim.units.setUnitLength(particleDiam);
  Sim.units.setUnitTime(particleDiam); 

  Sim.primaryCellSize = dynamo::Vector{1, 1, 4 * particleDiam};
  
  typedef std::pair<double,double> Step;
  std::vector<Step> steps;
  steps.push_back(Step{1.0,0.1});
  steps.push_back(Step{0.9,0.2});
  steps.push_back(Step{0.8,0.3});
  steps.push_back(Step{0.7,0.4});
  steps.push_back(Step{0.6,0.5});
  steps.push_back(Step{0.5,0.6});
  steps.push_back(Step{0.4,0.7});
  steps.push_back(Step{0.3,0.8});
  steps.push_back(Step{0.2,0.9});
  steps.push_back(Step{0.1,1.0});
  Sim.interactions.push_back(dynamo::shared_ptr<dynamo::Interaction>(new dynamo::IStepped(&Sim, dynamo::shared_ptr<dynamo::Potential>(new dynamo::PotentialStepped(steps, false)), new dynamo::IDPairRangeAll(), "Bulk", particleDiam, 1.0)));
    
  Sim.addSpecies(dynamo::shared_ptr<dynamo::Species>(new dynamo::SpPoint(&Sim, new dynamo::IDRangeAll(&Sim), 1.0, "Bulk", 0)));

  unsigned long nParticles = 0;
  Sim.particles.reserve(latticeSites.size());
  for (const dynamo::Vector & position : latticeSites)
    Sim.particles.push_back(dynamo::Particle(position, getRandVelVec() * Sim.units.unitVelocity(), nParticles++));

  for (auto& particle : Sim.particles)
    particle.getVelocity()[2] = 0;

  dynamo::InputPlugin(&Sim, "Rescaler").zeroMomentum();
  dynamo::InputPlugin(&Sim, "Rescaler").rescaleVels(2.0 / 3.0);
    
  Sim.ensemble = dynamo::Ensemble::loadEnsemble(Sim);

  BOOST_CHECK_EQUAL(Sim.N(), 128 * 128);
}
Пример #18
0
void init(dynamo::Simulation& Sim, const double density)
{
  RNG.seed(std::random_device()());
  Sim.ranGenerator.seed(std::random_device()());

  double massFrac = 0.001, sizeRatio = 0.5;
  size_t Na=100;
  
  Sim.dynamics = dynamo::shared_ptr<dynamo::Dynamics>(new dynamo::DynNewtonian(&Sim));
  Sim.BCs = dynamo::shared_ptr<dynamo::BoundaryCondition>(new dynamo::BCPeriodic(&Sim));
  Sim.ptrScheduler = dynamo::shared_ptr<dynamo::SNeighbourList>(new dynamo::SNeighbourList(&Sim, new DefaultSorter()));

  std::unique_ptr<dynamo::UCell> packptr(new dynamo::CUFCC(std::array<long, 3>{{10, 10, 10}}, dynamo::Vector(1, 1, 1), new dynamo::UParticle()));
  packptr->initialise();
  std::vector<dynamo::Vector> latticeSites(packptr->placeObjects(dynamo::Vector(0,0,0)));
  Sim.primaryCellSize = dynamo::Vector(1,1,1);

  double simVol = 1.0;
  for (size_t iDim = 0; iDim < NDIM; ++iDim)
    simVol *= Sim.primaryCellSize[iDim];

  double particleDiam = std::cbrt(simVol * density / latticeSites.size());
  
  Sim.interactions.push_back(dynamo::shared_ptr<dynamo::Interaction>(new dynamo::IHardSphere(&Sim, particleDiam, new dynamo::IDPairRangeSingle(new dynamo::IDRangeRange(0, Na - 1)), "AAInt")));
  
  Sim.interactions.push_back(dynamo::shared_ptr<dynamo::Interaction>(new dynamo::IHardSphere(&Sim, ((1.0 + sizeRatio) / 2.0) * particleDiam, new dynamo::IDPairRangePair(new dynamo::IDRangeRange(0, Na - 1), new dynamo::IDRangeRange(Na, latticeSites.size() - 1)), "ABInt")));

  Sim.interactions.push_back(dynamo::shared_ptr<dynamo::Interaction>(new dynamo::IHardSphere(&Sim, sizeRatio * particleDiam, new dynamo::IDPairRangeAll(), "BBInt")));

  Sim.addSpecies(dynamo::shared_ptr<dynamo::Species>(new dynamo::SpPoint(&Sim, new dynamo::IDRangeRange(0, Na - 1), 1.0, "A", 0)));

  Sim.addSpecies(dynamo::shared_ptr<dynamo::Species>(new dynamo::SpPoint(&Sim, new dynamo::IDRangeRange(Na, latticeSites.size() - 1), massFrac, "B", 0)));

  Sim.units.setUnitLength(particleDiam);

  unsigned long nParticles = 0;
  Sim.particles.reserve(latticeSites.size());

  for (const dynamo::Vector & position : latticeSites)
    Sim.particles.push_back(dynamo::Particle(position, getRandVelVec() * Sim.units.unitVelocity(), nParticles++));

  Sim.ensemble = dynamo::Ensemble::loadEnsemble(Sim);

  dynamo::InputPlugin(&Sim, "Rescaler").zeroMomentum();
  dynamo::InputPlugin(&Sim, "Rescaler").rescaleVels(1.0);

  BOOST_CHECK_EQUAL(Sim.N(), 4000);
  //BOOST_CHECK_CLOSE(Sim.getNumberDensity() * Sim.units.unitVolume(), density, 0.000000001);
  //BOOST_CHECK_CLOSE(Sim.getPackingFraction(), Sim.getNumberDensity() * Sim.units.unitVolume() * M_PI / 6.0, 0.000000001);
}
Пример #19
0
int main(int argc, char** argv) {
  rng.seed();
  CALL(TEST_HashFunctions);
  CALL(overview::TEST_Construction);
  CALL(overview::TEST_Retreival);
  CALL(overview::TEST_Resizing);
  CALL(separate_chaining::TEST_Construction);
  CALL(separate_chaining::TEST_Retreival);
  CALL(open_addressing::TEST_Construction);
  CALL(open_addressing::TEST_Retreival);
  CALL(cuckoo::TEST_CuckooHashing);
  CALL(TEST_MostCommon);
  CALL(TEST_Cache);
  return 0;
}
Пример #20
0
// -------------------------------------------------------------------------
int hpx_main(boost::program_options::variables_map& vm)
{
    std::size_t device     = vm["device"].as<std::size_t>();
    std::size_t sizeMult   = vm["sizemult"].as<std::size_t>();
    std::size_t iterations = vm["iterations"].as<std::size_t>();
    //
    unsigned int seed = std::random_device{}();
     if (vm.count("seed"))
        seed = vm["seed"].as<unsigned int>();

    gen.seed(seed);
    std::cout << "using seed: " << seed << std::endl;

    //
    sizeMult = (std::min)(sizeMult, std::size_t(100));
    sizeMult = (std::max)(sizeMult, std::size_t(1));
    //
    // use a larger block size for Fermi and above, query default cuda target properties
    hpx::compute::cuda::target target(device);

    std::cout
        << "GPU Device " << target.native_handle().get_device()
        << ": \"" << target.native_handle().processor_name() << "\" "
        << "with compute capability " << target.native_handle().processor_family()
        << "\n";

    int block_size = (target.native_handle().processor_family() < 2) ? 16 : 32;

    sMatrixSize matrix_size;
    matrix_size.uiWA = 2 * block_size * sizeMult;
    matrix_size.uiHA = 4 * block_size * sizeMult;
    matrix_size.uiWB = 2 * block_size * sizeMult;
    matrix_size.uiHB = 4 * block_size * sizeMult;
    matrix_size.uiWC = 2 * block_size * sizeMult;
    matrix_size.uiHC = 4 * block_size * sizeMult;

    printf("MatrixA(%u,%u), MatrixB(%u,%u), MatrixC(%u,%u)\n\n",
           matrix_size.uiWA, matrix_size.uiHA,
           matrix_size.uiWB, matrix_size.uiHB,
           matrix_size.uiWC, matrix_size.uiHC);

    matrixMultiply<float>(matrix_size, device, iterations);
    return hpx::finalize();
}
Пример #21
0
void init(dynamo::Simulation& Sim, double density = 0.5)
{
  RNG.seed(std::random_device()());
  Sim.ranGenerator.seed(std::random_device()());

  const double elasticity = 1.0;
  const double lambda = 1.5;
  const double welldepth = 1.0;

  Sim.dynamics = dynamo::shared_ptr<dynamo::Dynamics>(new dynamo::DynNewtonian(&Sim));
  Sim.BCs = dynamo::shared_ptr<dynamo::BoundaryCondition>(new dynamo::BCPeriodic(&Sim));
  Sim.ptrScheduler = dynamo::shared_ptr<dynamo::SNeighbourList>(new dynamo::SNeighbourList(&Sim, new DefaultSorter()));

  std::unique_ptr<dynamo::UCell> packptr(new dynamo::CUFCC(std::array<long, 3>{{7,7,7}}, dynamo::Vector(1,1,1), new dynamo::UParticle()));
  packptr->initialise();
  std::vector<dynamo::Vector> latticeSites(packptr->placeObjects(dynamo::Vector(0,0,0)));
  Sim.primaryCellSize = dynamo::Vector(1,1,1);

  double simVol = 1.0;
  for (size_t iDim = 0; iDim < NDIM; ++iDim)
    simVol *= Sim.primaryCellSize[iDim];

  double particleDiam = std::cbrt(simVol * density / latticeSites.size());

  Sim.interactions.push_back(dynamo::shared_ptr<dynamo::Interaction>(new dynamo::ISquareWell(&Sim, particleDiam, lambda, welldepth, elasticity, new dynamo::IDPairRangeAll(), "Bulk")));
  Sim.addSpecies(dynamo::shared_ptr<dynamo::Species>(new dynamo::SpPoint(&Sim, new dynamo::IDRangeAll(&Sim), 1.0, "Bulk", 0)));
  Sim.units.setUnitLength(particleDiam);
  Sim.units.setUnitTime(particleDiam); 

  unsigned long nParticles = 0;
  Sim.particles.reserve(latticeSites.size());
  for (const dynamo::Vector & position : latticeSites)
    Sim.particles.push_back(dynamo::Particle(position, getRandVelVec() * Sim.units.unitVelocity(), nParticles++));

  Sim.ensemble = dynamo::Ensemble::loadEnsemble(Sim);

  dynamo::InputPlugin(&Sim, "Rescaler").zeroMomentum();
  dynamo::InputPlugin(&Sim, "Rescaler").rescaleVels(1.0);

  BOOST_CHECK_EQUAL(Sim.N(), 1372);
  BOOST_CHECK_CLOSE(Sim.getNumberDensity() * Sim.units.unitVolume(), density, 0.000000001);
  BOOST_CHECK_CLOSE(Sim.getPackingFraction(), Sim.getNumberDensity() * Sim.units.unitVolume() * M_PI / 6.0, 0.000000001);
}
Пример #22
0
Random::Random(UInt64 seed) {
  if (seed == 0) {
    if( !static_gen_seeded ) {
      #if NDEBUG
        unsigned int static_seed = (unsigned int)std::chrono::system_clock::now().time_since_epoch().count();
      #else
        unsigned int static_seed = DEBUG_RANDOM_SEED;
      #endif
      static_gen.seed( static_seed );
      static_gen_seeded = true;
      NTA_INFO << "Random seed: " << static_seed;
    }
    seed_ = static_gen(); //generate random value from HW RNG
  } else {
    seed_ = seed;
  }
  // if seed is zero at this point, there is a logic error.
  NTA_CHECK(seed_ != 0);
  gen.seed((unsigned int)seed_); //seed the generator
  steps_ = 0;
}
Пример #23
0
    void use_graph_generator(const vle::devs::InitEventList& events)
    {
        model_number = events.getInt("model-number");
        std::string generator_name = events.getString("graph-generator");

        if (events.exist("graph-seed"))
            generator.seed(events.getInt("graph-seed"));

        if (generator_name == "defined")
            use_defined_graph_generator(events);
        else if (generator_name == "small-world")
            use_smallworld_graph_generator(events);
        else if (generator_name == "scale-free")
            use_scalefree_graph_generator(events);
        else if (generator_name == "sorted-erdos-renyi")
            use_sortederdesrenyi_graph_generator(events);
        else if (generator_name == "erdos_renyi")
            use_erdosrenyi_graph_generator(events);
        else
            throw vle::utils::ModellingError("Unknown graph gererator: %s",
                                             generator_name.c_str());
    }
Пример #24
0
void init(dynamo::Simulation& Sim, const double density)
{
  RNG.seed(std::random_device()());
  Sim.ranGenerator.seed(std::random_device()());

  const double elasticity = 1.0;
  const size_t N = 1000;
  Sim.dynamics = dynamo::shared_ptr<dynamo::Dynamics>(new dynamo::DynNewtonian(&Sim));
  Sim.BCs = dynamo::shared_ptr<dynamo::BoundaryCondition>(new dynamo::BCPeriodic(&Sim));
  Sim.ptrScheduler = dynamo::shared_ptr<dynamo::SNeighbourList>(new dynamo::SNeighbourList(&Sim, new DefaultSorter()));
  
  dynamo::CURandom packroutine(N, dynamo::Vector{1,1,1}, new dynamo::UParticle());
  packroutine.initialise();
  std::vector<dynamo::Vector> latticeSites(packroutine.placeObjects(dynamo::Vector{0,0,0}));
  Sim.BCs = dynamo::shared_ptr<dynamo::BoundaryCondition>(new dynamo::BCPeriodic(&Sim));
  double particleDiam = std::cbrt(density / N);
  Sim.interactions.push_back(dynamo::shared_ptr<dynamo::Interaction>(new dynamo::ILines(&Sim, particleDiam, elasticity, new dynamo::IDPairRangeAll(), "Bulk")));
  Sim.addSpecies(dynamo::shared_ptr<dynamo::Species>(new dynamo::SpSphericalTop(&Sim, new dynamo::IDRangeAll(&Sim), 1.0, "Bulk", 0, particleDiam * particleDiam / 12.0)));
  Sim.units.setUnitLength(particleDiam);

  unsigned long nParticles = 0;
  Sim.particles.reserve(latticeSites.size());
  for (const dynamo::Vector & position : latticeSites)
    Sim.particles.push_back(dynamo::Particle(position, getRandVelVec() * Sim.units.unitVelocity(), nParticles++));

  Sim.dynamics->initOrientations();

  Sim.ensemble = dynamo::Ensemble::loadEnsemble(Sim);

  dynamo::InputPlugin(&Sim, "Rescaler").zeroMomentum();
  dynamo::InputPlugin(&Sim, "Rescaler").rescaleVels(1.0);

  BOOST_CHECK_EQUAL(Sim.N(), N);
  BOOST_CHECK_CLOSE(Sim.getNumberDensity() * Sim.units.unitVolume(), density, 0.000000001);
  BOOST_CHECK_CLOSE(Sim.getPackingFraction(), 0, 0.000000001);
}
Пример #25
0
	void init() {
		r.seed((unsigned)std::chrono::system_clock::now().time_since_epoch().count());
	}
Пример #26
0
int main(int argc, char * argv[])
{
	for(int i = 0; i <14; i++)
	{
		cout << " " << endl;
	}
	cout << "Welcome, my friend to the simplistic game of Trinity's Nightmare. Here, you have" << endl <<
		"reached a dungeon where you are alone, standing with only your car keys and a trash" << endl <<
		"can lid that you found. This is also where the level where the real danger begins." << endl <<
		"You have conquered the attic of man eating camels -- You have trudged through" << endl <<
		"the muddy swamps of Dr. Heinz'science experiment of alligator-dogs, only to" << endl <<
		"come face to face with the most recent obstacle of the fire-breathing" << endl <<
		"coffee-ingesting cookie-stealing SQUIRRELS!! Now, hold on to your" << endl <<
		"Mountain Dew and Pizza, buckle up into your basement chair, and" << endl << 
		"change your profile picture to that of a face of fear, because" << endl <<
		"here you go..." << endl;

	cout << "To Play: " << endl;
	cout << "Unless otherwise declaried, you will show up as @" << endl;
	cout << "1.) Movement:" << endl;
	cout << "     a - moves the player left" << endl;
	cout << "     s - moves the player down" << endl;
	cout << "     d - moves the player right" << endl;
	cout << "     w - moves the player up" << endl;
	cout << "     EXTRA: DIAGONAL:"<< endl;
	cout << "         e - up to the right" << endl;
	cout << "         x - down to the right" << endl;
	cout << "         z - down to the left" << endl;
	cout << "         ` - up to the right" << endl << endl;

	cout << "2.) Picking up and Using Items:" << endl;
	cout << "     p - pick up, and thus using" << endl;

	cout << "3.) Attack:" << endl;
	cout << "     - Creatures will attack you if you are within one space of them." << endl;
	cout << "     - Weapons and Experience increase your attacking." << endl << endl;

	cout << "q will allow you to Quit -- if you are a Quitter..." << endl << endl << endl;

	mt.seed(time(NULL));
	cout << "This is command line" << endl;
	cout << "Arguments Given : " << argc << endl;

//load file into variable
	string inFileName; 
	string outFileName;
	ifstream input;
        int inputValue = 0;
	if (argc >= 3)
	{
		inFileName = argv[1];
		outFileName = argv[2];

	}
	else
	{
		cout << "Enter a file name with .xml exstension: ";
		cin >> inFileName;
		cout << endl;
		cout << "What do you want to name the output file? " ;
		cin >> outFileName;
		cout << endl;
	}
	
	if (argc >= 4)
	{
        inputValue = atoi(argv[3]);
	}
    else
    {
        cout << "How many random Dungeons do you you want generated? " ;
        cin >> inputValue;
        cout << endl;
    }

	if(!input.good())
	{
		cout << "No file by that name. Try Again. " << endl;
		return 1;
	}

	input.open(inFileName.c_str());
//make vector using XMLSerializable pointer
	vector<XMLSerializable*> vWorld;
//send variables to parseXML
	parseXML(input, vWorld);
    //dumpOntoConsole(vWorld);

//make output file
	ofstream output;
   
    bool creatureOccupied;
    bool wallOccupied;

    int tempX = 0;
    int tempY = 0;

    int thingTempX = 0;
    int thingTempY = 0;

    int playerX = 0;
    int playerY = 0;

    Player * pPlayer = new Player();
    Weapon * punch = new Weapon();
    Weapon * keys = new Weapon();
    Armor * TrashCanLid = new Armor();


    keys->setDamage(5);
    keys->setAccuracy(2);
    keys->setWeaponType("keychain");
    keys->setName("Car Keys");
    keys->setDisplayChar('x');

    pPlayer->setWeapon(punch);
    
    punch->setDamage(5);
    punch->setAccuracy(5);
    punch->setWeaponType("flesh");

    TrashCanLid->setArmorValue(3);
    TrashCanLid->setArmorType("trashlid");
    TrashCanLid->setName("Trash Can Lid");
    TrashCanLid->setDisplayChar('t');

    pPlayer->setInventory(TrashCanLid);
    pPlayer->setInventory(keys);

    pPlayer->setExperience(0);

    string sMove;
    int dNum = 0; 
    int iNum = 0;
    vector<DungeonLevel*> vDL;
    vector<vector<Creature*>> vvCreatures;
    vector<vector<vector<Item*>>> vvvItems;
    bool nextFloor = true;
    bool sameFloor = false;
    bool prevFloor = false;
    bool creatureTurn;

    int monsterHP = 0;
    int HP = 0;
    int attack = 0;
    int moveCount = 0;
    bool bWeapon = true;

    initscr();
	noecho();

    while(true)
    {   
		clear();
        if( nextFloor == true )
        {
            nextFloor = false;
            if( sameFloor == false )
            {
                vDL.push_back(new DungeonLevel(79,20));
            }
            playerX = vDL[dNum]->upstairXCoord();
            playerY = vDL[dNum]->upstairYCoord();
            vvvItems.resize(dNum+1);
            vvvItems[dNum].resize(5);
            vvCreatures.resize(dNum+1);
            if( sameFloor == false )
            {
                for(int i = 0 ; i<5; i++)
                {
                    //Creature * pCreature = CreatureFactory::instance().generateCreature(4);
                    vvCreatures[dNum].push_back(CreatureFactory::instance().generateCreature((vDL.size())*2));
                    
                    while(true)
                    {
                        thingTempX = mt() % 79;
                        thingTempY = mt() % 20;
                        wallOccupied = vDL[dNum]->checkMove(thingTempX, thingTempY);
                        if( wallOccupied == true )
                        {
                            vDL[dNum]->setCreature(vvCreatures[dNum][i], thingTempX, thingTempY);
                            vvCreatures[dNum][i]->setCoords(thingTempX, thingTempY);
                            break;
                        }
                    }
                    
                    iNum =( (mt() % 5) + 1 );
                    for( size_t j = 0 ; j < iNum ; j++ )
                    {
                        vvvItems[dNum][i].push_back(ItemFactory::instance().generateItem(vDL.size()*20));
                    }

                    while(true)
                    {
                        thingTempX = mt() % 79;
                        thingTempY = mt() % 20;
                        wallOccupied = vDL[dNum]->checkMove( thingTempX, thingTempY );
                        if( wallOccupied == true )
                        {
                            for( size_t j = 0 ; j < iNum ; j++ )
                            {
                                vDL[dNum]->setItems(vvvItems[dNum][i][j], thingTempX,thingTempY);
                                vvvItems[dNum][i][j]->setCoords(thingTempX, thingTempY);
                            }
                            break;
                        }
                    }
                    /*if( pCreature )
                    {
                        pCreature->dumpObject();
                        delete pCreature;
                    }*/
                }
            }
        }
        else if( prevFloor == true )
        {
            if( dNum < 0 )
            {
                break;
                //cout << "You Escaped... because you ran away like a pansy. Good Job." << endl;
				clear();
				mvprintw(0,0,"You Escaped... because you ran away like a pansy. Good Job. ");
				refresh();
            }
            prevFloor = false;
            playerX = vDL[dNum]->downstairXCoord();
            playerY = vDL[dNum]->downstairYCoord();
        }
        //dl.display();
        //continue;
        //cout << endl << "Final State: " << endl << endl;
        tempX = playerX;
        tempY = playerY;
        vDL[dNum]->setCreature(pPlayer, playerX, playerY);
        while(true)
        {
            if( moveCount % 10 == 0 )
            {
				if(pPlayer->getName() =="God")
				{
					pPlayer->setHP(1000000000);
				}
                else 
				{
					if( pPlayer->getHP() < 97 )
					{
						pPlayer->setHP( pPlayer->getHP() + 3 );
					}
				}
            }
            if( moveCount == 20 )
            {
                vvCreatures[dNum].push_back(CreatureFactory::instance().generateCreature((vDL.size())*2));
                
                while(true)
                {
                    thingTempX = mt() % 79;
                    thingTempY = mt() % 20;
                    wallOccupied = vDL[dNum]->checkMove(thingTempX, thingTempY);
                    if( wallOccupied == true )
                    {
                        vDL[dNum]->setCreature(vvCreatures[dNum][vvCreatures.size()-1], thingTempX, thingTempY);
                        vvCreatures[dNum][vvCreatures.size()-1]->setCoords(thingTempX, thingTempY);
                        break;
                    }
                }
            }
            do
            {
                for( size_t y = 0; y < 20 ; y++ )
                {
                    for( size_t x = 0; x < 79 ; x++ )
                    {
                        move(y,x);
                        addch(vDL[dNum]->display(x,y));
                    }
					refresh();
                    //cout << endl;
                }
				sMove = getch();
				move(23,0);
                clrtoeol();
				move(24,0);
				clrtoeol();
				move(25,0);
				clrtoeol();
				move(26,0);
				clrtoeol();
				move(21,0);
				clrtoeol();
				
                //vDL[dNum]->display();
                //refresh();
				mvprintw(30,0,"Got it. Next? ");
                //cout <<  endl <<"Got it, " << pPlayer->getName() << " What Next? ";
				//getnstr(sMove, sizeof( users_name ) - 1 );
				
                //cin >> sMove;
                //cout << endl;
                if( sMove == "w" )
                {
					//up
                    tempY--;
                    break;
                }
                else if( sMove == "s" )
                {
					//down
                    tempY++;
                    break;
                }
                else if( sMove == "a" )
                {
					//left
                    tempX--;
                    break;
                }   
                else if( sMove == "d" )
                {
					//right
                    tempX++;
                    break;
                }
				else if( sMove == "e" )
                {
					//up to the right
					tempX++;
					tempY--;
					break;
                }
				else if( sMove == "x" )
                {
					//down to the right
					tempX++;
					tempY++;
                    break;
				}
				else if( sMove == "z" )
                {
					//down to the left
        	        tempX--;
					tempY++;
                    break;
                }
				else if( sMove == "`" )
                {
					//up to the left
					tempX--;
					tempY--;
                    break;
                }
                else if( sMove == "q" )
                {
					clear();
					mvprintw(0,0,"Really!? You just quit. Good going.");
                    break;
                }
                else if( sMove == ">" )
                {
                    if( playerX == vDL[dNum]->downstairXCoord() && playerY == vDL[dNum]->downstairYCoord() )
                    {
						clear();
                        nextFloor = true;
                        break;
                    }   
                    pPlayer->setExperience(pPlayer->getExperience() + 5 * vDL.size());
                }
                else if( sMove == "<" )
                {
                    if( playerX == vDL[dNum]->upstairXCoord() && playerY == vDL[dNum]->upstairYCoord() )
                    {
                        prevFloor = true;
                        break;
                    }   
                }
                else if( sMove == "p" )
                {
                    if( vDL[dNum]->checkItem(playerX, playerY) )
                    {
                        vDL[dNum]->pickUpItem(playerX, playerY);
                        if(pPlayer->getDropItem() != NULL)
                        {
                            vDL[dNum]->setItems(pPlayer->getDropItem(), playerX, playerY);
                        }
                        break;
                    }
                }
                else if( sMove == "l" )
                {
                    pPlayer->setDropItem();
                    if( pPlayer->getDropItem() != NULL )
                    {
                        vDL[dNum]->setItems(pPlayer->getDropItem(), playerX, playerY);
                    }
                }
                else if( sMove == "u" )
                {
                    pPlayer->getInventory();
                }
                else
                {
                    //cout << endl << "What!? I try that again. I have no idea what you are trying to do." << endl;
					mvprintw(21,0,"What!? I try that again. I have no idea what you are trying to do.");
                }
				mvprintw(50,0,"Got it, What Next? ");
				refresh();
				
            }while( sMove != "q" );
            if( sMove == "q" )
            {
                //cout << endl << "Really!? You just quit. Good going." << endl;
                break;
            }


            /////////////////////////////////////PLAYER MOVEMENT AND ATTACK///////////////////////////////////////////


            for( size_t i = 0 ; i < vvCreatures[dNum].size() ; i++ )
            {
                if( vvCreatures[dNum][i]->getCoordX() == tempX && vvCreatures[dNum][i]->getCoordY() == tempY )
                {
                    //cout << "creature occupied set to true" << endl;
                    creatureOccupied = true;
                    break;
                }
            }
            wallOccupied = vDL[dNum]->DungeonLevel::checkMove(tempX,tempY);
            if(wallOccupied == true && creatureOccupied == false && ( tempX <! 0 || tempX >! 79 || tempY <! 0 || tempY >! 20 ))
            {
                vDL[dNum]->removeCreature(playerX, playerY);
                playerX = tempX;
                playerY = tempY;
                vDL[dNum]->setCreature(pPlayer, playerX, playerY);
                creatureTurn = true;
            }
            else if( wallOccupied == true && creatureOccupied == true )
            {
                if( bWeapon == false )
                {
                    attack = mt() % (pPlayer->getWeapon())->getDamage();
                }
                else
                {
                    attack = mt() % (punch->getDamage());
                }
                HP = (vDL[dNum]->getCreature(tempX,tempY))->getHP();
                //cout << endl << "Creature's HP before: " << HP << endl;
				mvprintw(24,0,"Creature's HP before: %i", HP);
				refresh();
                (vDL[dNum]->getCreature(tempX,tempY))->setHP(HP - attack);
                //cout << endl << pPlayer->getName() << " attacked " << (vDL[dNum]->getCreature(tempX, tempY))->getName() << " for " << attack << " damage " << endl;
                if( HP - attack <= 0 )
                {
                    for( int i = 0 ; i < vvCreatures[dNum].size() ; i++ )
                    {
                        if( vvCreatures[dNum][i]->getCoordX() == tempX && vvCreatures[dNum][i]->getCoordY() == tempY )
                        {
                            vDL[dNum]->removeCreature( vvCreatures[dNum][i]->getCoordX(), vvCreatures[dNum][i]->getCoordY() );
                            //cout << pPlayer->getName() << " killed " << vvCreatures[dNum][i]->getName() << "!" << endl;
							mvprintw(27,0,"%s killed the creature!",pPlayer->getName().c_str());
                            delete vvCreatures[dNum][i];
                            vvCreatures[dNum].erase(vvCreatures[dNum].begin() + i);
                            break;
                        }
                    }
                    pPlayer->setExperience(pPlayer->getExperience() + vDL.size() * 5);
                }
                else
                {
                    HP = (vDL[dNum]->getCreature(tempX,tempY))->getHP();
                }
                //cout << endl << "Creature's HP after: " << HP << endl;
				mvprintw(26,0,"Creature's HP after: %i", HP);
				refresh();
                creatureOccupied = false;
                tempX = playerX;
                tempY = playerY;
            }
            else if(wallOccupied == false)
            {
                tempX = playerX;
                tempY = playerY;
            }
            //cout << endl << pPlayer->getName() << "'s health is " << pPlayer->getHP() << endl;
			mvprintw(30,0,"%s's health is %i.", pPlayer->getName().c_str(), pPlayer->getHP());
            //cout << endl << "There are " << vvCreatures[dNum].size() << " creatures left on the field. " << endl;
			mvprintw(31,0,"There are %i creatures left on the field. ", vvCreatures[dNum].size());
			//cout << endl << pPlayer->getName() << " has " << pPlayer->getHP() << " Health and " << pPlayer->getExperience() << " Experience right now.";
			mvprintw(32,0,"%s has %i Health and %i Experience right now.",pPlayer->getName().c_str(),pPlayer->getHP(),pPlayer->getExperience());
			//cout << pPlayer->getName() << " killed the monster and gained experience!" << endl;

            ////////////////////////////////////MONSTER MOVEMENT AND ATTACK/////////////////////////////////////////////


            for( size_t i = 0 ; i < vvCreatures[dNum].size() ; i++ )
            {   
                thingTempX = vvCreatures[dNum][i]->getCoordX();
                thingTempY = vvCreatures[dNum][i]->getCoordY();
                //cout << endl << "Creature " << i << " moved from (" << thingTempX << ", " << thingTempY << ") to (";
				//mvprintw("Creature %i moved from (%i,%i) to (", i,thingTempX,thingTempY);
				refresh();
                if( thingTempX < playerX )
                {
                    thingTempX ++;
                }
                else if( thingTempX > playerX )
                {
                    thingTempX --;
                }
                if( thingTempY < playerY )
                {
                    thingTempY ++;
                }
                else if( thingTempY > playerY )
                {
                    thingTempY --;
                }
                for( size_t j = 0 ; j < vvCreatures[dNum].size() ; j++ )
                {
                    if( vvCreatures[dNum][j]->getCoordX() == thingTempX && vvCreatures[dNum][j]->getCoordY() == thingTempY )
                    {
                        creatureOccupied = true;
                    }
                }
				//cout << ")" << endl;
                if(wallOccupied == false)
                {
                    //vDL[dNum]->removeCreature(vvCreatures[dNum][i]->getCoordX(), vvCreatures[dNum][i]->getCoordY());
                    //cout << endl << "restraint" << endl;
					mvprintw(23,50,"You cannot move there...It's a wall.");
                    //vDL[dNum]->setCreature(vvCreatures[dNum][i], vvCreatures[dNum][i]->getCoordX(), vvCreatures[dNum][i]->getCoordY());
                }
                else if( (vDL[dNum]->checkMove(thingTempX, thingTempY) == true && creatureOccupied == false) && (playerX != thingTempX && playerY != thingTempY) )
                {
                    vDL[dNum]->removeCreature(vvCreatures[dNum][i]->getCoordX(), vvCreatures[dNum][i]->getCoordY());
                    vvCreatures[dNum][i]->setCoords(thingTempX, thingTempY);
                    vDL[dNum]->setCreature(vvCreatures[dNum][i], thingTempX, thingTempY);
                }
                else if( ((abs( playerX - thingTempX ) == 1) && (abs( playerY - thingTempY ) == 1)) || (thingTempX == playerX && thingTempY == playerY) )
                {
                    //cout << endl << vvCreatures[dNum][i]->getName() << " attacked " << pPlayer->getName();
					mvprintw(25,0,"%s atacked %s",vvCreatures[dNum][i]->getName().c_str(), pPlayer->getName().c_str());
                    HP = pPlayer->getHP();
                    attack = mt() % punch->getDamage() - (pPlayer->getArmorType())->getArmorValue();
                    if ( attack > 0 )
                    {
                        pPlayer->setHP(HP - attack);
                        //cout << " for " << attack << " damage." << endl;
						mvprintw(25,30," for %i damage.",attack);
						refresh();
                    }
                    else
                    {
						mvprintw(25,30," for 0 damage");
						refresh();
                        //cout << "for 0 damage" << endl;
                    }
                    //If Player Died in the attack:
					if(pPlayer->getHP() <= 0)
					{
						char regen[ 4 ];
						//cout << endl << "You were killed in battle!! Do you want to come back to life? y or n? " << endl;
						mvprintw(40,0,"You were killed in battle!! Do you want to come back to life? y or n? " );
						refresh();
						getnstr( regen, sizeof( regen ) - 1 );
						
						//cin >> regen;
						if (regen == "y")
						{
							pPlayer->setHP(100);
						}
						break;
					}
                    //cout << endl << pPlayer->getName() << " now has " << pPlayer->getHP() << " health left " << endl;
                    //vDL[dNum]->setCreature(vvCreatures[dNum][i], vvCreatures[dNum][i]->getCoordX(), vvCreatures[dNum][i]->getCoordY());
                    creatureOccupied = false;
                }
                //cout << endl << vvCreatures[dNum][i]->getCoordX() << ", " << vvCreatures[dNum][i]->getCoordY() << ")" << endl;
            }
            if( nextFloor == true )
            {
                dNum++;
                if( dNum < vDL.size() )
                {
                    sameFloor = true;
                }
                break;
            }
            else if( prevFloor == true )
            {
                dNum--;
                break;
            }
        }
        if( sMove == "q" )
        {
			//printw("\n You quit... you Quitter!");
			//printw("\n");
            break;
        }
    }

    for( size_t i = 0 ; i < vDL.size() ; i++ )
    {
        for( size_t j ; j < vvCreatures[i].size() ; j++ )
        {
            delete vvCreatures[i][j];
        }
    }

	/*cout << "GAME OVER" << endl;
    cout << "Score - " << pPlayer->getExperience() << endl;
	cout << "Health at the end - " << pPlayer->getHP() << endl;*/
    clear();
	mvprintw(0,0,"GAME OVER" );
	mvprintw(1,0,"Score - %i", pPlayer->getExperience() );
	mvprintw(2,0, "Health at the end - %i", pPlayer->getHP() );
	mvprintw(3,0," ");
	refresh();

    delete pPlayer;
    delete punch;
	delete keys;
	delete TrashCanLid;
	output.open(outFileName);
	
	//outputXML(vWorld, output);
//delete memory to avoid memory leaks
	for(auto it = vWorld.begin() ; it != vWorld.end() ; it++)
	{
		delete (*it);
	}
//close input and output files!
	input.close();
	output.close();
	clear();
	return 0;
}
Пример #27
0
void init_random_seed(int seed)
{
  generator.seed(seed);
}
Пример #28
0
		Controller() :
			network(this), model(this), resources(), display(this)
      {
	_generator.seed(42);
      }
Пример #29
0
 static void updateRandomSeed(uint32_t seed_number)
 {
     m_random_engine.seed(seed_number);
 }   // updateRandomSeed
Пример #30
0
void Window::Init(int width, int height, std::string title)
{
	// Intiate Random Number Generator	
	m_Random.seed(time(0));

	//initialize all SDL subsystems
	if (SDL_Init(SDL_INIT_EVERYTHING) == -1)
		throw std::runtime_error("SDL Init Failed");
	//if (TTF_Init() == -1)
		//throw std::runtime_error("TTF Init Failed");

	// -- For Music --
	/* We're going to be requesting certain things from our audio
	device, so we set them up beforehand */
	int audio_rate = 22050;
	Uint16 audio_format = AUDIO_S16; /* 16-bit stereo */
	int audio_channels = 2;
	int audio_buffers = 4096;

	SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);

	/* This is where we open up our audio device.  Mix_OpenAudio takes
	as its parameters the audio format we'd /like/ to have. */
	if (Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers))
		throw std::runtime_error("Unable to open audio!\n");

	/* If we actually care about what we got, we can ask here.  In this
	program we don't, but I'm showing the function call here anyway
	in case we'd want to know later. */
	Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels);
	/* Every sound that gets played is assigned to a channel.  Note that
	this is different from the number of channels you request when you
	open the audio device; a channel in SDL_mixer holds information
	about a sound sample that is playing, while the number of channels
	you request when opening the device is dependant on what sort of
	sound you want (1 channel = mono, 2 = stereo, etc) */

	//-- For Sounds --
	/* Mix_Chunk is like Mix_Music, only it's for ordinary sounds. */

	//Setup our window size
	mBox.x = 0;
	mBox.y = 0;
	mBox.w = width;
	mBox.h = height;

	/* Create the windows and initialize the renderers */
	//Create our window
	mWindow.reset(SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_CENTERED,
		SDL_WINDOWPOS_CENTERED, mBox.w, mBox.h, SDL_WINDOW_SHOWN));

	//Make sure it created ok
	if (mWindow == nullptr)
		throw std::runtime_error("Failed to create window");

	mRenderer.reset(SDL_CreateRenderer(mWindow.get(), -1,
		SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC));

	//Make sure it created ok
	if (mRenderer == nullptr)
		throw std::runtime_error("Failed to create renderer");

	Clear();
	SDL_SetRenderDrawBlendMode(mRenderer.get(), SDL_BLENDMODE_NONE);
	SDL_RenderFillRect(mRenderer.get(), NULL);
}