Exemple #1
0
int main(int argc, char *argv[])
{
  srand(time(NULL));
  generateMap();
  printMap();
  init();
  while(TRUE){
    if (enemies == NULL) { // win condition
      for (int i = 0; i < MAP_WIDTH*MAP_HEIGHT; ++i)
	unchanged[i] = FALSE;
      drawMapState(WIN_MAP);
      break;
    } if (!playerIsAlive) {
      for (int i = 0; i < MAP_WIDTH*MAP_HEIGHT; ++i)
	unchanged[i] = FALSE;
      drawMapState(GAME_OVER_MAP);
      break;
    }
    drawMapState(map);
    printMap();
    pause();
  }
  destroyFrameBuffer();
  destroyGamepad();
}
int getWindowSize(string str1, string str2)
{
   std::map<char, int> myStr2;
   for (int i=0; i< str2.length(); i++)
       myStr2.insert(std::pair<char, int>(str2[i], -1));
   printMap(myStr2);
	   
   int minWin = 100;   
   std::map<char, int>::const_iterator it;
   for (int i=0; i< str1.length(); i++)
    {
	   it = myStr2.find(str1[i]);
       if (it!= myStr2.end())
	    {
		  myStr2.erase(str1[i]);
	      myStr2.insert(std::pair<char, int>(str1[i], i));
		  int tmpMin = getMinIndex(myStr2);
		  if (minWin > (i-tmpMin+1) && tmpMin!=-1)
		  {
		     minWin = i-tmpMin+1;
			 std::cout<<"minWin...." << minWin <<"\n";
		  }
		  printMap(myStr2);
		}
	      
	}
	return minWin; 
}
Exemple #3
0
void main()
{
	StartCoords.x = 1;
	StartCoords.y = 5;

	FinishCoords.x = 9;
	FinishCoords.y = 9;

	PopulateMap(); //Initial map population
	printMap();

	while (true)
	{
		switch (state)
		{
		case 1:
			{
				LeePopulate();
			}
		case 2:
			{
				LeeBacktrace();
			}
		case 3:
			{
				LeeShowPath();
				break;
			}
		}
		printMap();
		break;
	}
}
Exemple #4
0
static void
test() {
    ValueSet vs1;
    vs1.insert(100);
    vs1.insert(101);
    vs1.insert(102);
    vs1.insert(103);

    Map m;

    // Insert something for a single key. The size_t cast is required.
    m.insert(KeyRange((size_t)0), vs1);
    printMap(std::cout, "inserted {100,101,102,103} at key 0", m);

    // Insert a neighboring key with the same value (they should be combined)
    m.insert(KeyRange((size_t)1), vs1);
    printMap(std::cout, "inserted {100,101,102,103} at key 1", m);

    // Insert another neighboring key with the same value (they should be combined)
    m.insert(KeyRange((size_t)2), vs1);
    printMap(std::cout, "inserted {100,101,102,103} at key 2", m);

    // Remove the middle key (should result in two values stored)
    m.erase(KeyRange((size_t)1));
    printMap(std::cout, "erased key 1", m);
}
Exemple #5
0
static void
test() {
    ValueSet vs1;
    vs1.insert(100);
    vs1.insert(101);
    vs1.insert(102);
    vs1.insert(103);

    Map m;

    // Insert something for a single key
    m.insert(0, vs1);
    printMap(std::cout, "inserted {100,101,102,103} at key 0", m);

    // Insert a neighboring key with the same value (they should be combined)
    m.insert(1, vs1);
    printMap(std::cout, "inserted {100,101,102,103} at key 1", m);

    // Insert another neighboring key with the same value (they should be combined)
    m.insert(2, vs1);
    printMap(std::cout, "inserted {100,101,102,103} at key 2", m);

    // Remove the middle key (should result in two values stored)
    m.erase(1);
    printMap(std::cout, "erased key 1", m);
}
Exemple #6
0
void WriteAndReadExampleStdIO()
{
	// Declare data to be serialized:
	std::map<std::string, uint32_t> m1{{"one", 1}, {"two", 2}};

	// === Write ===
	{
		// CStream output:
		std::ofstream ofs("file.bin");
		auto arch_out = mrpt::serialization::archiveFrom<std::ostream>(ofs);
		// Use << to serialize in binary form:
		arch_out << m1;
	}

	// === Read ===
	std::map<std::string, uint32_t> m2;
	{
		// CStream output:
		std::ifstream ifs("file.bin");
		auto arch_in = mrpt::serialization::archiveFrom<std::istream>(ifs);
		// Use >> to deserialize:
		arch_in >> m2;
	}

	std::cout << "Wrote: ";
	printMap(m1);
	std::cout << "Read : ";
	printMap(m2);
}
main()
{
    long mac = 1L;
    recur_put(first);
    printMap(mapbits, 48, 24, mac << 48);
    recur_put(second);
    printMap(wordbits, 64, 14, mac << 63);
}
Exemple #8
0
static void printKeyboard(void)
{
	// Print out the detail of the selected keymap
	printf(_("\nPrinting out keymap \"%s\"\n\n"), selectedMap->name);
	printf("-- %s --\n", _("Regular map"));
	printMap(selectedMap->regMap);
	printf("-- %s --\n", _("Shift map"));
	printMap(selectedMap->shiftMap);
	printf("-- %s --\n", _("Ctrl map"));
	printMap(selectedMap->controlMap);
	printf("-- %s --\n", _("AltGr map"));
	printMap(selectedMap->altGrMap);
}
Exemple #9
0
// Main game function
void run()
{
    // Initialize the map
    initMap();
    running = true;
    while (running) {
        // If a key is pressed
        if (_kbhit()) {
            // Change to direction determined by key pressed
            changeDirection(_getch());
        }
        // Upate the map
        update();

        // Clear the screen
        clearScreen();

        // Print the map
        printMap();

        // wait 0.5 seconds
        Sleep(500);
    }

    // Print out game over text
    std::cout << "\t\t!!!Game over!" << std::endl << "\t\tYour score is: " << food;

    // Stop console from closing instantly
    std::cin.ignore();
}
Exemple #10
0
int main(){
	int cont = 1, i, j, x = COLS / 2, y = ROWS / 2;
	char map[ROWS][COLS];
	char input;
	
	for(i = 0; i < ROWS; i++){
		for(j = 0; j < COLS; j++){
			map[i][j] = '.';
		}
	}

	while(cont){
		printMap(map, x, y);
		input = getch();
		if(input == 'w')
			y--;
		else if(input == 's')
			y++;
		else if(input == 'a')
			x--;
		else if(input == 'd')
			x++;
		else if(input == 'q')
			cont = 0;
	}
}
Exemple #11
0
/* 
 * Function: setup()
 * Setup the map from the file entered via argv.
 */
void setup(int argc, char *argv[]){

	// Chekc weather the user enter the right command
	if(argc!=2){
		printErrorAndExit(WRONG_USAGE);
	}

	// Scan in the size of the map
	printf("Read file map from: %s\n",argv[1]);
	FILE *fin = fopen(argv[1],"r");
	if(fin == NULL)	printErrorAndExit(FILE_READ_ERROR);
	if(fscanf(fin,"%d%d", &M, &N)!=2)
		printErrorAndExit(FILE_FORMAT_ERROR);

	// Setup Smiley's starting position on the bottom-left
	setSmileyPos();

	// Setup the map and the wall array
	Map = malloc2DArray(M,N);
	RWall = malloc2DArray(M-1,N);
	CWall = malloc2DArray(M,N-1);

	// Scan in the whole map
	readMap(fin);
	readWalls(fin);

	// Print out the map for debugging
	printMap();
	printWalls();

	// Function end here
}
Exemple #12
0
int     main(int ac, char **av) {
  ll_node *head;
  int steps, i;
  t_map map;

  /* Get user input */
  head = getColors();
  if (!head)
    return (0);
  steps = atoi(readLine(0));

  /* Init the map */
  map.nodes = malloc(sizeof(ll_node *) * WIDTH * HEIGHT);
  map.x_ant = WIDTH / 2;
  map.y_ant = HEIGHT / 2;
  map.dir = 0;
  for (i = 0; i < WIDTH * HEIGHT; ++i) {
    map.nodes[i] = head;
  }
  map.nodes[i] = NULL;

  while (steps--)
    moveAnt(&map);

  printMap(map.nodes);
}
Exemple #13
0
int main(void) {
    init();
    scan();
    // printMap();
    // scanf("%d %d" , &beginX , &beginY);
    // scanf("%d %d" , &endX , &endY);
    beginX--;
    beginY--;
    endX--;
    endY--;
    queue[tail].x = beginX;
    queue[tail++].y = beginY;
    sum = 1;
    // dfs(beginX , beginY);
    dfs(1 , 1);
    printf("%d 平方民\n" , sum);
    sum = 1;
    dfs(6 , 0);
    printf("%d 平方民\n" , sum);
    sum = 1;
    dfs(11 , 0);
    printf("%d 平方民\n" , sum);
    sum = 1;
    printf("%d 平方民\n" , sum);
    dfs(1 , 5);
    printMap();
    return 0;
}
Exemple #14
0
static int
printMetaData(D4printer* out, NCD4node* node, int depth)
{
    int ret = NC_NOERR;
    int i;

    if(nclistlength(node->dims) > 0) {
	for(i=0;i<nclistlength(node->dims);i++) {
	    NCD4node* dim = (NCD4node*)nclistget(node->dims,i);
	    printDimref(out,dim,depth);
	    CAT("\n");
	}
    }
    if(nclistlength(node->maps) > 0) {
	for(i=0;i<nclistlength(node->maps);i++) {
	    NCD4node* mapref = (NCD4node*)nclistget(node->maps,i);
	    printMap(out,mapref,depth);
	    CAT("\n");
	}
     }
    if(nclistlength(node->attributes) > 0) {
	for(i=0;i<nclistlength(node->attributes);i++) {
	    NCD4node* attr = (NCD4node*)nclistget(node->attributes,i);
	    printAttribute(out,attr,depth);
	    CAT("\n");
	}
    }
    return THROW(ret);
}
int main(int argc, char** argv)
{        
	//Generate map foundation
	short int map[MAPSIZE][MAPSIZE];
	int branch_chance = 50;
	initMap(map);
	createMainPath(map);
	createBranches(map, branch_chance);
	printMap(map);
	system("pause");
	/* Standard GLUT initialization */
	//glutInit(&argc,argv);
	/*glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    glutInitWindowSize(700,700);
    glutInitWindowPosition(50,50);
    glutCreateWindow("War Games Scene");
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
	glutKeyboardFunc(myKey);*/






	//myinit();
	//glutMainLoop(); /* enter event loop */
}
Exemple #16
0
int main()
{
    go(START_X, START_Y, 0);
    printf("The shortest route is the following one:\n");
    printMap(resultMap, resultNodes);
    return 0;
}
Exemple #17
0
//prints the overall map screen
void Game::update()
{
	ClearScrn();

	int verticalPadding = (20 - map.getRows()) / 2;

	//prints screen
	cout << " ======================================================================= \n";
	cout << "|" << al.PrintMapStats() << string(71 - (al.PrintMapStats().size()), ' ') << "|\n";
	cout << "|-----------------------------------------------------------------------|\n";
	for (int i = 0; i < verticalPadding; i++)
	{
		cout << "|                                                                       |\n";
	}

	printMap(al.GetxLocation(), al.GetyLocation());

	for (int i = 0; i < verticalPadding; i++)
	{
		cout << "|                                                                       |\n";
	}
	cout << "|-----------------------------------------------------------------------|\n";
	cout << "|  Messages: " << message << string(58 - message.size(), ' ') << " |\n";
	cout << "|                                                                       |\n";
	cout << "|  Controls: wasd - move, 3. Eat 4. Drink             q - quit          |\n";
	cout << "|                                                                       |\n";
	cout << " ======================================================================= \n";

}
Exemple #18
0
void ControlView::printMapScreenShot( QPointer<QPrintDialog> printDialog)
{
#ifndef QT_NO_PRINTER
    PrintOptionsWidget* printOptions = new PrintOptionsWidget( this );
    bool const mapCoversViewport = m_marbleWidget->viewport()->mapCoversViewport();
    printOptions->setBackgroundControlsEnabled( !mapCoversViewport );
    bool hasLegend = m_marbleWidget->model()->legend() != 0;
    printOptions->setLegendControlsEnabled( hasLegend );
    bool hasRoute = marbleWidget()->model()->routingManager()->routingModel()->rowCount() > 0;
    printOptions->setPrintRouteSummary( hasRoute );
    printOptions->setPrintDrivingInstructions( hasRoute );
    printOptions->setPrintDrivingInstructionsAdvice( hasRoute );
    printOptions->setRouteControlsEnabled( hasRoute );
    printDialog->setOptionTabs( QList<QWidget*>() << printOptions );

    if ( printDialog->exec() == QDialog::Accepted ) {
        QTextDocument document;
        QString text = "<html><head><title>Marble Printout</title></head><body>";
        QPalette const originalPalette = m_marbleWidget->palette();
        bool const wasBackgroundVisible = m_marbleWidget->showBackground();
        bool const hideBackground = !mapCoversViewport && !printOptions->printBackground();
        if ( hideBackground ) {
            // Temporarily remove the black background and layers painting on it
            m_marbleWidget->setShowBackground( false );
            m_marbleWidget->setPalette( QPalette ( Qt::white ) );
            m_marbleWidget->update();
        }

        if ( printOptions->printMap() ) {
            printMap( document, text, printDialog->printer() );
        }

        if ( printOptions->printLegend() ) {
            printLegend( document, text );
        }

        if ( printOptions->printRouteSummary() ) {
            printRouteSummary( document, text );
        }

        if ( printOptions->printDrivingInstructions() ) {
            printDrivingInstructions( document, text );
        }

        if ( printOptions->printDrivingInstructionsAdvice() ) {
            printDrivingInstructionsAdvice( document, text );
        }

        text += "</body></html>";
        document.setHtml( text );
        document.print( printDialog->printer() );

        if ( hideBackground ) {
            m_marbleWidget->setShowBackground( wasBackgroundVisible );
            m_marbleWidget->setPalette( originalPalette );
            m_marbleWidget->update();
        }
    }
#endif
}
Exemple #19
0
bool	Map::pushBomb(Character &pusher, unsigned int destX, unsigned int destY)
{
  unsigned int pushX = pusher.getX();
  unsigned int pushY = pusher.getY();
  unsigned int bombX;
  unsigned int bombY;
  int		index;

  if (!pusher.getKickBomb())
    return (false);
  printMap();
  if ((index = findBomb(destX, destY)) == -1)
    return (false);
  bombX = _bomb[index]->getX();
  bombY = _bomb[index]->getY();
  if (bombX == pushX)
    {
      if ((bombY > pushY) && (canMove(bombX, bombY, 1)))
	return (_bomb[index]->startMoving(1)); // UP
      else if ((bombY < pushY) && (canMove(bombX, bombY, 2)))
	return (_bomb[index]->startMoving(2)); // DOWN
      else
	return (false); //ERROR;
    }
  else if (bombY == pushY)
    {
      if ((bombX > pushX) && (canMove(bombX, bombY, 3)))
	return (_bomb[index]->startMoving(3)); // RIGHT
      else if ((bombX < pushX) && (canMove(bombX, bombY, 4)))
	return (_bomb[index]->startMoving(4)); // LEFT
      else
	return (false); //ERROR;
    }
  return (false);
}
Exemple #20
0
// Loading map
void Map::loadMap(const string mapFile)
{
	// Decode map file
	lodepng::decode(pixels, width, height, mapFile);

	// Resize the map vector with the height
	map.resize(height);

	// Going over all of the cells in the map
	for (unsigned int y = 0; y < height; y++)
	{
		// Resizing every cell with the given width
		map[y].resize(width);
	}

	Point current;

	// Going over all of the cells to the height of the map
	for (unsigned int y = 0; y < height; y++)
	{
		// Going over all of the cell to the width of the map
		for (unsigned int x = 0; x < width; x++)
		{
			current.y = y;
			current.x = x;

			// Checking if the current cell is occupied
			map[y][x] = checkIfCellIsOccupied(current);
		}
	}

	// Print the new map
	printMap();
}
Exemple #21
0
int main()
{
    createMap();
    printMap();
    aStar();

    return 0;
}
Exemple #22
0
/* prints basic GUI that should always be visible */
void printGui(world* w) {
  wborder(w->Windows.Main, '*', '*', '*', '*', '*', '*', '*', '*'); 
  wborder(w->Windows.Status, '#', '#', '#', '#', '#', '#', '#', '#'); 

  printObjects(w);
  printPlayerStatus(w);
  printMap(w); 
}
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;
}
Exemple #24
0
int main (int argc, const char * argv[]) {
	const char* filename;
	struct hashMap *hashTable;
	int tableSize = 10;
	clock_t timer;
	FILE *fileptr;
    /*
     this part is using command line arguments, you can use them if you wish
     but it is not required. DO NOT remove this code though, we will use it for
     testing your program.

     if you wish not to use command line arguments manually type in your
     filename and path in the else case.
     */
    if(argc == 2)
        filename = argv[1];
    else
        filename = "input2.txt"; /*specify your input text file here*/

    printf("opening file: %s\n", filename);

	timer = clock();

	hashTable = createMap(tableSize);

    /*... concordance code goes here ...*/
    FILE *ifp;
    char *mode = "r";
    char *word, key;
    ifp = fopen(filename, mode);
    assert(ifp);
    while((word = getWord(ifp)) != NULL){
            if(word)
                insertMap(hashTable, word, 1);
    }
    fclose(ifp);
	/*... concordance code ends here ...*/

	printMap(hashTable);
	timer = clock() - timer;
	printf("\nconcordance ran in %f seconds\n", (float)timer / (float)CLOCKS_PER_SEC);
	printf("Table emptyBuckets = %d\n", emptyBuckets(hashTable));
    printf("Table count = %d\n", size(hashTable));
	printf("Table capacity = %d\n", capacity(hashTable));
	printf("Table load = %f\n", tableLoad(hashTable));

    printf("Deleting keys\n");

	removeKey(hashTable, "bitter");
	removeKey(hashTable, "me");
	removeKey(hashTable, "the");
//	printMap(hashTable);

	deleteMap(hashTable);
	printf("\nDeleted the table\n");
	return 0;
}
void ModelPainter::paint(sf::RenderWindow& window)
{
    model::ObjectPtr playerObj = modelFacade_->getPlayerObject();
    maps::IMapContainer& currentMap = modelFacade_->getCurrentMap();

    printMap(window, currentMap);
    printPlayer(window, playerObj);
    setCamera(window, playerObj);
    updateViewportArea(currentMap, playerObj);
}
Exemple #26
0
void LeeShowPath()
{
	Coords Pathnode;
	while (!path.empty())
	{
		Pathnode = path.front();
		path.pop();
		Map[Pathnode.x][Pathnode.y].setPath(true);
		printMap();
	}
}
void phase_two(char* path) 
{
	//using shortest path, create map from start to finish
	double map[MAP_SIZE][2];
	buildMap(map, path);
	printMap(map);

	//Follow map to finish
	followMap(map);
	slowDown();
}
Exemple #28
0
void Drop::doDrop()
{
    initExitList();
    initPathValue();
    printMap(_map);
    Points eliminatePoints{Vec2(9,3),Vec2(8,3),Vec2(7,3),Vec2(6,3)};
    
    for (auto p: eliminatePoints) {
        findOneWay(p.x, p.y);
    }
}
Exemple #29
0
bool RoboyBehaviorPlan::doFlattening() {
    //TODO: SampleRate
    // Build MotorId - Trajectory Map for whole plan
    qint32 waypointCount = this->getDuration() / m_sampleRate;

    PLAN_DBG << "Begin flattening Trajectories";
    PLAN_DBG << "\t- Start Timestamp: " << this->m_startTimestamp;
    PLAN_DBG << "\t- End Timestamp: "   << this->m_endTimestamp;
    PLAN_DBG << "\t- Duration: "        << this->getDuration();
    PLAN_DBG << "\t- SampleRate:"       << this->m_sampleRate;
    PLAN_DBG << "\t- Waypoint Count:"   << waypointCount;

    Trajectory trajectory;
    trajectory.m_controlMode = ControlMode::UNDEFINED_CONTROL;
    trajectory.m_sampleRate =  m_sampleRate;

    RoboyWaypoint waypoint;
    waypoint.m_ulValue = FLT_MAX;

    for(RoboyBehaviorExecution execution : m_listExecutions) {
        // Initialize Motor-Trajectory Map with defaul Values WAYPOINT_DEFAULT
        for(qint32 motorId : execution.behavior.m_mapMotorTrajectory.keys()) {
            if(!m_mapMotorTrajectories.contains(motorId)){
                trajectory.m_id = execution.behavior.m_metadata.m_ulBehaviorId;
                trajectory.m_listWaypoints.clear();
                for(int i = 0; i < waypointCount; i++) {
                    trajectory.m_listWaypoints.append(waypoint);
                }
                m_mapMotorTrajectories.insert(motorId, trajectory);
            }
        }
        printMap();
        // Try to insert every execution
        if(!insertExecution(execution))
            return false;
    }

    printMap();
    return true;
}
Exemple #30
0
void
LevelMap::random (void) {
  printf ("start!\n");

  minX_ = 0;
  minY_ = 0;
  maxX_ = MAX_X;
  maxY_ = MAX_Y;
  totalMoves_ = totalPushes_ = 0;
  clearMap ();

  xpos_ = 13;
  ypos_ = 9;

  KRandomSequence random(0);

  for (int i=0; i<200; i++) {
    map (xpos_, ypos_, FLOOR);

    switch (random.getLong(4)) {
    case 0:
      if (ypos_ > 1) ypos_--; else i--;
      break;

    case 1:
      if (ypos_ < MAX_Y-1) ypos_++; else i--;
      break;

    case 2:
      if (xpos_ > 1) xpos_--; else i--;
      break;

    case 3:
      if (xpos_ < MAX_X-1) xpos_++; else i--;
      break;
    }
  }

  for (int y=1; y<MAX_Y; y++) {
    for (int x=1; x<MAX_X; x++) {
      if (map (x, y) & FLOOR) {
	if (!(map (x, y-1) & FLOOR)) map (x, y-1, WALL);
	if (!(map (x, y+1) & FLOOR)) map (x, y+1, WALL);
	if (!(map (x-1, y) & FLOOR)) map (x-1, y, WALL);
	if (!(map (x+1, y) & FLOOR)) map (x+1, y, WALL);
      }
    }
  }

  printf ("klar!\n");
  printMap ();
}