bool TileImage::matches(const TileImage *other)
{
    const QImage &image1 = image();
    const QImage &image2 = other->image();

    int width = image1.width();
    int height = image1.height();
    
    if (width != image2.width() || height != image2.height())
    {
        return false;
    }
    
    for (int y = 0; y < height; ++y)
    {
        for (int x = 0; x < width; ++x)
        {
            bool white1 = isWhite(image1.pixel(x, y));
            bool white2 = isWhite(image2.pixel(x, y));
            
            if (white1 ^ white2)
            {
                return false;
            }
        }
    }
    
    return true;
}
Пример #2
0
	bool King::isChecked(const Board& board) const {
		// Check other pieces.
		for (int x = 0; x < 8; x++) {
			for (int y = 0; y < 8; y++) {
				Piece* piece = board.getPiece(Position(x, y));

				if (piece != nullptr && isWhite() != piece->isWhite() && piece->notation() != 'k' && piece->notation() != 'K') {
					std::vector<Position> moves = piece->moves(board);
					for (Position move : moves) {
						if (move == position)
							return true;
					}
				}
			}
		}

		// Check opponent's king.
		for (int x = position.x - 1; x <= position.x + 1; x++) {
			for (int y = position.y - 1; y <= position.y + 1; y++) {
				if (Position(x, y).valid()) {
					Piece* piece = board.getPiece(Position(x, y));
					if (piece != nullptr && piece->isWhite() != isWhite() && (piece->notation() == 'k' || piece->notation() == 'K'))
						return true;
				}
			}
		}

		return false;
	}
Пример #3
0
std::vector<Move> Rook::getPossibleMoves(){
	std::vector<Move> possible;
	for(int i = getRow() - 1; i >= 0; i--){
		if (getBoard()->board[i][getColumn()] == NULL){
			possible.push_back(Move(i, getColumn()));
		}
		else if (getBoard()->board[i][getColumn()]->isWhite() != isWhite()){
			possible.push_back(Move(i, getColumn()));
			break;
		}
		else{
			break;
		}
	}
	for(int i = getRow() + 1; i < 8; i++){
		if (getBoard()->board[i][getColumn()] == NULL){
			possible.push_back(Move(i, getColumn()));
		}
		else if (getBoard()->board[i][getColumn()]->isWhite() != isWhite()){
			possible.push_back(Move(i, getColumn()));
			break;
		}
		else{
			break;
		}
	}
	for (int i = getColumn() - 1; i >= 0; i--){
		if (getBoard()->board[getRow()][i] == NULL){
			possible.push_back(Move(getRow(), i));
		}
		else if (getBoard()->board[getRow()][i]->isWhite() != isWhite()){
			possible.push_back(Move(getRow(), i));
			break;
		}
		else{
			break;
		}
		
	}
	for (int i = getColumn() + 1; i < 8; i++){
		if (getBoard()->board[getRow()][i] == NULL){
			possible.push_back(Move(getRow(), i));
		}
		else if (getBoard()->board[getRow()][i]->isWhite() != isWhite()){
			possible.push_back(Move(getRow(), i));
			break;
		}
		else{
			break;
		}
	}
	return possible;
}
Пример #4
0
Int16u GetWordLength (const char far * string)
{
    Int16u result = 0;

#if defined (DBCS)
    if (IsDBCSEnabled () && !isascii (*string))
    {
        result = (AnsiNext (string)) - ((char *)string);
        string += result;
        return result;
    }
#endif //(DBCS)

    while (*string != '\0' && !isWhite (*string) && !isNewLine (string)
#if defined (DBCS)
           && (!IsDBCSEnabled () || isascii (*string))
#endif //(DBCS)
          )
    {
        ++result;
        ++string;
    }

    return result;
}
Пример #5
0
int pushBackBuffer::readInt (void)
{
  int  c =0;
  int  i =0;
  int  s =1;
  char ch=getPB();

  while (isWhite(ch)) {
    ch=getPB();
  }
  // now read integer

  if (ch == '-') {
    s = -1;
    ch = getPB();
  }
  while (isDigit(ch)) {
    i *= 10;
    if ((ch>='0') && (ch<='9')) {
      i += (int)(ch-'0');
    }
    ch = getPB();
    c++;
  }
  if (ch != putPB(ch)) {
    ERROR("assert failed");
  }
  return( i*s );
}
Пример #6
0
void ChessClockWidget::initTop()
{
    QVBoxLayout* details = new QVBoxLayout();
    details->addWidget(timeUsedLabel_);
    details->addWidget(timeAverageLabel_);
    details->addWidget(turnLabel_);
    details->addWidget(turnTimeLabel_);

    QHBoxLayout* topLayout = new QHBoxLayout();
    if( isWhite() )
    {
        // White player
        //  Picture  |  Details | .. | LOSER
        topLayout->addWidget( pictureLabel_ );
        topLayout->addLayout( details );
        topLayout->addStretch();
        topLayout->addWidget(loserLabel_);
    }
    else
    {
        // Black player
        // LOSER | ... | Details | Picture
        topLayout->addWidget(loserLabel_);
        topLayout->addStretch();
        topLayout->addLayout( details );
        topLayout->addWidget( pictureLabel_ );
    }
    mainLayout->addLayout(topLayout);
}
boost::shared_ptr<cv::Mat> RemoveLonePixels::apply( boost::shared_ptr<cv::Mat> input ) const
{
    boost::shared_ptr<cv::Mat> result( new cv::Mat( input->clone() ) );

    for( int row = 0; row < input->rows; ++row )
    {
        for( int col = 0; col < input->cols; ++col )
        {
            cv::Vec3b& pixel = result->at<cv::Vec3b>( row, col );
            
            if ( !isImageBorder( row, col, input->rows, input->cols ) )
            {
                if( isWhite( pixel ) )
                {
                    if ( shouldBeColored( row, col, result ) )
                    {
                        colorPixel( pixel, row, col, result );
                    }
                }
                else
                {
                    if( isLonely( row, col, result ) )
                    {
                        whitenPixel( pixel );
                    }
                }   
            }
        }
    }

    return result;
}
Пример #8
0
/**
 * @brief Parses in the block context for the given node
 * 
 * The block context parses comments and data identifiers, any other
 * data is invalid in this context.
 * 
 * The block context ends when a closing hash marker is found.
 */
void NepParser::genCtxBlock(Nepeta::Node &node)
{
	size_t stLine = getCurLine(), stCol = getCurCol();
	
	while( notEof() ) {
		char ch = getCurRaw();
		
		// Skip whitespace
		if( isWhite(ch) ) {
			iterCur();
		// Check for data block marker
		} else if( checkIdentifier(ch) || checkHash(ch) ) {
			// Parse the data block.
			// If an end marker is found, this returns false
			if(!genCtxData(node))
				return;
		// Check for comment marker
		} else if( checkComment(ch) ) {
			helpSkipComment();
		// Any other character is invalid, skip to the next line
		} else {
			mScript.addError( Nepeta::ErrIllegalCharacter, std::string(1,ch),
				getCurLine(), getCurCol()
			);
			helpSeekNewline(false);
		}
	}
	
	if(node.getParent()) {
		mScript.addError( Nepeta::ErrPrematureEnd, "",
		stLine, stCol, getCurLine(), getCurCol());
	}
}
Пример #9
0
/*Determine if given Board Char matches Color*/
int sameCol(char c, Color col){
	if (isBlack(c) && col == BLACK){
		return 1;
	}
	if (isWhite(c) && col == WHITE){
		return 1;
	}
	return 0;
}
Пример #10
0
//string parsing
Bool getWhDelimString(char *&list, Str& firstPart)
{
    skipWhite(list);
    if (!*list) return FALSE;
    char *list_was = list;
    for(; *list && !isWhite(*list); list++);
    firstPart.nset(list_was, (int)(list - list_was));
    return TRUE;
}
Пример #11
0
/*Determine if given Board Char is opposed to given Location*/
int isOpposite(char c, char board[BOARD_SIZE][BOARD_SIZE], Location *loc){
	Color col = getColFromLoc(board, loc);
	if (col == WHITE){
		return isBlack(c);
	}
	if (col == BLACK){
		return isWhite(c);
	}
	return 0;
}
Пример #12
0
void	faxDecoder::addtoPhasing (int16_t x) {
	x	= faxAverager	-> filter (x);
	currPhaseLength ++;

	if (isWhite (x))
	   whiteLength ++;
//
//	Is this a start of segment of white ?
	if (!whiteSide && realWhite (x)) {
	   whiteSide = true;
	   return;
	}

//	are we getting a switch to black, then start working
	if (whiteSide && realBlack (x)) {
	   whiteSide = false;
//
//	We look for - at least - 5 successive phaselines
//
	   if (weFoundaValidPhaseline ()) {
	      lpmSum		+= 60.0 * theRate / currPhaseLength;
	      currPhaseLength	= 0;
	      whiteLength	= 0;
	      phaseLines ++;
	   }
	   else			// we might already be imaging
	   if (phaseLines >= 5) {
	      lpm		= lpmSum / phaseLines;
	      f_lpm		= lpmSum / phaseLines;
	      if (lpm == 0)	// should not happen
	         lpm = 120;	// just a default
	      samplesperLine		= theRate * 60 / lpm;
	      currentSampleIndex	= (int)(1.0 * 60.0 / lpm * theRate);
//	      currentSampleIndex	= (int)(1.025 * 60.0 / lpm * theRate);
	      faxState		= FAX_IMAGING;
	      showState		-> setText (QString ("Image"));
	      double pos	= fmod ((double)currentSampleIndex,
	                                 (double)theRate * 60 / lpm);
	      pos		/= theRate * 60.0 / lpm;
	      currentColumn		= (int)(pos * numberofColums);
	      pixelValue	= 0;
	      lastRow		= 100;
	      phaseLines	= 0;
	      currPhaseLength	= 0;
	      whiteLength	= 0;
	   }
	   else	{		// check for garbage, and clean up
//	   if (currPhaseLength > 5 * theRate) {
	      currPhaseLength	= 0;
	      whiteLength	= 0;
	      phaseLines	= 0;
	      lpmSum		= 0;
	   }
	}
}
Пример #13
0
void ChessClockWidget::initBottom()
{
    // At bottom, time left in BIG font!
    QFont bigfont("Helvetica",65,QFont::Bold);
    leftLabel_ = new QLabel("0.00.00");
    leftLabel_->setFont(bigfont);
    // Black player: right alignment
    if( !isWhite() )
       leftLabel_->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
    mainLayout->addWidget(leftLabel_);
}
Пример #14
0
void pushBackBuffer::skipUntilToken (void)
{
  char ch;

  while ((isWhite(putPB(getPB())) || (putPB(getPB()) == '#')) && (! eofFound)) {
    ch = getPB();
    if (ch == '#') {
      skipToNewline();
    }
  }
}
Пример #15
0
Int16u GetWhiteSpaceLength (const char far * string)
{
    Int16u result = 0;

    while (isWhite (*string))
    {
        ++result;
        ++string;
    }

    return result;
}
Пример #16
0
std::vector<Move> Pawn::getPossibleMoves(){
	std::vector<Move> possible;
	if (isWhite()){
		if (getRow() == 6){
			if (getBoard()->board[getRow() - 2][getColumn()] == NULL){
				possible.push_back(Move(getRow() - 2, getColumn()));
			}

		}
		if (getRow() - 1 >= 0){
			if (getBoard()->board[getRow() - 1][getColumn()] == NULL){
				possible.push_back(Move(getRow() - 1, getColumn()));
			}
			if (getColumn() + 1 < 8){
				if (getBoard()->board[getRow() - 1][getColumn() + 1] != NULL && !(getBoard()->board[getRow() - 1][getColumn() + 1]->isWhite())){
					possible.push_back(Move(getRow() - 1, getColumn() + 1));
				}
			}
			if (getColumn() - 1 >= 0){
				if (getBoard()->board[getRow() - 1][getColumn() - 1] != NULL && !(getBoard()->board[getRow() - 1][getColumn() - 1]->isWhite())){
					possible.push_back(Move(getRow() - 1, getColumn() - 1));
				}
			}
			return possible;
		}
	}
	else{
		if (getRow() == 1){
			if (getBoard()->board[getRow() + 2][getColumn()] == NULL){
				possible.push_back(Move(getRow() + 2, getColumn()));
			}

		}
		if (getRow() + 1 < 8){
			if (getBoard()->board[getRow() + 1][getColumn()] == NULL){
				possible.push_back(Move(getRow() + 1, getColumn()));
			}
			if (getColumn() + 1 < 8){
				if (getBoard()->board[getRow() + 1][getColumn() + 1] != NULL && getBoard()->board[getRow() + 1][getColumn() + 1]->isWhite()){
					possible.push_back(Move(getRow() + 1, getColumn() + 1));
				}
			}
			if (getColumn() - 1 >= 0){
				if (getBoard()->board[getRow() + 1][getColumn() - 1] != NULL && getBoard()->board[getRow() + 1][getColumn() - 1]->isWhite()){
					possible.push_back(Move(getRow() + 1, getColumn() - 1));
				}
			}
			return possible;
		}
	}
	return possible;

}
Пример #17
0
char *pushBackBuffer::readString (void)
{
  char  buffer[MAXPUSHBACKSTACK];
  char *str = 0;
  int   i=0;
  char ch=getPB();

  while (isWhite(ch)) {
    ch=getPB();
  }
  while ((i < MAXPUSHBACKSTACK) && (! isWhite(ch)) && (! eofFound)) {
    buffer[i] = ch;
    i++;
    ch = getPB();
  }
  if (i < MAXPUSHBACKSTACK) {
    buffer[i] = (char)0;
    str = (char *)malloc(strlen(buffer)+1);
    strcpy(str, buffer);
  }
  return( str );
}
Пример #18
0
/* -- Ctrl+cursor right key: to beginning of next word -- */
static void NextWord(WINDOW wnd)
{
    int savetop = wnd->wtop;
    int saveleft = wnd->wleft;
    ClearVisible(wnd);
    while (!isWhite(*CurrChar))    {
        char *cc = CurrChar+1;
        if (*cc == '\0')
            break;
        Forward(wnd);
    }
    while (isWhite(*CurrChar))    {
        char *cc = CurrChar+1;
        if (*cc == '\0')
            break;
        Forward(wnd);
    }
    SetVisible(wnd);
    SendMessage(wnd, KEYBOARD_CURSOR, WndCol, wnd->WndRow);
    if (wnd->wtop != savetop || wnd->wleft != saveleft)
        SendMessage(wnd, PAINT, 0, 0);
}
Пример #19
0
/// @brief constructor of piano key
PianoKey::PianoKey(uchar _id, QGraphicsItem *parent):
    QGraphicsObject(parent),
    id(_id),is_white(isWhite(_id)),
    path(defaultKeyShape(_id)),
    bound(is_white?whiteBound : blackBound),
    is_pressed(false),
    keysound(new QSound(soundpath.arg(QString::number(id,10),2,'0')))
    //keythread (new QThread(0))
{
    setToolTip(QString("I'm No.%1 from the left!").arg(id+1));

    //keysound->moveToThread(keythread);
}
Пример #20
0
char Chessboard::getColor(char row, char col) const {
    checkForValidRow(row);
    checkForValidCol(col);

    if (isWhite(row, col)) {
        return WHITE_PIECE;
    }

    if (isBlack(row, col)) {
        return BLACK_PIECE;
    }

    return OPEN_SQUARE;
}
Пример #21
0
//if singleline is non-zero, then parsing is for a single line
//All expressions using this are not strictly ordered (as in, a + b will be reordered to + a b)
parse_part parse_listitems(parser_state state, int singleln) {
    parse_part result;
    parse_part tmp;

    state.index -= 1;

    lexid exprid = EXPR_LEXID;
    exprid.attr.intval = 0; //Set strictness property to 0


    if (boundsCheck(state)) {
        exprid.loc = getCurrent(state).loc;
    }

    result.tree = lexid_tree_init(exprid);
    
    lexid current = SPACE_LEXID;

    while (singleln ? lexid_eq(current, SPACE_LEXID) : isWhite(current)) {
        while (singleln ? lexid_eq(current, SPACE_LEXID) : isWhite(current)) {
            state.index += 1;
            current = getCurrent(state);
        }
        if (singleln && isWhite(current)) {
            continue;
        }
        if (lexid_eq(current, COMMA_LEXID) || lexid_eq(current, RPAREN_LEXID)) {
            continue;
        }
        tmp = parse_listitem(state);
        result.tree = lexid_tree_addchild(result.tree, tmp.tree);
        state.index = tmp.state.index;
        current = getCurrent(state);
    }
    result.state = state;
    return result;
}
Пример #22
0
void ChessClockWidget::initPictures()
{
    // Load pictures from resources.
    if(  isWhite() )
      {
          picActive_.load(":/rc/pic/white_blue.png");
          picPassive_.load(":/rc/pic/white_gray.png");
      }
      else
      {
          picActive_.load(":/rc/pic/black_blue.png");
          picPassive_.load(":/rc/pic/black_gray.png");
      }
      picLoser_.load(":/rc/pic/loser.png");
}
Пример #23
0
/* -- Ctrl+cursor left key: to beginning of previous word -- */
static void PrevWord(WINDOW wnd)
{
    int savetop = wnd->wtop;
    int saveleft = wnd->wleft;
    ClearVisible(wnd);
    Backward(wnd);
    while (isWhite(*CurrChar))    {
        if (wnd->CurrLine == 0 && wnd->CurrCol == 0)
            break;
        Backward(wnd);
    }
    while (wnd->CurrCol != 0 && !isWhite(*CurrChar))
        Backward(wnd);
    if (isWhite(*CurrChar))
        Forward(wnd);
    SetVisible(wnd);
    if (wnd->wleft != saveleft)
        if (wnd->CurrCol >= saveleft)
            if (wnd->CurrCol - saveleft < ClientWidth(wnd))
                wnd->wleft = saveleft;
    SendMessage(wnd, KEYBOARD_CURSOR, WndCol, wnd->WndRow);
    if (wnd->wtop != savetop || wnd->wleft != saveleft)
        SendMessage(wnd, PAINT, 0, 0);
}
Пример #24
0
void lex_nextchar(z_lexstate *ls)
{
	if(ls->cur.pc + 1 < ls->cur.b.pend) {
		/* keep track of last non-white char
			for debugging and error messages */
		if(!isWhite(*ls->cur.pc) && *ls->cur.pc != '\0')
			ls->cur.plast = ls->cur.pc;

		++ls->cur.pc;
		++ls->cur.col;
	}
	else {
		*(++ls->cur.pc) = '\0';	// insert a null char at the last placeholder
		ls->cur.eof = true;
	}
}
Пример #25
0
Файл: core.c Проект: vojtsek/FTP
// reads word from the fd
// the word is separated by white characters
char readWord(int fd, char *word, size_t max) {
	int r, i = 0;
	char c = 0;
	while (1) {
		if ((r = read(fd, &c, 1)) != 1)
			break;
		if (isWhite(c)) break;
		word[i++] = c;
		if (i == max) {
			printf("Word too long.\n");
			return (0);
		}
	}
	word[i] = 0;
	// returns the white character which separated the world
	return (c);
}
Пример #26
0
bool RemoveLonePixels::isLonely(
    int row,
    int col,
    boost::shared_ptr<cv::Mat> image ) const
{
    std::list<cv::Vec3b> roundPixels;
    getRoundPixels( row, col, image, roundPixels );

    foreach( const cv::Vec3b& pixel, roundPixels )
    {
        if( !isWhite( pixel ) )
        {
            return false;
        }
    }

    return true;
}
Пример #27
0
bool SuperShader::Component::similarTo(const Component& other) const{
    // Black and white are only similar to themselves
    if (isBlack()) {
        return other.isBlack();
    } else if (other.isBlack()) {
        return false;
    }
    
    if (isWhite()) {
        return other.isWhite();
    } else if (other.isWhite()) {
        return false;
    }
    
    // Two components are similar if they both have/do not have texture
    // maps.
    return map.isNull() == other.map.isNull();
}
Пример #28
0
void CamCapture::showSegmentation()
{
    CvScalar pixel; 
    for (int x = 0; x < width_var; ++x)
    {
        for (int y = 0; y < height_var; ++y)
        {
            
            if(isRed(x,y))
            {
                setPixel3C(pixel,0,0,255);
            }
            else if(isBlue(x, y))
            {
                setPixel3C(pixel,255,0,0);
            }
            else if(isYellow(x, y))
            {
                setPixel3C(pixel,0,255,255);
            }
            else if(isGreen(x, y))
            {
                setPixel3C(pixel,0,255,0);
            }
            else if(isWhite(x, y))
            {
                setPixel3C(pixel, 255, 255, 255);
            }
            else if(isBlack(x, y))
            {
                setPixel3C(pixel, 127, 127, 127);   
            }
            else
            {
                setPixel3C(pixel,0,0,0);
            }

            cvSet2D(showSeg, y, x, pixel);
        }
    }
}
Пример #29
0
Color CubeAnalyzer::classifyColor(Vec3b color) {

	if(colorInBounds(color, RED_MIN, RED_MAX) || colorInBounds(color, RED_2_MIN, RED_2_MAX)){
        return RED;
    }
	if(colorInBounds(color, ORANGE_MIN, ORANGE_MAX)){
		return ORANGE;
	}
	if(colorInBounds(color, YELLOW_MIN, YELLOW_MAX)){
		return YELLOW;
	}
	if(colorInBounds(color, GREEN_MIN, GREEN_MAX)) {
		return GREEN;
	}
	if(colorInBounds(color, BLUE_MIN, BLUE_MAX)){
		return BLUE;
	}
	if(isWhite(color)){
		return WHITE;
	}
	return UNDEF;
}
Пример #30
0
void CommentFormatter::strip( const QString& str, QString& from ) {
  if( str.isEmpty() ) return;

  int i = 0;
  int ip = 0;
  int s = from.length();

  for( int a = 0; a < s; a++ ) {
      if( isWhite( from[a] ) ) {
          continue;
      } else {
          if( from[a] == str[i] ) {
              i++;
              ip = a+1;
              if( i == (int)str.length() ) break;
          } else {
              break;
          }
      }
  }

  if( ip ) from = from.mid( ip );
}