Beispiel #1
0
void Game::configure(GameConfiguration config) {
	if (!config.isValid()) {
		throw std::invalid_argument("Invalid configuration: " + config.str());
	}
	config.clean();

	reset();


	curTurn = config.getTurn();


	FOR_POSITION_64(pos) {
		setPieceAt(pos, config.getPieceAt(pos));
		if (config.getPieceAt(pos) != Piece::EMPTY()) {
			toggleBit(config.getOwnerAt(pos), pos, config.getPieceAt(pos));
		}
	}

	cur = Game_UndoData();
	cur.halfMoveClock = config.getHalfMoveClock();
	fullMoveCount = config.getMoveNumber();
	cur.check = posAttackedBy(getKingPosition(getTurn()), !getTurn());

	cur.hash = Game_Hash(config);


	integrityCheck();
}
Beispiel #2
0
Mesh::Mesh(const string &file)
    : scale(1.)
{
    int i;
#define OUT { vertices.clear(); edges.clear(); return; }
    ifstream obj(file.c_str());
    
    if(!obj.is_open()) {
        Debugging::out() << "Error opening file " << file << endl;
        return;
    }
    
    Debugging::out() << "Reading " << file << endl;
    
    if(file.length() < 4) {
        Debugging::out() << "I don't know what kind of file it is" << endl;
        return;
    }
    
    if(string(file.end() - 4, file.end()) == string(".obj"))
        readObj(obj);
    else if(string(file.end() - 4, file.end()) == string(".ply"))
        readPly(obj);        
    else if(string(file.end() - 4, file.end()) == string(".off"))
        readOff(obj);        
    else if(string(file.end() - 4, file.end()) == string(".gts"))
        readGts(obj);
    else if(string(file.end() - 4, file.end()) == string(".stl"))
        readStl(obj);        
    else {
        Debugging::out() << "I don't know what kind of file it is" << endl;
        return;
    }
    
    //reconstruct the rest of the information
    int verts = vertices.size();
    
    if(verts == 0)
        return;
    
    for(i = 0; i < (int)edges.size(); ++i) { //make sure all vertex indices are valid
        if(edges[i].vertex < 0 || edges[i].vertex >= verts) {
            Debugging::out() << "Error: invalid vertex index " << edges[i].vertex << endl;
            OUT;
        }
    }
    
    fixDupFaces();
    
    computeTopology();
    
    if(integrityCheck())
        Debugging::out() << "Successfully read " << file << ": " << vertices.size() << " vertices, " << edges.size() << " edges" << endl;
    else
        Debugging::out() << "Somehow read " << file << ": " << vertices.size() << " vertices, " << edges.size() << " edges" << endl;
    
    computeVertexNormals();
}
Beispiel #3
0
void BvhBuilder::integrityCheck(const NaiveBvhNode &node, int depth) const
{
    if (node.isLeaf())
        return;
    for (unsigned i = 0; i < _branchFactor && node.child(i); ++i) {
        integrityCheck(*node.child(i), depth + 1);
        ASSERT(node.bbox().contains(node.child(i)->bbox()),
                "Child box not contained! %s c/ %s at %d",
                node.child(i)->bbox(), node.bbox(), depth);
    }
}
Beispiel #4
0
void BvhBuilder::build(PrimVector prims)
{
    if (prims.empty())
        return;
    Box3fp geomBounds, centroidBounds;
    for (const Primitive &p : prims) {
        geomBounds.grow(p.box());
        centroidBounds.grow(p.centroid());
    }

    BuildResult result;
    recursiveBuild(result, *_root, 0, uint32(prims.size() - 1), prims, narrow(geomBounds), narrow(centroidBounds), _branchFactor);
    _numNodes = result.nodeCount;
    _depth = result.depth;

#ifndef NDEBUG
    integrityCheck(*_root, 0);
#endif
}
Beispiel #5
0
City::City(const std::string filename, std::ostream& stream, std::string vehiclesXML, bool html, bool runningUI) : o(stream, html) {

	validCity = true;
	_initCheck = this;

	if (!runningUI){
		o.print("\t\t\t\t\t\t\t\tEMERGENCY SERVICES SIMULATION \n");
		o.print("\t\t\t\t\t\t\t\t============================= \n\n");
	}

	XmlParser parser(this);
	if (vehiclesXML != "empty") {
		parser.parseCity(vehiclesXML);
	}
	parser.parseCity(filename);

	std::pair<int, int> maxCoords =	parser.getMaxValues();

	if(maxCoords.first == -1 && maxCoords.second == -1){
		if (!runningUI) o.print("ERROR: .XML CONTAINED SYNTAX ERRORS !\n\n");
		validCity = false;
		return;
	}

	else if(maxCoords.first == -2 && maxCoords.second == -2){
		if (!runningUI) o.print("ERROR: THERE WAS NO ROOT FOUND IN THE XMLFILE !\n\n");
		validCity = false;
		return;
	}

	else if(maxCoords.first == -3 && maxCoords.second == -3){
		if (!runningUI) o.print("ERROR: THERE WAS FOUND AN OBJECT THAT'S NOT SUPPORTED !\n\n");
		validCity = false;
		return;
	}

	matrix = Matrix(maxCoords.second + 1, maxCoords.first +1);

	link_vehicles_to_bases();

	matrix.addHouses(houses);
	matrix.addFiredeps(departments);
	crossroads = matrix.addStreets(streets);
	matrix.addCrossroads(crossroads);
	matrix.addStores(stores);
	matrix.addHospitals(hospitals);
	matrix.addPolStations(poliStats);

	//o.print(matrix << "\n");
	if (!runningUI) matrix.printMatrix(o);

	if (!runningUI){
		o.print("\nINTEGRITYCHECK: \n");
		o.print("===============\n");
	}
	if (!(integrityCheck())){
		validCity = false;
		return;
	}
	else {
		if (!runningUI) o.print("\tPASSED\n\n");
	}

    matrix.generateHTMLMap(getVehicles());

	ENSURE(properlyInitialized(), "Object 'City' was not properly initialized.");
}