-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.php
executable file
·47 lines (40 loc) · 1.91 KB
/
main.php
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
<?php
/**
* @author: Alejandro Martínez Peregrina
* @date: 8/01/19
*/
require __DIR__ . '/init.php';
use TalentedPanda\PuzzleProblem\DependencyInjection\ContainerLoader;
use TalentedPanda\PuzzleProblem\Model\Exception\NonExistentPieceException;
use TalentedPanda\PuzzleProblem\Model\Exception\NonValidFilePathException;
use TalentedPanda\PuzzleProblem\Model\Exception\NonValidPieceException;
use TalentedPanda\PuzzleProblem\Model\Exception\NonValidPiecesBagException;
try {
printf("Welcome to the Puzzle Solver Application, made using blacktrack algorithm. \n");
printf("Puzzles are located by default in: '" . ContainerLoader::instance()->getParameter('default_puzzle_path') . "'.\n");
printf("If you want to add any new puzzle, please copy to this folder and give it '.txt' extension. \n");
printf("Please, write the name of the file to solve the puzzle (without extension, i.e: '5x5'):");
$fileName = trim(fgets(STDIN));
$input = (ContainerLoader::instance()->get(
'talented_panda.puzzle_problem.service.input_handler'
)->handle($fileName));
print_r("\nSolving the puzzle...please be patient. \n");
$response = ContainerLoader::instance()->get(
'talented_panda.puzzle_problem.controller.puzzle'
)->solvePuzzleFromInputAction($input);
} catch (NonValidFilePathException $nonValidFilePathException) {
printf($nonValidFilePathException->getMessage());
exit;
} catch (NonValidPiecesBagException $nonValidPiecesBagException) {
print_r($nonValidPiecesBagException->getMessage() . "\n");
exit;
} catch (NonExistentPieceException $nonExistentPieceException) {
print_r($nonExistentPieceException->getMessage() . "\n");
exit;
} catch (NonValidPieceException $nonValidPieceException) {
print_r($nonValidPieceException->getMessage() . "\n");
exit;
} catch (Exception $exception) {
printf("\n\nAn error was occurred while trying to load any service.");
exit;
}