Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

CSC112 Spring 2016 Examples

2370 views
1
// Implementation of the CrossFour Puzzle
2
#ifndef CROSSFOUR_H
3
#define CROSSFOUR_H
4
5
#include "widget.h"
6
#include "peg.h"
7
#include "backtrack.h"
8
#include <vector>
9
10
class CrossFour : public Widget
11
{
12
public:
13
14
//reset the puzzle to starting position
15
virtual void reset();
16
17
//constructors and destructors
18
CrossFour();
19
CrossFour(int x, int y);
20
~CrossFour();
21
22
//display our puzzle
23
virtual void display();
24
25
//cursor movements
26
virtual void left();
27
virtual void right();
28
29
//perform a move
30
virtual bool move();
31
32
//autosolve
33
virtual void solve();
34
35
private:
36
std::vector<Peg*> pegs;
37
int cx; //peg the cursor is on
38
int sx; //selected peg for the move (-1 if no selection)
39
40
void displayState(char state[]);
41
42
class Solver : public MoveState
43
{
44
public:
45
Solver(CrossFour *puzzle);
46
Solver(CrossFour *puzzle, char state[], int movedPeg); // moved peg is the peg we are moving
47
48
virtual bool reject();
49
virtual bool accept();
50
virtual MoveState* next();
51
52
//move "memory"
53
virtual MoveState* before();
54
virtual MoveState* after();
55
56
57
char state[9];
58
int movedPeg;
59
int nextTrial;
60
Solver *_before;
61
Solver *_after;
62
CrossFour *puzzle;
63
};
64
};
65
66
#endif
67