Ejemplo n.º 1
0
// ==========================================================================
int main(int argc, char *argv[]) {

  std::string filename;
  int rows = -1;
  int columns = -1;
  bool all_solutions = false;
  bool allow_rotations = false;
  HandleCommandLineArguments(argc, argv, filename, rows, columns, all_solutions, allow_rotations);


  // load in the tiles
  std::vector<Tile*> tiles;
  ParseInputFile(argc,argv,filename,tiles);
	//if no board dimension entered, set the columns to 1/2 the number of tiles
	//this assumes the solutions won't be a straight line, but saves a lot of work
	if (rows<1 && columns<1) {
		rows=tiles.size()/2;
		columns=tiles.size()/2;
		if (tiles.size()%2==1) rows++;columns++;
	}
  // confirm the specified board is large enough
  if (rows < 1  ||  columns < 1  ||  rows * columns < tiles.size()) {
    std::cerr << "ERROR: specified board is not large enough" << rows << "X" << columns << "=" << rows*columns << " " << tiles.size() << std::endl;
    usage(argc,argv);
  }
	Board board(rows,columns);
    std::vector<Location> locations;//creates the base vector and board,then runs the function
	FindSolutionDriver(board,tiles,locations,all_solutions,allow_rotations);
	
  // delete the tiles
  for (int t = 0; t < tiles.size(); t++) {
    delete tiles[t];
  }
}
Ejemplo n.º 2
0
int _CRTAPI1 main(
    int argc,
    char *argv[])
{
    //
    //  Parse the command line.
    //  Open input file.
    //
    if (ParseCmdLine(argc, argv))
    {
        return (1);
    }

    //
    //  Parse the input file.
    //  Close the input file.
    //
    if (ParseInputFile())
    {
        fclose(pInputFile);
        return (1);
    }
    fclose(pInputFile);

    //
    //  Return success.
    //
    return (0);
}
Ejemplo n.º 3
0
int main(int argc, char **argv)
{
    if (argc != 2) {
        fprintf(stderr, "Usage: %s PATH\n", argv[0]);
        return 1;
    }

    FileLineReader reader(argv[1]);
    if (reader.error()) {
        fprintf(stderr, "Failed to open input file\n");
        return 1;
    }

    InputConfig config;
    ParseInputFile(config, reader);

    for (unsigned mode = 0; mode < config.mode_map_count; ++mode) {
        _tprintf(_T("Mode '%s'\n"), config.mode_map[mode]);

        for (unsigned key = 0; key < InputConfig::MAX_KEY; ++key) {
            unsigned event = config.Key2Event[mode][key];
            assert(event < InputConfig::MAX_EVENTS);
            if (event == 0)
                continue;

            printf("  Key 0x%x\n", key);
            do {
                Dump(config.Events[event], event);
                assert(config.Events[event].next < InputConfig::MAX_EVENTS);
                event = config.Events[event].next;
            } while (event > 0);
        }

        for (unsigned i = 0; i < Menu::MAX_ITEMS; ++i) {
            const MenuItem &mi = config.menus[mode][i];
            if (mi.defined()) {
                _tprintf(_T("  Menu[%u] = '%s'\n"), i, mi.label);
                unsigned event = mi.event;
                assert(event < InputConfig::MAX_EVENTS);
                do {
                    Dump(config.Events[event], event);
                    assert(config.Events[event].next < InputConfig::MAX_EVENTS);
                    event = config.Events[event].next;
                } while (event > 0);
            }
        }
    }

    return 0;
}
Ejemplo n.º 4
0
int main(int argc, char **argv)
{
  Args args(argc, argv, "PATH");
  const char *path = args.ExpectNext();
  args.ExpectEnd();

  FileLineReader reader(path);
  if (reader.error()) {
    fprintf(stderr, "Failed to open input file\n");
    return 1;
  }

  InputConfig config;
  config.SetDefaults();
  ParseInputFile(config, reader);

  for (unsigned mode = 0; mode < config.modes.size(); ++mode) {
    _tprintf(_T("Mode '%s'\n"), config.modes[mode].c_str());

    for (unsigned key = 0; key < InputConfig::MAX_KEY; ++key) {
      unsigned event = config.Key2Event[mode][key];
      assert(event < InputConfig::MAX_EVENTS);
      if (event == 0)
        continue;

      printf("  Key 0x%x\n", key);
      do {
        Dump(config.events[event], event);
        assert(config.events[event].next < InputConfig::MAX_EVENTS);
        event = config.events[event].next;
      } while (event > 0);
    }

    for (unsigned i = 0; i < Menu::MAX_ITEMS; ++i) {
      const MenuItem &mi = config.menus[mode][i];
      if (mi.IsDefined()) {
        _tprintf(_T("  Menu[%u] = '%s'\n"), i, mi.label);
        unsigned event = mi.event;
        assert(event < InputConfig::MAX_EVENTS);
        do {
          Dump(config.events[event], event);
          assert(config.events[event].next < InputConfig::MAX_EVENTS);
          event = config.events[event].next;
        } while (event > 0);
      }
    }
  }

  return 0;
}
Ejemplo n.º 5
0
// ==========================================================================
int main(int argc, char *argv[]) {

  std::string filename;
  int rows = -1;
  int columns = -1;
  bool all_solutions = false;
  bool allow_rotations = false;
  HandleCommandLineArguments(argc, argv, filename, rows, columns, all_solutions, allow_rotations);


  // load in the tiles
  std::vector<Tile*> tiles;
  ParseInputFile(argc,argv,filename,tiles);


  // confirm the specified board is large enough
  if (rows < 1  ||  columns < 1  ||  rows * columns < tiles.size()) {
    std::cerr << "ERROR: specified board is not large enough" << rows << "X" << columns << "=" << rows*columns << " " << tiles.size() << std::endl;
    usage(argc,argv);
  }


  //for (int i = 0; i < 5; i++) {

    // generate a random tile layouts
    Board board(rows,columns);
    std::vector<Location> locations;
    //RandomlyPlaceTiles(board, tiles, locations);
    PrintPieces(board, tiles, locations, all_solutions, allow_rotations);
    
    // print the solution
    //std::cout << "probably-not-a-Solution: ";
    // for (int i = 0; i < locations.size(); i++) {
    //   std::cout << locations[i];
    // }
    // std::cout << std::endl;

    // print the ASCII art board representation
    //board.Print();
    //std::cout << std::endl;
  //}

  
  // delete the tiles
  for (int t = 0; t < tiles.size(); t++) {
    delete tiles[t];
  }
}