~ubuntu-branches/ubuntu/raring/qgo/raring

« back to all changes in this revision

Viewing changes to src/group.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin A. Godisch
  • Date: 2005-01-01 23:07:10 UTC
  • Revision ID: james.westby@ubuntu.com-20050101230710-fhng6yidm47xlb2i
Tags: upstream-1.0.0-r2
ImportĀ upstreamĀ versionĀ 1.0.0-r2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * group.cpp
 
3
 */
 
4
 
 
5
#include "group.h"
 
6
#include "stone.h"
 
7
#include "defines.h"
 
8
 
 
9
Group::Group()
 
10
{
 
11
    liberties = 0;
 
12
    setAutoDelete(FALSE);
 
13
}
 
14
 
 
15
int Group::compareItems(Item d1, Item d2)
 
16
{
 
17
        Stone *s1 = static_cast<Stone*>(d1);
 
18
        Stone *s2 = static_cast<Stone*>(d2);
 
19
 
 
20
        CHECK_PTR(s1);
 
21
        CHECK_PTR(s2);
 
22
 
 
23
        if (s1->posX() == s2->posX() &&
 
24
            s1->posY() == s2->posY() &&
 
25
            s1->getColor() == s2->getColor())
 
26
                return 0;
 
27
 
 
28
        return 1;
 
29
}
 
30
 
 
31
bool Group::isAttachedTo(Stone *s)
 
32
{
 
33
    CHECK_PTR(s);
 
34
 
 
35
    int stoneX = s->posX(),
 
36
              stoneY = s->posY(),
 
37
              x, y;
 
38
    StoneColor col = s->getColor(), c;
 
39
    Stone *tmp;
 
40
 
 
41
    if (isEmpty())
 
42
                return false;
 
43
 
 
44
    for (unsigned int i=0; i<count(); i++)
 
45
    {
 
46
                tmp = at(i);
 
47
                x = tmp->posX();
 
48
                y = tmp->posY();
 
49
                c = tmp->getColor();
 
50
                if (((stoneX == x && (stoneY == y-1 || stoneY == y+1)) ||
 
51
                         (stoneY == y && (stoneX == x-1 || stoneX == x+1))) &&
 
52
                         c == col)
 
53
                        return true;
 
54
    }    
 
55
    
 
56
    return false;
 
57
}
 
58
 
 
59
#ifndef NO_DEBUG
 
60
void Group::debug()
 
61
{
 
62
        qDebug(QString("Count: %1").arg(count()));
 
63
        Stone *s;
 
64
 
 
65
        QListIterator<Stone> it(*this);
 
66
 
 
67
        for (; it.current(); ++it)
 
68
        {
 
69
                s = it.current();
 
70
                qDebug(" (%d, %d) %s", s->posX(), s->posY(),
 
71
                s->getColor() == stoneBlack ? "B" : "W");
 
72
    }   
 
73
}
 
74
#endif