forked from dsanno/Klondike-Solver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Solitaire.h
103 lines (94 loc) · 2.6 KB
/
Solitaire.h
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
#ifndef Solitaire_h
#define Solitaire_h
#include <memory>
#include <mutex>
#include <stack>
#include <string>
#include "Card.h"
#include "HashMap.h"
#include "Move.h"
#include "Pile.h"
#include "Random.h"
using namespace std;
enum SolveResult {
CouldNotComplete = -2,
SolvedMayNotBeMinimal = -1,
Impossible = 0,
SolvedMinimal = 1
};
struct MoveValue {
Move move;
int value;
};
class Solitaire {
private:
Move movesMade[512];
Pile piles[13];
Card cards[52];
Move movesAvailable[32];
MoveValue moveValue[100];
int moveValueCount;
Random random;
int drawCount, roundCount, maxRoundCount;
int foundationCount, movesAvailableCount, movesMadeCount;
int FoundationMin();
int GetTalonCards(Card talon[], int talonMoves[]);
public:
void Initialize();
int Shuffle1(int dealNumber = -1);
void Shuffle2(int dealNumber);
void ResetGame();
void ResetGame(int drawCount, int maxRoundCount = 11);
void UpdateAvailableMoves();
void MakeAutoMoves();
void MakeMove(Move move);
void MakeMove(int index);
void UndoMove();
SolveResult SolveMinimalMultithreaded(int numThreads, int maxClosedCount);
SolveResult SolveMinimal(int maxClosedCount);
SolveResult SolveFast(int maxClosedCount, int twoShift, int threeShift);
SolveResult SolveRandom(int numberOfTimesToPlay, int solutionsToFind);
int MovesAvailableCount();
int MovesMadeCount();
int MovesMadeNormalizedCount();
int FoundationCount();
int RoundCount();
int DrawCount();
int MovesAdded(Move const &move);
int MinimumMovesLeft();
void SetMaxRoundCount(int maxRoundCount);
void SetDrawCount(int drawCount);
HashKey GameState();
string GetMoveInfo(Move move);
bool sampleGames(const int initialValues[], int sampleCount, int values[],
int dealNumber = -1);
bool setCards(const int values[], const int sizes[]);
bool LoadSolitaire(string const &cardSet);
string GetSolitaire();
bool LoadPysol(string const &cardSet);
string GetPysol();
Move GetMoveAvailable(int index);
Move GetMoveMade(int index);
string GameDiagram();
string GameDiagramPysol();
string MovesMade();
string MovesAvailable();
Move operator[](int index);
int MoveValueCount();
MoveValue GetMoveValue(int i);
};
class SolitaireWorker {
private:
stack<shared_ptr<MoveNode>> open[512];
Move bestSolution[512];
Solitaire *solitaire;
mutex mtx;
int openCount, maxFoundationCount, bestSolutionMoveCount, startMoves,
maxClosedCount;
void RunMinimalWorker(void *closed);
void RunFastWorker();
public:
SolitaireWorker(Solitaire &solitaire, int maxClosedCount);
SolveResult Run(int numThreads);
};
#endif