Beispiel #1
0
VectorSpace<V,M>::VectorSpace(const VectorSpace<V,M>& aux)
  : VectorSet<V,M>(aux.env(),((std::string)(aux.m_prefix)).c_str(),INFINITY),
    m_dimGlobal(aux.m_dimGlobal),
    m_map(newMap()),
    m_dimLocal(m_map->NumMyElements()),
    m_componentsNamesArray(NULL),
    m_componentsNamesVec(NULL),
    m_emptyComponentName(""),
    m_zeroVector(new V(m_env,*m_map))
{
  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
    *m_env.subDisplayFile() << "Entering VectorSpace<V,M>::constructor(2)"
                            << ": aux.m_componentsNamesArray = " << aux.m_componentsNamesArray
                            << ", aux.m_componentsNamesVec = "   << aux.m_componentsNamesVec
                            << std::endl;
  }

  if (aux.m_componentsNamesArray != NULL) {
    m_componentsNamesArray = new DistArray<std::string>(*(aux.m_componentsNamesArray));
  }

  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
    *m_env.subDisplayFile() << "Leaving VectorSpace<V,M>::constructor(2)"
                            << std::endl;
  }
}
Beispiel #2
0
bool User::addKnown(int x, int z)
{
  vec newMap(x, 0, z);
  this->mapKnown.push_back(newMap);

  return true;
}
std::multimap<float, std::vector<int> > HuffmanCoder::Merge(std::multimap<float, std::vector<int> >& mapOne, std::multimap<float, std::vector<int> >& mapTwo) {
    std::multimap<float, std::vector<int> > newMap(mapOne);
    for (std::multimap<float, std::vector<int> >::iterator it = mapTwo.begin(); it != mapTwo.end(); it++) {
        newMap.insert(*it);
    }
    return newMap;
}
TVP createMap1()
{
	//{}
	TVP map = newMap();

//	//maplet1 1|->2
	TVP key1 = newInt(1);
	TVP val1 =newInt(2);
	vdmMapAdd(map,key1,val1);
	vdmFree(key1);
	vdmFree(val1);

	//maplet2 3|->4
	TVP key2 = newInt(3);
	TVP val2 =newInt(4);
	vdmMapAdd(map,key2,val2);
	vdmFree(key2);
	vdmFree(val2);

	//maplet3 6|->7
	TVP key3 = newInt(6);
	TVP val3 =newInt(7);
	vdmMapAdd(map,key3,val3);
	vdmFree(key3);
	vdmFree(val3);


	return map;
}
Beispiel #5
0
bool User::addRemoveQueue(int x, int z)
{
  vec newMap(x, 0, z);

  this->mapRemoveQueue.push_back(newMap);

  return true;
}
bool NHomGroupPresentation::intelligentSimplify()
{
 // step 1: simplify presentation of domain and range
 std::unique_ptr<regina::NHomGroupPresentation> rangeMap =
    range_->intelligentSimplifyDetail();
 std::unique_ptr<regina::NHomGroupPresentation> domainMap =
    domain_->intelligentSimplifyDetail();
 // build identity maps if either of the above is null.
 if (! domainMap.get())
    domainMap.reset(new NHomGroupPresentation(*domain_));
 if (! rangeMap.get())
    rangeMap.reset(new NHomGroupPresentation(*range_));

 NGroupPresentation *oldDom(domainMap->domain_), *oldRan(rangeMap->domain_),
                    *newDom(domain_), *newRan(range_);

 domain_ = oldDom; range_ = oldRan;// we need to call this->evaluate but our map

 // step 2: compute rangeMap*(*oldthis)*domainMap.inverse()
 //         and replace "map" appropriately.  Simplify the words in the range.
 //         Do the same for the inverse map if we have one.
 bool retval = rangeMap.get() || domainMap.get();
 std::vector< NGroupExpression > newMap( newDom->countGenerators() );
 for (unsigned long i=0; i<newMap.size(); i++)
  newMap[i].addTermsLast( rangeMap->evaluate(
     evaluate( domainMap->invEvaluate(i) ) ) );
 std::vector< NGroupExpression > newInvMap;
 if (inv_) {
     newInvMap.resize( newRan->countGenerators() );
     for (unsigned long i=0; i<newInvMap.size(); i++)
       newInvMap[i].addTermsLast( domainMap->evaluate(
          invEvaluate( rangeMap->invEvaluate(i) ) ) );
 }
 domain_ = newDom; range_ = newRan;

 // step 3: rewrite this map, and simplify
 for (unsigned long i=0; i<map_.size(); i++) delete map_[i];
 map_.resize( newMap.size() );
 if (inv_) {
     for (unsigned long i=0; i<inv_->size(); i++) delete (*inv_)[i];
     inv_->resize( newInvMap.size() );
 }

 for (unsigned long i=0; i<map_.size(); i++)
       {
        map_[i] = new NGroupExpression(newMap[i]);
        range_->simplifyWord(*map_[i]);
       }
 if (inv_)
     for (unsigned long i=0; i<inv_->size(); i++)
           {
            (*inv_)[i] = new NGroupExpression(newInvMap[i]);
            domain_->simplifyWord(*(*inv_)[i]);
           }

 return retval;
}
Beispiel #7
0
static void setHotFuncAttr() {
  static bool synced = false;
  if (synced) return;

  Lock lock(syncLock);
  if (synced) return;

  /*
   * s_treadmill forces any Funcs that are being destroyed to go through a
   * treadmill pass, to make sure we won't try to dereference something that's
   * being pulled out from under us.
   */
  Func::s_treadmill = true;
  SCOPE_EXIT {
    Func::s_treadmill = false;
  };

  if (RuntimeOption::EvalHotFuncCount) {
    std::priority_queue<FuncHotness,
                        std::vector<FuncHotness>,
                        bool(*)(const FuncHotness& a, const FuncHotness& b)>
      queue(comp);

    Func::getFuncVec().foreach([&](const Func* f) {
      if (!f) return;
      auto const profCounter = [&]() -> uint32_t {
        FuncProfileCounters::const_accessor acc;
        if (s_func_counters.find(acc, f->getFuncId())) {
          return acc->second;
        }
        return 0;
      }();
      auto fh = FuncHotness(f, profCounter);
      if (queue.size() >= RuntimeOption::EvalHotFuncCount) {
        if (!comp(fh, queue.top())) return;
        queue.pop();
      }
      queue.push(fh);
    });

    while (queue.size()) {
      auto f = queue.top().first;
      queue.pop();
      const_cast<Func*>(f)->setAttrs(f->attrs() | AttrHot);
    }
  }

  // We won't need the counters anymore.  But there might be requests in flight
  // that still thought they were profiling, so we need to clear it on the
  // treadmill.
  Treadmill::enqueue([&] {
    FuncProfileCounters newMap(0);
    swap(s_func_counters, newMap);
  });

  synced = true;
}
Beispiel #8
0
int main(int argc, char **argv)
{
	int id1, id2, errs=0;

	if (argc < 3) {
		fprintf(stderr, "Usage: %s Place1 Place2\n", argv[0]);
		exit(1);
	}

	// convert args to place IDs
	id1 = (strlen(argv[1]) == 2) ? abbrevToID(argv[1]) : nameToID(argv[1]);
	id2 = (strlen(argv[1]) == 2) ? abbrevToID(argv[2]) : nameToID(argv[2]);

	// check place validity
	if (id1 == NOWHERE) {
		errs++;
		fprintf(stderr, "Invalid place name: %s\n", argv[1]);
	}
	if (id2 == NOWHERE) {
		errs++;
		fprintf(stderr, "Invalid place name: %s\n", argv[2]);
	}
	if (errs > 0) exit(1);

	Map europe;
	europe = newMap();

	// find shortest path
	int i, n;
    LocationID path[NUM_MAP_LOCATIONS];
	TransportID trans[NUM_MAP_LOCATIONS];

	printf("Starting from %s ...\n", idToName(id1));
	n = shortestPath(europe, id1, id2, path, trans);
	if (n == 0)
		printf("you cannot reach %s\n", idToName(id2));
	else {
		for (i = 1; i < n; i++) {
			if (i > 1 && n > 2) printf("then ");
			printf("go to %s by ", idToName(path[i]));
			switch (trans[i]) {
			case ROAD: printf("road\n"); break;
			case RAIL: printf("rail\n"); break;
			case BOAT: printf("boat\n"); break;
			default:   printf("????\n"); break;
			}
		}
		printf("You have reached your destination\n");
	}

	//DEBUG
    printf("start is: %d; end is: %d\n", id1, id2);
    printf("path[0] is: %d; path[1] is: %d\n", path[0], path[1]);

	return 0;
}
Beispiel #9
0
Game *startGame()
{
	Game *game = malloc(sizeof(Game));
	
	game->renderer = start_UI(0);
	game->map      = newMap();
		
	drawGame(game);
	
	return game;
}
Beispiel #10
0
// Creates a new GameView to summarise the current state of the game
GameView newGameView(char *pastPlays, PlayerMessage messages[])
{
  //printf("called newGameView\n");
   GameView gameView = malloc(sizeof(struct gameView));
   // INITIALIZE ALL THE THINGS IN THE GAMEVIEW STRUCT
   gameView->RoundNum = 0;
   gameView->CurrentPlayer = 0;
   gameView->GameScore = GAME_START_SCORE;
   gameView->europe = newMap();

   gameView->Lord_Godalming  = initPlayer(PLAYER_LORD_GODALMING);
   gameView->Dr_Seward	     = initPlayer(PLAYER_DR_SEWARD);
   gameView->Van_Helsing     = initPlayer(PLAYER_VAN_HELSING);
   gameView->Mina_Harker     = initPlayer(PLAYER_MINA_HARKER);
   gameView->Dracula	     = initPlayer(PLAYER_DRACULA);

   int i;
   int scoreChange=0;

   //// HANDLING PAST PLAYS STRING
   //// We will probably do this a different way in the final thing,  (maybe)
   //// but for now it has to be like this because we can't add functions in
   //// this ADT  ((  :(  ))
   for (i=0; pastPlays[i] != '\0' ; i+=7) {
      if (pastPlays[i] == ' ') i++;
      if (pastPlays[i] == 'G') { //if Godalmings turn 0
         scoreChange = doPlayerTurn(gameView->Lord_Godalming, pastPlays+i);
      } else if (pastPlays[i] == 'S') { //Seward 1
         scoreChange = doPlayerTurn(gameView->Dr_Seward, pastPlays+i);
      } else if (pastPlays[i] == 'H') { //Van helsing 2
         scoreChange = doPlayerTurn(gameView->Van_Helsing, pastPlays+i);
      } else if (pastPlays[i] == 'M') { //Mine 3
         scoreChange = doPlayerTurn(gameView->Mina_Harker, pastPlays+i);
      } else if (pastPlays[i] == 'D') { //DRACUULLLAAA 4
         scoreChange = doPlayerTurn(gameView->Dracula, pastPlays+i);
      }
      if (scoreChange <= 0) {
         gameView->GameScore += scoreChange;
      } else if (scoreChange == 10)
         deductHealth(gameView->Dracula, 10);
      else if (scoreChange == 4) {
         deductHealth(gameView->Dracula, 10);
         gameView->GameScore -= 6;
      }
      gameView->CurrentPlayer++;
      if (gameView->CurrentPlayer==5) {
         gameView->CurrentPlayer = 0;
         gameView->RoundNum++;
      }
   }

   return gameView;
}
Beispiel #11
0
shared_ptr<int> Map::createIntMap()
{
	shared_ptr<int> newMap(new int[map->width * map->height]);

	for (int j = 0; j < map->height; j++)
	{
		for (int i = 0; i < map->width; i++)
		{
			newMap.get()[j * map->width + i] = at(i, j);
		}
	}
	return newMap;
}
Beispiel #12
0
map createNewState(map m, int nPiece, dir d, int dist)
{
	game g = new_game(1, 1, 0, NULL);
	copy_game(m->g, g);
	map r = NULL;
	if (play_move(g, nPiece, d, dist)){
		r = newMap(g, m);
		delete_game(g);
	}
	else
		delete_game(g);
	return r;
}
Beispiel #13
0
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
    if (nrhs != 4)
    {
        mexPrintf("Usage: alpha = LineSearch(prevScores, newScores, labels, lossType)\n");
        mexErrMsgTxt("Incorrect input format\n");
    }

#define mPrevScores (prhs[0])
#define mNewScores (prhs[1])
#define mLabels (prhs[2])
#define mLossType (prhs[3])

    if (nlhs != 1)
        mexErrMsgTxt("One output arg expected");

    char lossName[40];
    if ( mxGetString(mLossType, lossName, sizeof(lossName)) != 0 )
        mexErrMsgTxt("Error reading options.loss");

    SQB::LossType sqbLoss = SQB::ExpLoss;

    if (strcmp(lossName, "exploss") == 0)
        sqbLoss = SQB::ExpLoss;
    else if ( strcmp(lossName, "logloss") == 0 )
        sqbLoss = SQB::LogLoss;
    else if ( strcmp(lossName, "squaredloss") == 0 )
        sqbLoss = SQB::SquaredLoss;
    else
        mexErrMsgTxt("options.loss contains an invalid value");


    MatlabInputMatrix<WeightsType> pPrev( mPrevScores, 0, 1, "prevScores" );
    MatlabInputMatrix<WeightsType> pNew( mNewScores, pPrev.rows(), 1, "newScores" );
    MatlabInputMatrix<WeightsType> pLabels( mLabels, pPrev.rows(), 1, "labels" );

    // create mappings
    ArrayMapType prevMap( pPrev.data(), pPrev.rows(), pPrev.cols() );
    ArrayMapType newMap( pNew.data(), pNew.rows(), pNew.cols() );
    ArrayMapType labelsMap( pLabels.data(), pLabels.rows(), pLabels.cols() );



    SQB::LineSearch< ArrayType, ArrayMapType >  LS( prevMap, newMap, labelsMap, sqbLoss );

    WeightsType alpha = LS.run();

    MatlabOutputMatrix<WeightsType>   outMatrix( &plhs[0], 1, 1 );
    outMatrix.data()[0] = alpha;
}
Beispiel #14
0
int main()
{
	Reader reader;
	try {
		Map newMap( reader.readMap( MAP_PATH ) );
		Line startLine = reader.readLine();
		PlayersInfo newPlayersInfo = reader.readPlayers();
		Game newGame( newMap, newPlayersInfo, startLine, reader );
		newGame.start();
	} catch( std::exception const &e ) {
		std::cerr << e.what() << std::endl;
	}

	return 0;
}
bool NHomGroupPresentation::intelligentNielsen()
{ // modelled on intelligentSimplify
 std::unique_ptr<regina::NHomGroupPresentation> rangeMap =
    range_->intelligentNielsenDetail();
 std::unique_ptr<regina::NHomGroupPresentation> domainMap =
    domain_->intelligentNielsenDetail();
 if (! domainMap.get())
    domainMap.reset(new NHomGroupPresentation(*domain_));
 if (! rangeMap.get())
    rangeMap.reset(new NHomGroupPresentation(*range_));
 NGroupPresentation *oldDom(domainMap->domain_), *oldRan(rangeMap->domain_),
                    *newDom(domain_), *newRan(range_);
 domain_ = oldDom; range_ = oldRan;// we need to call this->evaluate but our map
 bool retval = rangeMap.get() || domainMap.get();
 std::vector< NGroupExpression > newMap( newDom->countGenerators() );
 for (unsigned long i=0; i<newMap.size(); i++)
  newMap[i].addTermsLast( rangeMap->evaluate(
     evaluate( domainMap->invEvaluate(i) ) ) );
 std::vector< NGroupExpression > newInvMap;
 if (inv_) {
     newInvMap.resize( newRan->countGenerators() );
     for (unsigned long i=0; i<newInvMap.size(); i++)
       newInvMap[i].addTermsLast( domainMap->evaluate( invEvaluate(
          rangeMap->invEvaluate(i) ) ) );
 }
 domain_ = newDom; range_ = newRan;
 for (unsigned long i=0; i<map_.size(); i++) delete map_[i];
 map_.resize( newMap.size() );
 if (inv_) {
     for (unsigned long i=0; i<inv_->size(); i++) delete (*inv_)[i];
     inv_->resize( newInvMap.size() );
 }

 for (unsigned long i=0; i<map_.size(); i++)
       {
        map_[i] = new NGroupExpression(newMap[i]);
        range_->simplifyWord(*map_[i]);
       }
 if (inv_)
     for (unsigned long i=0; i<inv_->size(); i++)
           {
            (*inv_)[i] = new NGroupExpression(newInvMap[i]);
            domain_->simplifyWord(*(*inv_)[i]);
           }

 return retval;
}
int main(int argc, char **argv) {
	MAP* map = newMap();
	char *strFrank = "frank";
	char *strJef = "jef";
	char *strDirk = "dirk";
	put(map, strFrank, "0486/11.33.23");
	put(map, strJef, "0486/10.20.30");
	put(map, strDirk, "0475/11.39.12");
	printMap(map);
	printf("Nummer van frank: %s\n",get(map, strFrank));
	printf("Jef verwijderen...\n");
	removePair(map, strJef);
	removePair(map, "bla");
	printMap(map);
	freeMemory(map);
	return 0;
}
Beispiel #17
0
int main(int argc, char **argv)
{
	int id1, id2, errs=0;

	if (argc < 3) {
		fprintf(stderr, "Usage: %s Place1 Place2\n", argv[0]);
		exit(1);
	}

	// convert args to place IDs
	id1 = (strlen(argv[1]) == 2) ? abbrevToID(argv[1]) : nameToID(argv[1]);
	id2 = (strlen(argv[1]) == 2) ? abbrevToID(argv[2]) : nameToID(argv[2]);

	// check place validity
	if (id1 == NOWHERE) {
		errs++;
		fprintf(stderr, "Invalid place name: %s\n", argv[1]);
	}
	if (id2 == NOWHERE) {
		errs++;
		fprintf(stderr, "Invalid place name: %s\n", argv[2]);
	}
	if (errs > 0) exit(1);

	Map europe;
	europe = newMap();

	// check for direct connection
    Transport t[NUM_TRANSPORT];  int i, n;

	printf("Between %s and %s ...\n", idToName(id1), idToName(id2));
	n = connections(europe, id1, id2, t);
	if (n == 0)
		printf("No direct connection\n");
	else {
		for (i = 0; i < n; i++) {
			switch (t[i]) {
			case ROAD: printf("Road connection\n"); break;
			case RAIL: printf("Rail connection\n"); break;
			case BOAT: printf("Boat connection\n"); break;
			default:   printf("Weird connection\n"); break;
			}
		}
	}
	return 0;
}
Beispiel #18
0
// Creates a new GameView to summarise the current state of the game
GameView newGameView(char *pastPlays, PlayerMessage messages[])
{
    //Initialise GameView
    GameView gameView = malloc(sizeof(struct gameView));
    assert(gameView != NULL);

    //Add messages to struct
    //gameView->messages = messages;

    //Establish struct fields
    gameView->currScore = calculateScore(pastPlays);
    gameView->currRound = calculateRound(pastPlays);
    gameView->currTurn = calculateTurn(pastPlays);
    gameView->currPlayer = calculatePlayer(pastPlays);
    gameView->currHealth[PLAYER_LORD_GODALMING] = calculateHunterHealth(pastPlays, PLAYER_LORD_GODALMING);
    gameView->currHealth[PLAYER_DR_SEWARD] = calculateHunterHealth(pastPlays, PLAYER_DR_SEWARD);
    gameView->currHealth[PLAYER_VAN_HELSING] = calculateHunterHealth(pastPlays, PLAYER_VAN_HELSING);
    gameView->currHealth[PLAYER_MINA_HARKER] = calculateHunterHealth(pastPlays, PLAYER_MINA_HARKER);
    gameView->currHealth[PLAYER_DRACULA] = calculateDraculaHealth(pastPlays);
    int trail[TRAIL_SIZE] = {};
    int i = 0;
    calculateTrail(pastPlays, PLAYER_LORD_GODALMING, trail);
    for (i = 0; i < TRAIL_SIZE; i++) {
        gameView->trail[PLAYER_LORD_GODALMING][i] = trail[i];
    }
    calculateTrail(pastPlays, PLAYER_DR_SEWARD, trail);
    for (i = 0; i < TRAIL_SIZE; i++) {
        gameView->trail[PLAYER_DR_SEWARD][i] = trail[i];
    } 
    calculateTrail(pastPlays, PLAYER_VAN_HELSING, trail);
    for (i = 0; i < TRAIL_SIZE; i++) {
        gameView->trail[PLAYER_VAN_HELSING][i] = trail[i];
    }
    calculateTrail(pastPlays, PLAYER_MINA_HARKER, trail);
    for (i = 0; i < TRAIL_SIZE; i++) {
        gameView->trail[PLAYER_MINA_HARKER][i] = trail[i];
    }
    calculateTrail(pastPlays, PLAYER_DRACULA, trail);
    for (i = 0; i < TRAIL_SIZE; i++) {
        gameView->trail[PLAYER_DRACULA][i] = trail[i];
    }     
    gameView->map = newMap();


    return gameView;
}
void ResourceSpawnImplementation::createSpawnMaps(bool jtl, int minpool, int maxpool,
		const String& zonerestriction, Vector<String>& activeZones) {

	int concentration = getConcentration(jtl);
	Vector<String> zonenames = getSpawnZones(minpool, maxpool, zonerestriction, activeZones);

	for (int i = 0; i < zonenames.size(); ++i) {

		Zone* zone = server->getZoneServer()->getZone(zonenames.get(i));
		if (zone == NULL)
			continue;

		SpawnDensityMap newMap(isType("ore"), concentration, zone->getMinX(),
				zone->getMaxX(), zone->getMinY(), zone->getMaxY());

		spawnMaps.put(zonenames.get(i), newMap);
	}
}
EditorWindow::EditorWindow() : QMainWindow(), newmap(this), editgroup(this)
{
	ui.setupUi(this);

	// Set up input
	QObject::connect(ui.ActionNew, SIGNAL(activated()), &newmap, SLOT(exec()));
	QObject::connect(ui.ActionOpen, SIGNAL(activated()), this, SLOT(openDialog()));
	QObject::connect(ui.ActionSave, SIGNAL(activated()), this, SLOT(save()));
	QObject::connect(ui.ActionSaveAs, SIGNAL(activated()), this, SLOT(saveAs()));
	QObject::connect(ui.ActionCompile, SIGNAL(activated()), this, SLOT(compile()));
	QObject::connect(ui.ActionAbout, SIGNAL(activated()), this, SLOT(about()));
	QObject::connect(&newmap, SIGNAL(accepted()), this, SLOT(newMap()));
	QObject::connect(&openmap, SIGNAL(accepted()), this, SLOT(open()));
	QObject::connect(ui.ActionGrid, SIGNAL(toggled(bool)), ui.levelview, SLOT(showGrid(bool)));
	ui.ActionGrid->setChecked(true);
	QObject::connect(ui.ActionMiniMap, SIGNAL(toggled(bool)), ui.levelview, SLOT(showMiniMap(bool)));
	ui.ActionMiniMap->setChecked(true);
	QObject::connect(ui.resize, SIGNAL(clicked()), this, SLOT(resize()));
	QObject::connect(ui.tilelist, SIGNAL(clicked(QModelIndex)), this, SLOT(selectTile(QModelIndex)));
	QObject::connect(ui.entitylist, SIGNAL(clicked(QModelIndex)), this, SLOT(selectEntity(QModelIndex)));
	QObject::connect(ui.toolbox, SIGNAL(currentChanged(int)), this, SLOT(selectPanel(int)));
	// Create edit input group
	editgroup.addAction(ui.ActionDraw);
	editgroup.addAction(ui.ActionErase);
	editgroup.addAction(ui.ActionSelect);
	editgroup.setExclusive(true);
	ui.ActionSelect->setChecked(true);
	QObject::connect(&editgroup, SIGNAL(triggered(QAction*)), this, SLOT(setAction(QAction*)));
	// Fill tile list
	std::vector<std::string> tilenames = TileSet::getTiles();
	for (unsigned int i = 0; i < tilenames.size(); i++)
	{
		tilelist.appendRow(new QStandardItem(tilenames[i].c_str()));
	}
	ui.tilelist->setModel(&tilelist);
	// Fill entity list
	std::vector<std::string> entitynames = Game::get().getEntities();
	for (unsigned int i = 0; i < entitynames.size(); i++)
	{
		entitylist.appendRow(new QStandardItem(entitynames[i].c_str()));
	}
	ui.entitylist->setModel(&entitylist);
}
Beispiel #21
0
static ComoFrame *create_frame(Object *code) {
    size_t i;
    ComoFrame *frame = malloc(sizeof(ComoFrame));

    frame->cf_sp = 0;
    frame->cf_stack_size = 0;

    for(i = 0; i < (size_t)COMO_DEFAULT_FRAME_STACKSIZE; i++) {
        frame->cf_stack[i] = NULL;
    }

    frame->cf_symtab = newMap(4);
    frame->code = code;
    frame->next = NULL;
    frame->namedparameters = newArray(2);
    frame->filename = NULL;

    return frame;
}
Beispiel #22
0
Datei: map.c Projekt: Medeah/P1
map *openMap(char *filePath) {
  FILE *file = fopen(filePath, "r");
  
  /* get width and height of map */
  int width, height;
  if(fscanf(file, "P3 %d %d 255", &width, &height) != 2) {
    printf("error reading frome file\n");
  };
  
  /* create the empty map */
  map *m = newMap(width, height);
  
  /* fill the map */
  parseMap(file, m);
  
  fclose(file);
  
  return m;
}
TVP createMap3()
{
	//{}
	TVP map = newMap();

	//maplet1 7|->8
	TVP key1 = newInt(7);
	TVP val1 =newInt(8);
	vdmMapAdd(map,key1,val1);
	vdmFree(key1);
	vdmFree(val1);

	//maplet2 9|->11
	TVP key2 = newInt(9);
	TVP val2 =newInt(11);
	vdmMapAdd(map,key2,val2);
	vdmFree(key2);
	vdmFree(val2);

	return map;
}
Beispiel #24
0
int main()
{
  // Creation de la carte
  struct map* carte = newMap(MAP_W, MAP_H);

  // Initialisation de la map
  for(int i = 0; i < carte->height; ++i) {
    for(int j = 0; j < carte->width; ++j) {
      int tmp = i == 0 || j == 0 || i == carte->height-1 || j == carte->width-1;
      setCase(carte, i, j, tmp);
    }
  }

  // Affichage map
  printMap(carte);

  // On libère la map
  freeMap(carte);

  return EXIT_SUCCESS;
}
TVP mapApply()
{
	TVP res = NULL;
	//{1|->2,3|->4}(1)=2

	//{}
	TVP map = newMap();

	//maplet1 1|->2
	TVP key1 = newInt(1);
	TVP val1 =newInt(2);
	vdmMapAdd(map,key1,val1);
	vdmFree(key1);
	vdmFree(val1);

	//maplet2 3|->4
	TVP key2 = newInt(3);
	TVP val2 =newInt(4);
	vdmMapAdd(map,key2,val2);
	vdmFree(key2);
	vdmFree(val2);

	//apply id
	TVP tmp1 = newInt(1);

	TVP tmp2 = vdmMapApply(map,tmp1);
	vdmFree(tmp1);

	TVP tmp3 = newInt(2);

	TVP tmp4 = newBool(equals(tmp2,tmp3));


	res = vdmClone(tmp4);
	vdmFree(tmp4);
	vdmFree(tmp3);
	vdmFree(tmp2);

	return res;
}
Beispiel #26
0
bool User::addQueue(int x, int z)
{
  vec newMap(x, 0, z);

  for(unsigned int i = 0; i < mapQueue.size(); i++)
  {
    // Check for duplicates
    if(mapQueue[i].x() == newMap.x() && mapQueue[i].z() == newMap.z())
      return false;
  }

  for(unsigned int i = 0; i < mapKnown.size(); i++)
  {
    //Check for duplicates
    if(mapKnown[i].x() == newMap.x() && mapKnown[i].z() == newMap.z())
      return false;
  }

  this->mapQueue.push_back(newMap);

  return true;
}
Beispiel #27
0
void testMapModule(void) {
   Map map, map2;
   string key;
   string str;

   trace(map = newMap());
   test(size(map), 0);
   test(isEmpty(map), true);
   trace(put(map, "H", "Hydrogen"));
   test(size(map), 1);
   test(isEmpty(map), false);
   trace(put(map, "He", "Helium"));
   trace(put(map, "Al", "Aluminum"));
   test(containsKey(map, "H"), true);
   test(get(map, "H"), "Hydrogen");
   test(get(map, "He"), "Helium");
   test(get(map, "Al"), "Aluminum");
   test(containsKey(map, "Li"), false);
   test(get(map, "Li"), NULL);
   trace(put(map, "Al", "Aluminium"));
   test(get(map, "Al"), "Aluminium");
   trace(remove(map, "Al"));
   test(containsKey(map, "Al"), false);
   test(get(map, "He"), "Helium");
   trace(put(map, "Li", "Lithium"));
   test(get(map, "Li"), "Lithium");
   trace(put(map, "Be", "Beryllium"));
   test(size(map), 4);
   trace(str = "");
   trace (foreach (key in map) str = concat(str, key));
   test(str, "BeHHeLi");
   trace(str = "");
   trace(foreach (key in map) str = concat(str, get(map, key)));
   test(str, "BerylliumHydrogenHeliumLithium");
   trace(map2 = clone(map));
   trace(str = "");
   trace(foreach (key in map2) str = concat(str, get(map2, key)));
   test(str, "BerylliumHydrogenHeliumLithium");
}
Beispiel #28
0
int main(int argc, char** argv) {
  HashMap* map = newMap(40, &testHashFunction, &testComparator, &testKeyCopy);
  Hash key = 0;
  Key testKeyPtr = (Key) &key;
  incrementKeyValue(map, testKeyPtr);
  incrementKeyValue(map, testKeyPtr);
  incrementKeyValue(map, testKeyPtr);
  Hash key2 = 20;
  Key testKeyPtr2 = (Key) &key2;
  incrementKeyValue(map, testKeyPtr2);
  incrementKeyValue(map, testKeyPtr2);
  printf("key = %d\n", get(map, testKeyPtr));
  printf("key2 = %d\n", get(map, testKeyPtr2));
  Hash key3 = 18;
  Key testKeyPtr3 = (Key) &key3;
  incrementKeyValue(map, testKeyPtr3);
  incrementKeyValue(map, testKeyPtr3);
  incrementKeyValue(map, testKeyPtr3);
  incrementKeyValue(map, testKeyPtr3);
  printf("key3 = \%d\n", get(map, testKeyPtr3));
  deleteMap(map);
}
Beispiel #29
0
int main() {
    char map_val[3][3] = {
            {1, 1, 1},
            {1, 1, 1},
            {1, 1, 0}
    };
    map = newMap();
/*    for(int i = 0; i < WIDTH; i++) {
        map[i] = &map_val[i];
    }*/

    int i;

    for (i = 0; i < WIDTH; i++) {
        memcpy(map[i], map_val[i], HEIGHT);
    }
    printMap(map);
    State state;
    state.index = 8;
    state.shape = SPACE;
    printf("fitable? %d\n", fitable(SPACE, 8));

    fit(&state, EL2);
    printMap(map);
    /* State * p_state = &state;
     fit(p_state, EL1);
     if (fitable(STICK1, 4)) {
         printf("fitable!\n");
         state.index = 4;
         state.shape = STICK1;
         p_state = &state;
         fit(p_state, STICK1);
     }*/
    //printf("fitable? %d\n", fitable(STICK1, 4));


    return 0;
}
Beispiel #30
0
void Maps::changeMap(Player* player, int mapid, int pos){
	removePlayer(player);
	player->setMap(mapid);
	player->setMappos(pos);
	player->setType(0);
	player->setChair(0);
	Pos cpos;
	if((unsigned int)pos<info[mapid].Portals.size()){
		cpos.x = info[mapid].Portals[pos].x;
		cpos.y = info[mapid].Portals[pos].y;
	}
	else if(info[mapid].Portals.size() > 0){
		cpos.x = info[mapid].Portals[0].x;
		cpos.y = info[mapid].Portals[0].y;
	}
	else{
		cpos.x = 0;
		cpos.y = 0;
	}
	player->setPos(cpos);
	MapPacket::changeMap(player);
	newMap(player);
}