Esempio n. 1
0
bool Puzzle::connect(Piece *p) {
	int dir;
	Piece *neighbor;
	Coord *pos = p->getPos(true);
	bool ret = false;
	float d_angle;
	for(unsigned int i = 0; i < p->getNumNeighbors(); i++) {
		neighbor = p->getNeighbor(i);
		dir = p->getDirection(i);
		d_angle = abs(p->getRotateAngle() - neighbor->getRotateAngle());
		if(d_angle > angle_eps)
			continue;
		switch(dir) {
		case BELOW: 
			if(isInLine(pos, neighbor->getPos(true), BELOW, neighbor->getRotateAngle())) {
				if(!ret)
					join(p, neighbor, BELOW);
				p->removeNeighbor(i);
				neighbor->removeNeighbor(p);
				ret = true;
			}
			break;
		case ABOVE: 
			if(isInLine(pos, neighbor->getPos(true), ABOVE, neighbor->getRotateAngle())) {
				if(!ret)
					join(p, neighbor, ABOVE);
				p->removeNeighbor(i);
				neighbor->removeNeighbor(p);
				ret = true;
			}
			break;
		case RIGHT:
			if(isInLine(pos, neighbor->getPos(true), RIGHT, neighbor->getRotateAngle())) {
				if(!ret)
					join(p, neighbor, RIGHT);
				p->removeNeighbor(i);
				neighbor->removeNeighbor(p);
				ret = true;
			}
			break;
		case LEFT:
			if(isInLine(pos, neighbor->getPos(true), LEFT, neighbor->getRotateAngle())) {
				if(!ret)
					join(p, neighbor, LEFT);
				p->removeNeighbor(i);
				neighbor->removeNeighbor(p);
				ret = true;
			}
			break;
		}
	}
	return ret;
}
Esempio n. 2
0
int				LinearConflict::eval(State const &s) const
{
	size_t		i;
	size_t		n;
	size_t		x;
	int			foundI;
	int			foundX;
	int			result(0);
	tArray const	&map(s.getMap());

	for (i = 0; i < _size * _size; ++i)
	{
		foundI = isInLine(i / _size, map[i]);
		if (foundI > -1)
		{
			for (n = 0; n < _size; ++n)
			{
				x = (i / _size) * _size + n;
				foundX = isInLine(x / _size, map[x]);
				if (foundX > -1 && ((i > x && foundI < foundX)
									|| (x > i && foundX < foundI)))
				{
						result += 2;
				}
			}
		}
		foundI = isInColumn(i % _size, map[i]);
		if (foundI > -1)
		{
			for (n = 0; n < _size; ++n)
			{
				x = n * _size + i % _size;
				foundX = isInColumn(x % _size, map[x]);
				if (foundX > -1	&& ((i > x && foundI < foundX)
									|| (x > i && foundX < foundI)))
				{
						result += 2;
				}
			}
		}
	}
	return (result);
}
Esempio n. 3
0
char moveValidity(TILE t1, TILE t2, TILE board[]) {
    if (posEqual(t1, t2)) return 1; // same spot as we're currently on
    if (!isInLine(t1, t2)) return 2; // tile 2 not directly in line with tile 1
    if (t2.piece != 0) return 3; // tile 2 occupied already
    if (t2.attr == 3) return 8; // tutorial special space
    if (t2.attr != 0 && !(t1.piece==3)) return 4; // this is a "king only" space
    TILE temp = t1;
    while (!posEqual(temp, t2)) {
        if (isInLine(temp, t2) > 0) {
            // y must be changed
            temp.y += temp.y > t2.y ? -1 : 1;
        }
        else {
            temp.x += temp.x > t2.x ? -1 : 1;
        }
        temp = board[temp.y*11 + temp.x];
        if (temp.piece != 0) return 5; // path blocked
    }
    
    return 0; // the move is a valid move
}
Esempio n. 4
0
	int countLine(LineType type, short K, short i, short j) {
		int count = 0;
		short x1, x2, y1, y2;
		line l;

		getBounds(type, K, i, j, &x1, &y1, &x2, &y2);
		l = std::make_tuple(x1, y1, x2, y2);
		if (queriedLines[l] == false) {
			queriedLines[l] = true;
			for (point it : inputPoints) {
				if (isInLine(type, it, K, i, j) == true) {
					count++;
					printf("\t\t[%hd,%hd]: (%hd,%hd) line(%d) found. count=%d\n", i, j, it.first, it.second, type, count);
				}
			}
		}
		return count;
	}