-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboard.h
74 lines (53 loc) · 2.27 KB
/
board.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
#ifndef BOARD_H
#define BOARD_H
#include <iostream>
#include <map>
class Board
{
public:
// Init a board of given dimension (size = dim^2) and
// scramble it with numInitMoves by moving
// the space tile with a randomly chosen direction N, W, S, E
// some of which may be invalid, in which case we skip that move
Board(int dim, int numInitMoves, int seed);
// ****** Add a copy constructor, destructor, etc. if you need them ****** //
Board(const Board &obj);
~Board();
// Swaps the blank with the specified tile value
void move(int tile);
// Generate potential moves and fill in the map with
// Key=tile, Value=Ptr to corresponding Board
// Clear the moveMap as the first order of business.
//void potentialMoves(map<int, Board*> &moveMap);
std::map<int, Board*> potentialMoves() const;
// Returns true if the board is solved, false otherwise
bool solved() const;
//---------- Operators --------------//
// Prints the board in the desired 2D format (utilizes printRowBanner())
friend std::ostream& operator<<(std::ostream &os, const Board &b);
// Checks if this board is less-than another. We define less than
// as a "string-style" comparison of the tile array (i.e. Starting by comparing
// the 0-th tile in this Board and the other.
// If this board's tile is less than the other board's tile value, return true
// If they are equal, continue with the next tile location and repeat
bool operator<(const Board& rhs) const;
//sets one board equal to another;
Board& operator=(const Board &rhs);
//---------- Accessors --------------//
// Returns the tile value at location, loc
// Let's a user treat the board object like an array to get a tile value
// at a given index
int const & operator[](int loc) const;
// Returns the size of the tiles array
int size() const;
// Returns the dimension of the board (i.e. sqrt(size) )
int dim() const;
private:
// Prints the row banner at the top, bottom, and in between tile rows
void printRowBanner(std::ostream& os) const;
// Do not modify...use these as your data members. No vectors/lists/dequees
// we want you to manage memory explicitly for the learning experience.
int *tiles_; // Will point to an array
int size_; // Size of the array
};
#endif