new 4475edb243ed4627f4c5f2c470ca40b3def034d4
[tagua/yd.git] / src / core / board.h
blob10caf397566855d2820df5a2098e93ce85cb925f
1 /*
2 Copyright (c) 2007 Paolo Capriotti <p.capriotti@gmail.com>
3 (c) 2007 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 */
11 #ifndef CORE__BOARD_H
12 #define CORE__BOARD_H
14 #include <QStringList>
15 #include <vector>
17 #include "point.h"
18 #include "pathinfo.h"
20 class Piece;
22 // TODO: make Board a component
24 /**
25 * @brief A grid of pieces.
27 * The board class maintains a rectangular grid of Piece objects,
28 * providing methods to access, add, remove and find them.
30 class TAGUA_EXPORT Board {
31 Point m_size;
32 std::vector<Piece> m_data;
33 public:
34 /**
35 * Create a new Board with the given size.
37 explicit Board(const Point& size);
39 /**
40 * Create a Board copying a given one.
42 explicit Board(const Board* other);
44 /**
45 * Compare two boards for equality.
47 bool equals(const Board* other) const;
49 /**
50 * @return Board size.
52 Point size() const;
54 /**
55 * Retrieve a piece from the board.
56 * @param p Coordinates of the piece.
57 * @return Pointer to the piece at that square, or NULL, if the square is out of the board.
59 Piece* get(const Point& p);
60 const Piece* get(const Point& p) const;
62 /**
63 * Add a piece to the board.
64 * @param p Coordinates of the piece.
65 * @param piece The piece to add.
66 * @note This function does nothing if @a p is out of the board.
68 void set(const Point& p, const Piece& piece);
70 /**
71 * @return Whether @a p is a valid board square.
73 bool valid(const Point& p) const;
75 /**
76 * @return Information on the path joining @a from and @a to.
78 PathInfo path(const Point& from, const Point& to) const;
80 /**
81 * Searches the board for a given piece.
82 * @return The first square where the piece is found, or an
83 * invalid point, if no such piece exists on the board.
85 Point find(const Piece& piece) const;
87 /**
88 * Coordinates displayed at the board border.
90 QStringList borderCoords() const;
93 #endif // CORE__BOARD_H