-
Notifications
You must be signed in to change notification settings - Fork 0
/
tile.h
91 lines (77 loc) · 1.92 KB
/
tile.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
/**
* @file tile.h
* @author DSN
* @brief Defines a unit \c Tile of a \c Board
* @version 0.1
* @date 2023-10-12
*/
#ifndef TILE_H
#define TILE_H
#include "direction.h"
#include <iostream>
class Tile
{
public:
using Number = std::size_t;
private:
/**
* @brief The number the tile displays.
*/
Number m_num;
/**
* @brief The number the tile is supposed to show if it were in its correct position.
*/
Number m_correctNum;
public:
/**
* @brief Construct a \c Tile given a number
*
* @param num: the number to be assigned to the tile; by default, it's zero.
*/
explicit Tile(Number num = 0) : m_num{ num }, m_correctNum{ num }
{
}
/**
* @brief Get the number corresponding to the tile
*
* @return the tile number
*/
Number getNum() const;
/**
* @brief Get the tile's "correct number" (see \c Number::m_correctNum)
*
* @return Number
*/
Number getCorrectNum() const;
/**
* @brief A tile is empty if its number is 0.
*
* @return true: the tile is non-empty
* @return false: it's empty
*/
operator bool() const;
/**
* @brief Check if the tile is in its correct position or not
*
* @return true: If the tile displays the "correct number"
* @return false
*/
bool isCorrectPosition() const;
/**
* @brief Swap two tiles.
* @details We swap only the numbers they display so that their correctness can be maintained.
*
* @param a
* @param b
*/
friend void swapTiles(Tile& a, Tile& b);
};
/**
* @brief Display a tile
*
* @param out: output stream (typically, \c std::cout )
* @param tile: a \c Tile object
* @return std::ostream&: a reference to \c out (to allow chaining of \c operator<< )
*/
std::ostream& operator<<(std::ostream& out, const Tile& tile);
#endif