aboutsummaryrefslogtreecommitdiff
path: root/src/test/integration_tests/canfield_test.cpp
blob: 406b23a7abdef8d11c8f343d2c0e9c72383abc1a (plain) (blame)
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
129
130
//
// Created by thecharlesblake on 10/4/17.
//

#include <gtest/gtest.h>

#include "../test_helper.h"
#include "../../main/input-output/input/json-parsing/rules_parser.h"
#include "../../main/game/search-state/game_state.h"

using std::vector;

typedef test_helper th;
typedef game_state::streamliner_options so;
typedef std::initializer_list<std::initializer_list<std::string>> string_il;

const static std::string path = "resources/canfield/";
const static std::string type = "simple-canfield";

TEST(Canfield, SimpleSolvable) {
    EXPECT_TRUE(th::is_solvable(path + "SimpleSolvable.json", type));
}

TEST(Canfield, ComplexSolvable) {
    EXPECT_TRUE(th::is_solvable(path + "ComplexSolvable.json", type));
}

TEST(Canfield, SimpleUnsolvable) {
    EXPECT_FALSE(th::is_solvable(path + "SimpleUnsolvable.json", type));
}

TEST(Canfield, ComplexUnsolvable) {
    EXPECT_FALSE(th::is_solvable(path + "ComplexUnsolvable.json", type));
}

TEST(Canfield, FoundationSingleCard) {
    sol_rules sr = rules_parser::from_preset("canfield");
    game_state gs(sr, 0, so::NONE);

    ASSERT_EQ(1, test_helper::cards_in_founds(gs));
}

TEST(Canfield, FoundationWraps) {
    sol_rules sr = rules_parser::from_preset("simple-canfield");

    game_state gs(sr, string_il{
            {"3C"},{},{},{}, // Foundations
            {},{}, // Stock-waste
            {}, // Reserve
            {"AC"},{},{} // Tableau piles
    });

    vector<move> actual_moves = gs.get_legal_moves();
    vector<move> exp_moves = {
            move(move::mtype::regular, 7, 0, 1)
    };

    ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves;
}

TEST(Canfield, MoveWholePile) {
    sol_rules sr = rules_parser::from_preset("simple-canfield");

    game_state gs(sr, string_il{
            {"3C"},{},{},{}, // Foundations
            {},{}, // Stock-waste
            {}, // Reserve
            {"2H","3S","AH"},{"AC"},{"2D"} // Tableau piles
    });

    vector<move> actual_moves = gs.get_legal_moves();
    vector<move> exp_moves = {
            move(move::mtype::built_group, 7, 8, 3)
    };

    ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves;
}

TEST(Canfield, MoveWholePileNotSpace) {
    sol_rules sr = rules_parser::from_preset("simple-canfield");

    game_state gs(sr, string_il{
            {"3C"},{},{},{}, // Foundations
            {},{}, // Stock-waste
            {}, // Reserve
            {"2H","3S","AH"},{},{"2D"} // Tableau piles
    });

    vector<move> actual_moves = gs.get_legal_moves();
    vector<move> exp_moves = {};

    ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves;
}

TEST(Canfield, AutoReserve) {
    sol_rules sr = rules_parser::from_preset("simple-canfield");

    game_state gs(sr, string_il{
            {"3C"},{},{},{}, // Foundations
            {"3D"},{"2D"}, // Stock-waste
            {"3H"}, // Reserve
            {"2H","3S","AH"},{},{"AC"} // Tableau piles
    });

    vector<move> actual_moves = gs.get_legal_moves();
    vector<move> exp_moves = {
            move(move::mtype::regular, 6, 8, 1)
    };

    ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves;
}

TEST(Canfield, AutoReserveThenWaste) {
    sol_rules sr = rules_parser::from_preset("simple-canfield");

    game_state gs(sr, string_il{
            {"3C"},{},{},{}, // Foundations
            {"3D"},{"3H"}, // Stock-waste
            {}, // Reserve
            {"2H","3S","AH"},{},{"AC"} // Tableau piles
    });

    vector<move> actual_moves = gs.get_legal_moves();
    vector<move> exp_moves = {
            move(move::mtype::stock_k_plus, 4, 8, 1),
            move(move::mtype::stock_k_plus, 4, 8, 2),
    };

    ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves;
}