-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel-check.cpp
54 lines (45 loc) · 1.35 KB
/
model-check.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
51
52
53
54
#include <iostream>
#include <vector>
#include <iomanip>
#include "tictactoe.hpp"
#include "model.hpp"
using namespace std;
using namespace afg::model;
int main(int argc, char **argv) {
TicTacToe ttt(3);
vector<function<bool(const TicTacToe&)>> predicates;
/* Predicate #1: Find TTT states that look like this:
* o | o |
* -----------
* | o |
* -----------
* | |
*/
predicates.push_back(
[](const TicTacToe& st) {
return (st.b.board[0][0] == 'o'
&& st.b.board[0][1] == 'o'
&& st.b.board[1][1] == 'o');
}
);
/* Predicate #2: Find a TTT state where Player1 ('o') wins */
predicates.push_back(
[](const TicTacToe& st) {
return st.b.isWinner() && (st.getTurnParity() == 0);
}
);
/* Print all boards that match predicate #1 */
auto res = bfsFind(ttt, predicates[0], 10);
for (const auto& ttt : res.matches) {
string repr;
for (auto& row : ttt.b.board) {
for (auto& c : row) {
repr += c;
}
}
cout << repr << endl;
}
cout << "Count: " << res.matches.size() << endl;
/* Check if it's possible to satisfy predicate #1 and #2 in 7 moves */
cout << "Reachable?: " << pathExists(ttt, predicates, 7) << endl;
}