~ubuntu-branches/ubuntu/quantal/kdegames/quantal

« back to all changes in this revision

Viewing changes to ksudoku/engine/ruleset.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-12-15 14:17:50 UTC
  • mfrom: (1.3.14)
  • Revision ID: package-import@ubuntu.com-20111215141750-6tj6brf4azhrt915
Tags: 4:4.7.90-0ubuntu1
new upstream beta release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include "ruleset.h" 
2
 
 
3
 
#include <iostream>
4
 
 
5
 
#include "constraint.h"
6
 
#include "problem.h"
7
 
 
8
 
/**
9
 
 * \class Graph
10
 
 *
11
 
 * \brief Graph represents the topology and the rules of a puzzle.
12
 
 *
13
 
 */
14
 
 
15
 
/**
16
 
 * \fn int Graph::valueCount() const
17
 
 *
18
 
 * Returns the maximum of different values.
19
 
 */
20
 
 
21
 
/**
22
 
 * \fn int Graph::maxValue(int index) const
23
 
 *
24
 
 * Returns the maximum value for cell \a index.
25
 
 * Currently same as valueCount()
26
 
 */
27
 
 
28
 
/**
29
 
 * \fn int Graph::sizeX() const
30
 
 *
31
 
 * Returns the width of the game.
32
 
 */
33
 
 
34
 
/**
35
 
 * \fn int Graph::sizeY() const
36
 
 *
37
 
 * Returns the height of the game.
38
 
 */
39
 
 
40
 
/**
41
 
 * \fn int Graph::index(int x, int y) const
42
 
 *
43
 
 * Returns the index of the cell at (\a x, \a y).
44
 
 */
45
 
 
46
 
/**
47
 
 * \fn int Graph::size() const
48
 
 *
49
 
 * Returns the count of cells in the gamefield.
50
 
 */
51
 
 
52
 
/**
53
 
 * \fn int Graph::markerStart(int index) const
54
 
 *
55
 
 * Returns the position of cell \a index relative to the internal cache.
56
 
 */
57
 
 
58
 
/**
59
 
 * \fn QVector<const ConstraintHelper*>& helpers() const
60
 
 *
61
 
 * Returns the list of helpers.
62
 
 */
63
 
 
64
 
/**
65
 
 * \fn QVector<int> affectedHelpers(int node) const
66
 
 *
67
 
 * Returns the list of helpers that need to be (re)checked after
68
 
 * changing \a node.
69
 
 */
70
 
 
71
 
/**
72
 
 * Constructs a new graph with the width \a sizeX, height \a sizeY,
73
 
 * and support for \a values different values at maximum.
74
 
 */
75
 
Ruleset::Ruleset() {
76
 
}
77
 
 
78
 
/**
79
 
 * Destructs the graph.
80
 
 */
81
 
Ruleset::~Ruleset() {
82
 
        QVector<Item*>::iterator it;
83
 
        for(it = m_items.begin(); it != m_items.end(); ++it) {
84
 
                delete *it;
85
 
        }
86
 
}
87
 
 
88
 
/**
89
 
 * \internal
90
 
 */
91
 
void Ruleset::addHelper(ConstraintHelper* helper) {
92
 
        int pos = m_helpers.size();
93
 
        m_helpers << helper;
94
 
 
95
 
        foreach(Item *item, helper->constraint()->affectedItems()) {
96
 
                item->addAffectingHelper(helper);
97
 
                helper->index = pos;
98
 
        }
99
 
}
100
 
 
101
 
/**
102
 
 * Adds \a item to the graph
103
 
 *
104
 
 * \a item is owned by graph and will be deleted at destruction.
105
 
 */
106
 
void Ruleset::addItem(Item *item) {
107
 
        item->setParent(this);
108
 
        m_items << item;
109
 
}
110
 
 
111
 
QVector<Storage*> Ruleset::storages() const {
112
 
        return m_storages;
113
 
}
114
 
 
115
 
Storage *Ruleset::storage(int id) {
116
 
        return m_storages[id];
117
 
}
118
 
 
119
 
const Storage *Ruleset::storage(int id) const {
120
 
        return m_storages[id];
121
 
}
122
 
 
123
 
int Ruleset::storageId(const QByteArray &name) const {
124
 
        return m_storageIds.value(name, -1);
125
 
}
126
 
 
127
 
int Ruleset::regStorage(const QByteArray &name, Storage *storage) {
128
 
        Q_ASSERT(!m_storageIds.contains(name));
129
 
        Q_ASSERT(storage->storageId() < 0);
130
 
        int id = m_storages.count();
131
 
        m_storages << storage;
132
 
        m_storageIds.insert(name, id);
133
 
        storage->setStorageId(id);
134
 
        return id;
135
 
}
136
 
 
137
 
#include "ruleset.moc"