-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolver.hpp
More file actions
128 lines (108 loc) · 2.57 KB
/
solver.hpp
File metadata and controls
128 lines (108 loc) · 2.57 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#pragma once
#include <minisat/core/Solver.h>
#include <vector>
using board = std::vector<std::vector<int>>;
enum Column {
Colour = 0,
Pet,
Beverage,
Cigarettes,
Nationality
};
enum House {
House1 = 0,
House2,
House3,
House4,
House5
};
enum Colour {
White = 0,
Red,
Yellow,
Blue,
Green
};
enum Pet {
Dog = 0,
Bird,
Cat,
Horse,
Fish
};
enum Beverage {
Tea = 0,
Coffee,
Milk,
Beer,
Water
};
enum Cigarettes{
PallMall = 0,
Dunhill,
BlueMaster,
Blend,
Princ
};
enum Nationality {
Brit = 0,
Swede,
Dane,
German,
Norwegian
};
class Solver {
private:
const bool m_write_dimacs = true;
Minisat::Solver solver;
bool transform_to_cnf(Minisat::vec<Minisat::Lit> const& lit_vec1, Minisat::vec<Minisat::Lit> const& lit_vec2);
bool nextTo(int col1, int val1, int col2, int val2);
bool setColValToColVal(int col1, int val1, int col2, int val2);
public:
Solver(bool write_dimacs = false);
bool solve();
board get_solution() const;
void printPretty();
private:
// This is going to be adapted from the Sudoku example.
// Where Sudoku is 9 * 9 with 9 possible values, this riddle
// is 5 * 5 with 5 possible values
void init_variables();
// The functions bellow may remain the same ...
void one_square_one_value();
// ... except this one could be simplified because a row may
// actually may contain identical values ...
void non_duplicated_values();
void exactly_one_true(Minisat::vec<Minisat::Lit> const& literals);
// Riddle rules
// - Brit lives in a red house
bool BritLivesInARedGHouse();
// - Swede has a dog
bool SwedeHasADog();
// - Dane drinks tea
bool DaneDrinksTea();
// - Green house is left of white house
bool GreenLeftOfWhite();
// - Green house’s inhabitant drinks coffee
bool GreenDrinksCoffee();
// - Pall Mall smoker has a bird
bool PallMallHasBird();
// - Yellow house’s inhabitant smokes Dunhill
bool YellowSmokesDunhill();
// - Mid house inhabitant drinks milk
bool MidHouseDrinksMilk();
// - Norwegian lives in the first house
bool NorwegianLivesInTheFirstHouse();
// - Blend smoker lives next to cat owner
bool BlendSmokerNextToCatOwner();
// - Horse owner lives next to Dunhill smoker
bool HorseOwnerNextToDunhillSmoker();
// - Blue Master smoker drinks beer
bool BlueMasterSmokerDrinksBeer();
// - German smokes Prince
bool GermanSmokesPrince();
// - Norwegian lives next to the blue house
bool NorwegianNextToBlue();
// - Blend smoker lives next to water drinker
bool BlendSmokerNextToWaterDrinker();
};