Ejemplo n.º 1
0
		void simplifyRouteTest()
		{
			int row, column;
			cin >> row >> column;
			vector<vector<int> > board(HEIGHT, vector<int>(WIDTH, 0));
			inputBoard(board);

			const int up = 0;
			const int right = 1;
			const int down = 2;
			const int left = 3;

			Route route;

			//vector<int> routes = { up, up, up, up, up, down, up, up, up, up, up, up, up
			//	, up, up, up, up, up, up, up, up, right };

			vector<int> routes = { down, down, down, down, down, up, left, down, right, down, down, up, up, up, up,
				up, up, up, up, up, up, up };

			route.push_back(routes);
			debug(route);
			vector<vector<int>> board2 = board;
			moveByRoute(board, route, row, column);
			debug(board);
			cout << endl;
			Route simplifid;
			simplifyRoutePerfectly(route, row, column, simplifid);
			//_simplifyRouteNonMoving(board, route, row, column, simplifid);
			cout << endl;
			debug(simplifid);
			moveByRoute(board2, simplifid, row, column);
			debug(board2);
		}
Ejemplo n.º 2
0
Archivo: life.c Proyecto: zellcht/c
int main(int argc, char *argv[]){
  int x, y, i, j;
  FILE *file;
  char iniBoard[MAX_SIZE][MAX_SIZE];
  int status[MAX_SIZE][MAX_SIZE];
  SDL_Simplewin sw;
  SDL_Rect rectangle;

  file = NULL;
  Neill_SDL_Init(&sw);
  initial(iniBoard, status);
  file = fopen(argv[1], "r");
  /* fopen returns NULL pointer on failure */
  if (file == NULL){
    printf("Could not open file. \n");
  }
  else {
    printf("File (%s) opened. \n", argv[1]);
    fscanf(file, "%d %d", &x, &y);
    printf("Row: %d Column: %d \n", x, y);
    char board[y][x];
    if(fgetc(file) != EOF){
      for(j = 0; j < y; j++){
	for(i = 0; i < x + 1; i++){
	  board[j][i] = fgetc(file);
	}
      }
    }
    /* Closing file */
    fclose(file);
    /* Input the board which read from the txt file to a 50x50 board*/
    inputBoard(x, y, board, iniBoard);
    do{
      /* Sleep for a short time */
      SDL_Delay(MILLISECONDDELAY);
      SDL_RenderClear(sw.renderer);   
      /* Draw the actual board */
      drawBoard(iniBoard, sw, rectangle, x, y);      
      /* Update window */
      SDL_RenderPresent(sw.renderer);
      SDL_UpdateWindowSurface(sw.win); 
      /* Get the neighbours' status */
      getNeighbours(x, y, iniBoard, status);
      /* Calculate next generation */
      nextGen(x, y, iniBoard, status);
      Neill_SDL_Events(&sw);
    }while(!sw.finished);
    /* Clear up graphics subsystems */
    atexit(SDL_Quit);
  }
  return 0;
}
Ejemplo n.º 3
0
		BOARD inputBoard()
		{
			BOARD board(HEIGHT, vector<int>(WIDTH));
			inputBoard(board);
			return board;
		}