~ubuntu-branches/ubuntu/utopic/picmi/utopic

« back to all changes in this revision

Viewing changes to src/logic/streaks.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2012-12-03 17:39:47 UTC
  • Revision ID: package-import@ubuntu.com-20121203173947-tt1kk5wp92zk1f2z
Tags: upstream-4.9.90
ImportĀ upstreamĀ versionĀ 4.9.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* *************************************************************************
 
2
 *  Copyright 2012 Jakob Gruber <jakob.gruber@gmail.com>                   *
 
3
 *                                                                         *
 
4
 *  This program is free software: you can redistribute it and/or modify   *
 
5
 *  it under the terms of the GNU General Public License as published by   *
 
6
 *  the Free Software Foundation, either version 2 of the License, or      *
 
7
 *  (at your option) any later version.                                    *
 
8
 *                                                                         *
 
9
 *  This program is distributed in the hope that it will be useful,        *
 
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
 
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
 
12
 *  GNU General Public License for more details.                           *
 
13
 *                                                                         *
 
14
 *  You should have received a copy of the GNU General Public License      *
 
15
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.  *
 
16
 ************************************************************************* */
 
17
 
 
18
#ifndef STREAKS_H
 
19
#define STREAKS_H
 
20
 
 
21
#include <QVector>
 
22
#include <QSharedPointer>
 
23
 
 
24
#include "boardmap.h"
 
25
#include "boardstate.h"
 
26
 
 
27
/* Moved from streaks.cpp to work around QSharedPointer issues with forward declarations.
 
28
 * TODO: move this back once when Qt 5 is used. */
 
29
struct LineInfo {
 
30
    LineInfo(const QVector<Board::State> &l);
 
31
 
 
32
    int box_count;
 
33
    int cross_count;
 
34
    QVector<int> streaks_regular;
 
35
    QVector<int> streaks_reversed;
 
36
    QVector<Board::State> line;
 
37
};
 
38
 
 
39
class Streaks
 
40
{
 
41
public:
 
42
    struct StreakElement {
 
43
        int value;
 
44
        bool solved;
 
45
    };
 
46
 
 
47
    Streaks(QSharedPointer<BoardMap> map, QSharedPointer<BoardState> state);
 
48
 
 
49
    /* Updates streaks affected by changes to (x,y). */
 
50
    void update(int x, int y);
 
51
 
 
52
    /* Updates streaks, taking the entire board into account. */
 
53
    void update();
 
54
 
 
55
    /* Returns the request row/col streak. These contain the least information required by
 
56
       the frontend, which is (for each position within a streak): "which number is this",
 
57
       and "is this position solved" */
 
58
    QVector<QSharedPointer<Streaks::StreakElement> > getRowStreak(int y) const;
 
59
    QVector<QSharedPointer<Streaks::StreakElement> > getColStreak(int x) const;
 
60
 
 
61
private:
 
62
 
 
63
    void calcMapStreaks();
 
64
 
 
65
 
 
66
    QSharedPointer<BoardMap> m_map;
 
67
    QSharedPointer<BoardState> m_state;
 
68
 
 
69
    QVector<QVector<int> > m_map_row_streaks;
 
70
    QVector<QVector<int> > m_map_col_streaks;
 
71
 
 
72
    QVector<QSharedPointer<LineInfo> > m_state_row_streaks;
 
73
    QVector<QSharedPointer<LineInfo> > m_state_col_streaks;
 
74
};
 
75
 
 
76
#endif // STREAKS_H