Exemplo n.º 1
0
bool Field::qcanBeatTR(const Cell *arg)
{
    if( arg == NULL || !arg->getFigure().isQueen() )
    {
        string exep = "ERROR! qcanBeatTR function cannot take not queen, or arg is NULL\n";
        throw exep;
    }

    unsigned char tmpcol = arg->getFigure().getColor();
    bool was_token = false;

    Cell* temp = getTopRight(arg);                          // Top Right element

    while( temp != NULL )                                   // while it's not an end of field
    {
        if( temp->isEmpty() )                               // if it's empty cell
        {
            if( was_token )                                 // and we beated some figure
            {
                temp->setCanMove(true);                     // then we can move on this
            }
            temp = getTopRight(temp);                       // set checking on next top right cell
        }

        else                                                // if it's not empty cell
        {
            if( temp->getFigure().getColor() == tmpcol )    // if it's friendly figure
            {
                break;
            }
            else                                            // !!! if it's an empty cell
            {
                if( was_token )                             // we can beat only 1 time per move!
                {
                    break;
                }

                // !!! not token
                if( getTopRight(temp)->isEmpty() )          // if next one is empty
                {
                    was_token = true;                       // we beated!
                    temp = getTopRight(temp);               // move to that pozition
                    temp->setCanMove(true);
                }
            }
        }
    }
    return was_token;
}
Exemplo n.º 2
0
bool glmRectangle::clip( glm::vec3& _p0, glm::vec3& _p1) const {
    
    glm::vec3 topLeft     = getTopLeft();
    glm::vec3 topRight    = getTopRight();
    glm::vec3 bottomRight = getBottomRight();
    glm::vec3 bottomLeft  = getBottomLeft();
    
    if (!inside(_p0)) {
        glm::vec3 r;
        if (LineSegmentIntersection(_p0, _p1, topLeft,     topRight,    r)){
            _p0 = r;
        } else if (LineSegmentIntersection(_p0, _p1, topRight,    bottomRight, r)){
            _p0 = r;
        } else if (LineSegmentIntersection(_p0, _p1, bottomRight, bottomLeft,  r)){
            _p0 = r;
        } else if (LineSegmentIntersection(_p0, _p1, bottomLeft,  topLeft,     r)){
            _p0 = r;
        }
    }
    
    if (!inside(_p1)) {
        glm::vec3 r;
        if (LineSegmentIntersection(_p1, _p0, topLeft,     topRight,    r)){
            _p1 = r;
        } else if (LineSegmentIntersection(_p1, _p0, topRight,    bottomRight, r)){
            _p1 = r;
        } else if (LineSegmentIntersection(_p1, _p0, bottomRight, bottomLeft,  r)){
            _p1 = r;
        } else if (LineSegmentIntersection(_p1, _p0, bottomLeft,  topLeft,     r)){
            _p1 = r;
        }
    }
}
Exemplo n.º 3
0
// dieses Rect relativ zum anderen...
eTouchType Rect::getTouchType(const Rect& rect) const
{
	if(!isTouched(rect)) {
		return TOUCHES_NO_TOUCH;
	}

	// ist 'rect' innerhalb dieses Rects?
	if(isRectInside(rect)) {
		return TOUCHES_IS_COMPLETELY_INSIDE;
	} else if(isTopLeftCornerInside(rect.getTopLeft()) && isBottomLeftCornerInside(rect.getBottomLeft())) {
		return TOUCHES_CROSSES_RIGHT_BORDER;
	} else if(isTopLeftCornerInside(rect.getTopLeft()) && isTopRightCornerInside(rect.getTopRight())) {
		return TOUCHES_CROSSES_LOWER_BORDER;
	} else if(isTopRightCornerInside(rect.getTopRight()) && isBottomRightCornerInside(rect.getBottomRight())) {
		return TOUCHES_CROSSES_LEFT_BORDER;
	} else if(isBottomRightCornerInside(rect.getBottomRight()) && isBottomLeftCornerInside(rect.getBottomLeft())) {
		return TOUCHES_CROSSES_UPPER_BORDER;
	} else if(isTopLeftCornerInside(rect.getTopLeft())) {
		return TOUCHES_CROSSES_BOTTOM_RIGHT_CORNER;
	} else if(isTopRightCornerInside(rect.getTopRight())) {
		return TOUCHES_CROSSES_BOTTOM_LEFT_CORNER;
	} else if(isBottomRightCornerInside(rect.getBottomRight())) {
		return TOUCHES_CROSSES_TOP_LEFT_CORNER;
	} else if(isBottomLeftCornerInside(rect.getBottomLeft())) {
		return TOUCHES_CROSSES_TOP_RIGHT_CORNER;
	}

	else if((rect.getLeft() < getLeft()) && (rect.getRight() > getRight()) && (rect.getTop() >= getTop()) && (rect.getBottom() <= getBottom())) { // ? = 
		return TOUCHES_CROSSES_LEFT_AND_RIGHT_BORDER;
	} else if((rect.getTop() < getTop()) && (rect.getBottom() > getBottom()) && (rect.getLeft() >= getLeft()) && (rect.getRight() <= getRight())) {
		return TOUCHES_CROSSES_TOP_AND_BOTTOM_BORDER;
	}

	else if((rect.getLeft() == getRight()) && (rect.getTop() == getTop()) && (rect.getBottom() == getBottom())) {
		return TOUCHES_RIGHT_BORDER;
	} else if((rect.getTop() == getBottom()) && (rect.getLeft() == getLeft()) && (rect.getRight() == getRight())) {
		return TOUCHES_LOWER_BORDER;
	} else if((rect.getRight() == getLeft()) && (rect.getTop() == getTop()) && (rect.getBottom() == getBottom())) {
		return TOUCHES_LEFT_BORDER;
	} else if((rect.getBottom() == getTop()) && (rect.getLeft() == getLeft()) && (rect.getRight() == getRight())) {
		return TOUCHES_UPPER_BORDER;
	}

	else if((rect.isTopLeftCornerInside(getTopLeft())) && (rect.isTopRightCornerInside(getTopRight())) && (!rect.isBottomRightCornerInside(getBottomRight())) && (!rect.isBottomLeftCornerInside(getBottomLeft()))) {
		return TOUCHES_CROSSES_UPPER_AREA;
	} else if((!rect.isTopLeftCornerInside(getTopLeft())) && (rect.isTopRightCornerInside(getTopRight())) && (rect.isBottomRightCornerInside(getBottomRight())) && (!rect.isBottomLeftCornerInside(getBottomLeft()))) {
		return TOUCHES_CROSSES_RIGHT_AREA;
	} else if((!rect.isTopLeftCornerInside(getTopLeft())) && (!rect.isTopRightCornerInside(getTopRight())) && (rect.isBottomRightCornerInside(getBottomRight())) && (rect.isBottomLeftCornerInside(getBottomLeft()))) {
		return TOUCHES_CROSSES_LOWER_AREA;
	} else if((rect.isTopLeftCornerInside(getTopLeft())) && (!rect.isTopRightCornerInside(getTopRight())) && (!rect.isBottomRightCornerInside(getBottomRight())) && (rect.isBottomLeftCornerInside(getBottomLeft()))) {
		return TOUCHES_CROSSES_LEFT_AREA;
	}

	else { 
		return TOUCHES_NO_TOUCH;
	}
}
Exemplo n.º 4
0
bool Field::canBeatTR(const Cell *arg)
{
    Cell* temp = getTopRight(arg);
    Cell* tempTR = getTopRight(temp);

    if( tempTR != NULL && !arg->isEmpty() )    // getTopRight checks arg for NULL value
    {
        if( !temp->isEmpty() )
        {
            if( arg->getFigure().getColor() == temp->getFigure().getColor() )
            {
                return false;
            }
            if( tempTR->isEmpty() )
            {
                tempTR->setCanMove(true);
            }
         }
    }
    return false;
}
//----------------------------------------------------------
bool ofRectangle::intersects(const ofPoint& p0, const ofPoint& p1) const {
    // check for a line intersection
    ofPoint p;

    ofPoint topLeft     = getTopLeft();
    ofPoint topRight    = getTopRight();
    ofPoint bottomRight = getBottomRight();
    ofPoint bottomLeft  = getBottomLeft();

    return inside(p0) || // check end inside
           inside(p1) || // check end inside
           ofLineSegmentIntersection(p0, p1, topLeft,     topRight,    p) || // cross top
           ofLineSegmentIntersection(p0, p1, topRight,    bottomRight, p) || // cross right
           ofLineSegmentIntersection(p0, p1, bottomRight, bottomLeft,  p) || // cross bottom
           ofLineSegmentIntersection(p0, p1, bottomLeft,  topLeft,     p);   // cross left
}
Exemplo n.º 6
0
//------------------------------------------------------------------------
Point& Rect::toPoint (Direction dir, Point& p) const
{
	switch (dir) {
	case kSouthWest:		return p = getBottomLeft ();
	case kWest:				return p = getLeftCenter ();
	case kNorthWest:		return p = getTopLeft ();
	case kNorth:			return p = getTopCenter ();
	case kNorthEast:		return p = getTopRight ();
	case kEast:				return p = getRightCenter ();
	case kSouthEast:		return p = getBottomRight ();
	case kSouth:			return p = getBottomCenter ();
	case kNoDirection:		return p = getCenter ();
	}

	return p;
}
Exemplo n.º 7
0
//----------------------------------------------------------
bool glmRectangle::intersects(const glm::vec3& p0, const glm::vec3& p1) const {
    // check for a line intersection
    glm::vec3 p;
    
    glm::vec3 topLeft     = getTopLeft();
    glm::vec3 topRight    = getTopRight();
    glm::vec3 bottomRight = getBottomRight();
    glm::vec3 bottomLeft  = getBottomLeft();
    
    return inside(p0) || // check end inside
    inside(p1) || // check end inside
    LineSegmentIntersection(p0, p1, topLeft,     topRight,    p) || // cross top
    LineSegmentIntersection(p0, p1, topRight,    bottomRight, p) || // cross right
    LineSegmentIntersection(p0, p1, bottomRight, bottomLeft,  p) || // cross bottom
    LineSegmentIntersection(p0, p1, bottomLeft,  topLeft,     p);   // cross left
}