-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
50 lines (45 loc) · 1.79 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include <fstream>
#include "MurmurHash64.hpp"
#include "Board.hpp"
#include "SimpleXml.hpp"
#include "BfsSolver.hpp"
#include "BranchBoundSolver.hpp"
int main(int argc, char** argv) {
if (argc != 2) {
std::cout<<"Specify a path"<<std::endl;
exit(1);
}
std::cout<<argv[1]<<std::endl;
std::ifstream t(argv[1]);
std::string xml((std::istreambuf_iterator<char>(t)), std::istreambuf_iterator<char>());
size_t pos = 0;
SimpleXml::consume("<?xml version=\"1.0\" encoding=\"utf-8\" ?>", xml, pos);
SimpleXml::skipWhitespace(xml, pos);
SimpleXml::consume("<levels>", xml, pos);
size_t indexInFile = 0;
while (true) {
indexInFile++;
auto [levelNr, color, modifier, hasSolution] = SimpleXml::parseBoardXml(xml, pos);
std::cout<<"# Level "<<indexInFile<<" (id "<<levelNr<<")"<<std::endl;
if (hasSolution) {
std::cout<<"# Has solution"<<std::endl;
//continue;
}
Board board = Board::from(color, modifier);
//Board solvedBoard = solveBFS(levelNr, board);
Board solvedBoard = solveBranchAndBound(levelNr, board);
if (!solvedBoard.isSolved()) {
std::cout<<"# Unable to solve "<<levelNr<<std::endl;
board.print();
} else {
std::cout<<"# Solved with "<<solvedBoard.moveSequence.n<<" moves: "
<<solvedBoard.moveSequence.toString()<<std::endl;
board.print();
std::string levelnr = "<level number=\""+std::to_string(levelNr)+"\"";
std::string replacement = " solution=\""+solvedBoard.moveSequence.toString()+"\"";
std::cout<<"sed -i 's/"<<levelnr<<"/"<<levelnr<<"\\n"<<replacement<<"/' levels.xml";
}
std::cout<<std::endl;
}
}