Source Code (Use browser search to find items of interest.)
Class Index
kabalone'MoveList (./kdegames/kabalone/Move.h:57)
class MoveList
{
public:
MoveList();
static const int MaxMoves = 84;
/* for isElement: search for moves starting with 1/2/3 fields */
enum { all , start1, start2, start3 };
void clear();
void insert(Move);
bool isElement(int f);
bool isElement(Move&, int startType, bool del=false);
void insert(short f, char d, Move::MoveType t)
{ insert( Move(f,d,t) ); }
int getLength()
{ return nextUnused; }
bool getNext(Move&,int maxType); /* returns false if no more moves */
private:
Move move[MaxMoves];
int next[MaxMoves];
int first[Move::typeCount];
int last[Move::typeCount];
int actual[Move::typeCount];
int nextUnused, actualType;
};
kabalone'MoveList::MoveList() (./kdegames/kabalone/Move.cpp:69)
MoveList::MoveList()
{
clear();
}
kabalone'MoveList::clear() (./kdegames/kabalone/Move.cpp:74)
void MoveList::clear()
{
int i;
for(i=0;i<Move::typeCount;i++)
first[i] = actual[i] = -1;
nextUnused = 0;
actualType = -1;
}
kabalone'MoveList::insert() (./kdegames/kabalone/Move.cpp:85)
void MoveList::insert(Move m)
{
int t = m.type;
/* valid and possible ? */
if (t <0 || t >= Move::typeCount) return;
if (nextUnused == MaxMoves) return;
assert( nextUnused < MaxMoves );
/* adjust queue */
if (first[t] == -1) {
first[t] = last[t] = nextUnused;
}
else {
assert( last[t] < nextUnused );
next[last[t]] = nextUnused;
last[t] = nextUnused;
}
next[nextUnused] = -1;
move[nextUnused] = m;
nextUnused++;
}
kabalone'MoveList::isElement() (./kdegames/kabalone/Move.cpp:110)
bool MoveList::isElement(int f)
{
int i;
for(i=0; i<nextUnused; i++)
if (move[i].field == f)
return true;
return false;
}
kabalone'MoveList::isElement() (./kdegames/kabalone/Move.cpp:122)
bool MoveList::isElement(Move &m, int startType,bool del)
{
int i;
for(i=0; i<nextUnused; i++) {
Move& mm = move[i];
if (mm.field != m.field)
continue;
/* if direction is supplied it has to match */
if ((m.direction > 0) && (mm.direction != m.direction))
continue;
/* if type is supplied it has to match */
if ((m.type != Move::none) && (m.type != mm.type))
continue;
if (m.type == mm.type) {
/* exact match; eventually supply direction */
m.direction = mm.direction;
if (del) mm.type = Move::none;
return true;
}
switch(mm.type) {
case Move::left3:
case Move::right3:
if (startType == start3 || startType == all) {
m.type = mm.type;
m.direction = mm.direction;
if (del) mm.type = Move::none;
return true;
}
break;
case Move::left2:
case Move::right2:
if (startType == start2 || startType == all) {
m.type = mm.type;
m.direction = mm.direction;
if (del) mm.type = Move::none;
return true;
}
break;
default:
if (startType == start1 || startType == all) {
/* unexact match: supply type */
m.type = mm.type;
m.direction = mm.direction;
if (del) mm.type = Move::none;
return true;
}
}
}
return false;
}
kabalone'MoveList::getNext() (./kdegames/kabalone/Move.cpp:179)
bool MoveList::getNext(Move& m, int maxType)
{
if (actualType == Move::typeCount) return false;
while(1) {
while(actualType < 0 || actual[actualType] == -1) {
actualType++;
if (actualType == Move::typeCount) return false;
actual[actualType] = first[actualType];
if (actualType > maxType) return false;
}
m = move[actual[actualType]];
actual[actualType] = next[actual[actualType]];
if (m.type != Move::none) break;
}
return true;
}