~ubuntu-branches/ubuntu/trusty/picmi/trusty-proposed

« back to all changes in this revision

Viewing changes to src/logic/picmi.cpp

  • Committer: Package Import Robot
  • Author(s): Rohan Garg
  • Date: 2013-06-21 02:02:30 UTC
  • mfrom: (1.2.3)
  • Revision ID: package-import@ubuntu.com-20130621020230-amlvc60a8dgm4vz9
Tags: 4:4.10.80-0ubuntu1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
167
167
    return coord;
168
168
}
169
169
 
 
170
QPoint Picmi::hint()
 
171
{
 
172
    QVector<QPoint> empty_cells;
 
173
    for (int x = 0; x != width(); ++x) {
 
174
        for (int y = 0; y != height(); ++y) {
 
175
            if (stateAt(x, y) == Board::Nothing) {
 
176
                empty_cells.push_back(QPoint(x, y));
 
177
            }
 
178
        }
 
179
    }
 
180
 
 
181
    if (empty_cells.size() == 0) {
 
182
        return QPoint(0, 0);
 
183
    }
 
184
 
 
185
    const int idx = rand() % empty_cells.size();
 
186
    const QPoint cell(empty_cells.at(idx));
 
187
    Board::State state = m_map->get(cell.x(), cell.y());
 
188
    if (state == Board::Nothing) {
 
189
        state = Board::Cross;
 
190
    }
 
191
 
 
192
    setState(cell.x(), cell.y(), state);
 
193
    m_timer.addPenaltyTime();
 
194
    return cell;
 
195
}
 
196
 
170
197
KScoreDialog::FieldInfo Picmi::endGame() {
171
198
    m_timer.stop();
172
199