Exemplo n.º 1
0
static int isRotateMirror()
{
	char piece;
	int i, j, i2, j2;

	i2 = getRowSize();
	for (i = 1; i <= ((getRowSize() + 1) / 2); i++) {
		j2 = getColSize();
		for (j = 1; j <= getColSize(); j++) {
			piece = getAt(i, j);
			switch (getAt(i2, j2)) {
				case NW:
					if (piece != SE)
						return false;
			                break;
				case NE:
					if (piece != SW)
						return false;
			                break;
				case SW:
					if (piece != NE)
						return false;
			                break;
				case SE:
					if (piece != NW)
						return false;
			                break;
				case NS:
					if (piece != NS)
						return false;
			                break;
				case WE:
					if (piece != WE)
						return false;
			                break;
				case EMPTY:
					if (piece != EMPTY)
						return false;
			                break;
				default:
					break;
			}
			j2--;
		}
		i2--;
	}
	return true;
}
Exemplo n.º 2
0
Arquivo: parser.c Projeto: uai/VZI
int parseList(FILE* pf, int dimension, edgeData_t *list)
{
    char line[LINE_BUFFER_SZ];
    int i = 0;

    for (i = 0; i < dimension; ++i)
    {
        char* runing = NULL;
        int* row = NULL;
        int count = 0;

        fgets(line, sizeof(line), pf);
        runing = line;

        row = (int*)calloc(getRowSize(line), sizeof(int));
        if (!row) return 0;

        while (runing != NULL)
        {
            int num = atoi(strsep(&runing, " "));
            row[count] = num;

            count++;
        }

        list[i].size = count;
        list[i].row = row;
    }

    return 1;
}
	gluit::Point getCurrentStepPosition() const
	{
		unsigned int x = currentStep % (columns + 1);
		unsigned int y = currentStep / (columns + 1);

		return gluit::Point::fromDouble(x * getColumnSize(), y * getRowSize()).move(getPatternRectangle().upperLeftCorner);
	}
  FilterReverse::FilterReverse(const Miro::ImageFormatIDL& _format) :
    Super(_format),
    rowSize_(getRowSize(_format))
  {
    switch(inputFormat_.palette)
      {
      case Miro::GREY_8: 
	bytesPerPixel = 1;
	break;
      case Miro::GREY_16:
	bytesPerPixel = 2;
	break;
      case Miro::GREY_32:
	bytesPerPixel = 4;
	break;
      case Miro::RGB_24:
	bytesPerPixel = 3;
	break;
      case Miro::BGR_24:
	bytesPerPixel = 3;
	break;
      case Miro::RGB_32:
	bytesPerPixel = 4;
	break;
      case Miro::BGR_32:
	bytesPerPixel = 4;
	break;
      default:
	MIRO_LOG(LL_CRITICAL, "cannot handle YUV");
	exit(-1);
      }
  }
 FilterHalfImage::FilterHalfImage(const Miro::ImageFormatIDL& _format) :
   Super(_format),
   rowSize_(getRowSize(_format)),
   rowSize2_(rowSize_ * 2),
   offset_(0)
 {
   outputFormat_.height /= 2;
 }
Exemplo n.º 6
0
static void putAt(int row, int col, char piece)
{
	if (piece == EMPTY) {
		if (current.board[current.firstRow + row - 1][current.firstCol +
		                                              col - 1] != EMPTY)
			current.numOfTiles--;
		current.board[current.firstRow + row - 1][current.firstCol +
		                                          col - 1] = piece;
		return;
	} else {
		if (current.boardEmpty) {
			current.boardEmpty = false;
			current.firstRow = BOARD_SIZE - 1;
			current.firstCol = BOARD_SIZE - 1;
			current.lastRow = BOARD_SIZE - 1;
			current.lastCol = BOARD_SIZE - 1;
			current.numOfTiles = 1;
			current.board[current.firstRow][current.firstCol] = piece;
			return;
		}
		if (row == 0) {
			current.firstRow--;
			row++;
		}
		if (col == 0) {
			current.firstCol--;
			col++;
		}
		if (row > getRowSize()) {
			current.lastRow += row - getRowSize();
		}
		if (col > getColSize()) {
			current.lastCol += col - getColSize();
		}
		current.numOfTiles++;
	}
	current.board[current.firstRow + row - 1][current.firstCol + col -
	                                          1] = piece;
}
Exemplo n.º 7
0
void Modules::inputRow(int rType, string num) {
    bool valid;	// input valid check
    string input;

    for (int i = 0; i < getRowSize(rType); i++) {
        cout << "Enter your " << num << "row in pitches or numbers (" << i + 1 << "): ";
        do {
            valid = true;
            cin >> input;
            if (pitchToNum(input) == -1) {
                inputInvalid(valid);
                continue;
            }
            setRow(i, pitchToNum(input), rType);
        } while (valid == false);
    }
}
	void drawCalibrationPattern(gluit::Graphics& g) const
	{
		gluit::Rectangle patternRectangle = getPatternRectangle();

		g.setColor(gluit::Color::WHITE);
		g.setLineWidth(1);
		g.drawRectangle(patternRectangle, false);

		double columnSize = getColumnSize();
		double rowSize = getRowSize();
		for (unsigned int y = 0; y < getPointsPerColumn(); ++y) {
			for (unsigned int x = 0; x < getPointsPerRow(); ++x) {
				gluit::Point p = gluit::Point::fromDouble(x * columnSize, y * rowSize).move(patternRectangle.upperLeftCorner);
				g.drawLine(p.move(-15, 0), p.move(15, 0));
				g.drawLine(p.move(0, -15), p.move(0, 15));
			}
		}
	}
Exemplo n.º 9
0
void Modules::inputRowNor() {
    bool valid;	// input valid check
    int input;

    for (int i = 0; i < getRowSize(1); i++) {
        cout << "Enter your row in any integers between -" << MAXINT
            << " and " << MAXINT << " (" << i + 1 << "): ";
        do {
            valid = true;
            cin >> input;
            if (getRow(i, 1) < -MAXINT || getRow(i, 1) > MAXINT || !cin) {
                inputInvalid(valid);
                continue;
            }
            setRow(i, input, 1);
        } while (valid == false);
    }
}
 FilterFlip::FilterFlip(const Miro::ImageFormatIDL& _format) :
   Super(_format),
   rowSize_(getRowSize(_format))
 {
 }
Exemplo n.º 11
0
void Modules::transposition(int rType) {
    setRow(0, 0, 4); // no transposition for the first pitch
    for (int i = 1; i < getRowSize(1); i++)
        // initialize a transposition table to find the distance between each pitch in the row
        setRow(i, getRow(i, rType) - getRow(i - 1, rType), 4); // start with subtracting the 1st pitch from the 2nd pitch
}
Exemplo n.º 12
0
int uniqueMoves(char moves[][256])
{
	/*
	 * complex throw away a lot of equal moves
	 * and symmetries (hopefully)
	*/

	int movesIndex = 0;

	int i, j, k;
	char dl, dr, ur, rr, ul;
	/* which neighbors - default all values 0 */
	int neighbors[BOARD_SIZE + 2][BOARD_SIZE + 2];
	int directionList[BOARD_SIZE + 2][BOARD_SIZE + 2][3];
	/*
	 * which directions for move
	 * 0 -> /
	 * 1 -> \
	 * 2 -> +
	 * true means already used
	 * default all values false
	*/
	int ohs_up, ohs_down, ohs_right, ohs_left, eks_up, eks_down, eks_right, eks_left;
	int up, down, left, right;
	int iBegin, jBegin, iEnd, jEnd;

	int rsym;

	if (current.gameOver != NOPLAYER)
		return 0;

	/* empty board only two moves */
	if (current.boardEmpty) {
		strcpy(moves[movesIndex], "@0/");
		movesIndex++;
		strcpy(moves[movesIndex], "@0+");
		movesIndex++;
		return movesIndex;
	}
	if (getRowSize() * getColSize() == 1) {
		switch (getAt(1, 1)) {
			case NW:
				strcpy(moves[movesIndex], "@1+");
		                movesIndex++;
		                strcpy(moves[movesIndex], "@1/");
		                movesIndex++;
		                strcpy(moves[movesIndex], "@1\\");
		                movesIndex++;
		                strcpy(moves[movesIndex], "B1+");
		                movesIndex++;
		                strcpy(moves[movesIndex], "B1/");
		                movesIndex++;
		                strcpy(moves[movesIndex], "B1\\");
		                movesIndex++;
		                strcpy(moves[movesIndex], "A0\\");
		                movesIndex++;
		                strcpy(moves[movesIndex], "A0/");
		                movesIndex++;
		                strcpy(moves[movesIndex], "A0+");
		                movesIndex++;
		                strcpy(moves[movesIndex], "A2/");
		                movesIndex++;
		                strcpy(moves[movesIndex], "A2\\");
		                movesIndex++;
		                strcpy(moves[movesIndex], "A2+");
		                movesIndex++;
		                break;
			case NS:
				strcpy(moves[movesIndex], "@1+");
		                movesIndex++;
		                strcpy(moves[movesIndex], "@1/");
		                movesIndex++;
		                strcpy(moves[movesIndex], "@1\\");
		                movesIndex++;
		                strcpy(moves[movesIndex], "A0/");
		                movesIndex++;
		                strcpy(moves[movesIndex], "A0+");
		                movesIndex++;
		                strcpy(moves[movesIndex], "A0\\");
		                movesIndex++;
		                strcpy(moves[movesIndex], "B1/");
		                movesIndex++;
		                strcpy(moves[movesIndex], "B1\\");
		                movesIndex++;
		                strcpy(moves[movesIndex], "A2/");
		                movesIndex++;
		                strcpy(moves[movesIndex], "A2\\");
		                movesIndex++;
		                break;
			default:
				/* This should never happen */
				break;
		}
		return movesIndex;
	}

	for (i = 0; i < BOARD_SIZE + 2; i++)
		for (j = 0; j < BOARD_SIZE + 2; j++)
			for (k = 0; k < 3; k++)
				directionList[i][j][k] = false;

	rsym = isRotateMirror();
	iBegin = (canMoveDown()) ? 0 : 1;
	jBegin = (canMoveRight()) ? 0 : 1;
	iEnd = (getRowSize() < BOARD_SIZE) ? getRowSize() : BOARD_SIZE;
	jEnd = (getColSize() < BOARD_SIZE) ? getColSize() : BOARD_SIZE;

	for (i = iBegin; i <= iEnd; i++) {
		for (j = jBegin; j <= jEnd; j++) {
			if (!(isBlank(i, j))) {
				neighbors[i][j] = 0;
			} else {
				ohs_up = 0;
				ohs_down = 0;
				ohs_right = 0;
				ohs_left = 0;
				eks_up = 0;
				eks_down = 0;
				eks_right = 0;
				eks_left = 0;
				up = getAt(i - 1, j);
				down = getAt(i + 1, j);
				left = getAt(i, j - 1);
				right = getAt(i, j + 1);

				if (up == SN || up == SW || up == SE) {
					ohs_up = 1;
				} else if (up != EMPTY) {
					eks_up = 1;
				}

				if (down == NS || down == NW ||
				    down == NE) {
					ohs_down = 1;
				} else if (down != EMPTY) {
					eks_down = 1;
				}

				if (left == EN || left == ES ||
				    left == WE)
					ohs_left = 1;
				else if (left != EMPTY)
					eks_left = 1;

				if (right == WE || right == WS ||
				    right == WN)
					ohs_right = 1;
				else if (right != EMPTY)
					eks_right = 1;

				neighbors[i][j] =
					ohs_up + 2 * ohs_down +
					4 * ohs_left
					+ 8 * ohs_right + 16 * eks_up +
					32 * eks_down + 64 * eks_left +
					128 * eks_right;
			}
		}
	}

	for (i = iBegin; i <= iEnd; i++) {
		for (j = jBegin; j <= jEnd; j++) {
			if (neighbors[i][j] != 0) {
				dl = getAt(i + 1, j - 1);
				dr = getAt(i + 1, j + 1);
				ur = getAt(i - 1, j + 1);
				ul = getAt(i - 1, j - 1);
				rr = getAt(i, j + 2);
				switch (neighbors[i][j]) {
					case 1:
						if (dr == NS || dr == NW ||
						    dr == NE)
							directionList[i][j +
							                 1][1] = true;
				                if (dr == WN || dr == WS ||
				                    dr == WE)
					                directionList[i +
					                              1][j][1] = true;
				                if (dl == EW || dl == ES ||
				                    dl == ES)
					                directionList[i +
					                              1][j][0] = true;
				                if (ur == SW || ur == SE ||
				                    ur == SN)
					                directionList[i][j +
					                                 1][0] = true;
				                break;
					case 2: {
						if (dr == NS || dr == NW ||
						    dr == NE)
							directionList[i][j +
							                 1][1] = true;
						if (ur == SW || ur == SE ||
						    ur == SN)
							directionList[i][j +
							                 1][0] = true;
						break;
					}
					case 4: {
						if (dl == ES || dl == EN ||
						    dl == EW)
							directionList[i +
							              1][j][0] = true;
						if (dr == WN || dr == WS ||
						    dr == WE)
							directionList[i +
							              1][j][1] = true;
						if (ur == SW || ur == SN ||
						    ur == SE)
							directionList[i][j +
							                 1][0] = true;
						if (dr == NS || dr == NE ||
						    dr == NW)
							directionList[i][j +
							                 1][1] = true;
						break;
					}
					case 8: {
						if (dl == ES || dl == EN ||
						    dl == EW)
							directionList[i +
							              1][j][0] = true;
						if (dr == WN || dr == WE ||
						    dr == WS)
							directionList[i +
							              1][j][1] = true;
						break;
					}
					case 16: {
						if (dr == SW || dr == SE ||
						    dr == WE)
							directionList[i][j +
							                 1][1] = true;
						if (dr == SE || dr == SN ||
						    dr == EN)
							directionList[i +
							              1][j][1] = true;
						if (dl == NW || dl == NS ||
						    dl == WS)
							directionList[i +
							              1][j][0] = true;
						if (ur == NW || ur == NE ||
						    ur == WE)
							directionList[i][j +
							                 1][0] = true;
						break;
					}
					case 18:
					case 33: {
						directionList[i][j +
						                 1][1] = true;
						directionList[i][j +
						                 1][0] = true;
						directionList[i][j][2] = true;
						break;
					}
					case 20:
					case 65: {
						if (rr != EMPTY)
							directionList[i][j +
							                 1][2] = true;
						directionList[i +
						              1][j][0] = true;
						directionList[i +
						              1][j][1] = true;
						directionList[i][j +
						                 1][0] = true;
						directionList[i][j][0] = true;
						break;
					}
					case 24:
					case 129: {
						directionList[i +
						              1][j][1] = true;
						directionList[i][j][1] = true;
						break;
					}
					case 32: {
						if (dr == SE || dr == SW ||
						    dr == EW)
							directionList[i][j +
							                 1][1] = true;
						if (ur == NW || ur == NE ||
						    ur == WE)
							directionList[i][j +
							                 1][0] = true;
						break;
					}
					case 36: {
						if (ul == NW || ul == SW ||
						    ul == NS)
							directionList[i -
							              1][j][1] = true;
						directionList[i][j +
						                 1][1] = true;
						directionList[i][j +
						                 1][0] = true;
						directionList[i][j][1] = true;
						break;
					}
					case 40:
					case 130: {
						directionList[i][j][0] = true;
						break;
					}
					case 64: {
						if (dl == WN || dl == WS ||
						    dl == NS)
							directionList[i +
							              1][j][0] = true;
						if (dr == EN || dr == ES ||
						    dr == NS)
							directionList[i +
							              1][j][1] = true;
						if (ur == NW || ur == NE ||
						    ur == WE)
							directionList[i][j +
							                 1][0] = true;
						if (dr == SE || dr == SW ||
						    dr == EW)
							directionList[i][j +
							                 1][1] = true;
						break;
					}
					case 66: {
						if (ul == EW || ul == ES ||
						    ul == EN)
							directionList[i -
							              1][j][1] = true;
						directionList[i][j +
						                 1][1] = true;
						directionList[i][j +
						                 1][0] = true;
						directionList[i][j][1] = true;
						break;
					}
					case 72:
					case 132: {
						directionList[i +
						              1][j][0] = true;
						directionList[i +
						              1][j][1] = true;
						directionList[i][j][2] = true;
						break;
					}
					case 128: {
						if (dl == WS || dl == WN ||
						    dl == SN)
							directionList[i +
							              1][j][0] = true;
						if (dr == EN || dr == ES ||
						    dr == NS)
							directionList[i +
							              1][j][1] = true;
						break;
					}
					default:
						break;
				}
			}
		}
	}

	/* collects the moves */
	for (i = iBegin; i <= iEnd; i++) {
		for (j = jBegin; j <= jEnd; j++) {
			/* remove rotation symmetry moves */
			if (rsym && getRowSize() % 2 == 1) {
				int jMiddle = (getColSize() + 1) / 2;
				if (j > jMiddle && i == iEnd) {
					continue;
				}
			}
			if (neighbors[i][j] != 0) {
				ohs_up = 0;
				ohs_down = 0;
				ohs_right = 0;
				ohs_left = 0;
				eks_up = 0;
				eks_down = 0;
				eks_right = 0;
				eks_left = 0;
				up = getAt(i - 1, j);
				down = getAt(i + 1, j);
				left = getAt(i, j - 1);
				right = getAt(i, j + 1);

				if (up == SN || up == SW || up == SE)
					ohs_up = 1;
				else if (up != EMPTY)
					eks_up = 1;
				if (down == NS || down == NW ||
				    down == NE)
					ohs_down = 1;
				else if (down != EMPTY)
					eks_down = 1;
				if (left == EN || left == ES ||
				    left == WE)
					ohs_left = 1;
				else if (left != EMPTY)
					eks_left = 1;
				if (right == WE || right == WS ||
				    right == WN)
					ohs_right = 1;
				else if (right != EMPTY)
					eks_right = 1;

				if (!directionList[i][j][0]) {
					saveState();
					if ((ohs_up + ohs_left > 0)
					    ||
					    (eks_right + eks_down > 0))
						putAt(i, j, NW);
					if ((eks_up + eks_left > 0)
					    ||
					    (ohs_right + ohs_down > 0))
						putAt(i, j, SE);
					if (forcedMove(i - 1, j) &&
					    forcedMove(i + 1, j)
					    && forcedMove(i, j - 1) &&
					    forcedMove(i, j + 1)) {
						getTraxMoveString(i, j,
							moves[movesIndex],
							'/');
						movesIndex++;
					}
					restoreState();
				}
				if (!directionList[i][j][1]) {
					saveState();
					if ((ohs_up + ohs_right > 0)
					    ||
					    (eks_left + eks_down > 0))
						putAt(i, j, NE);
					if ((eks_up + eks_right > 0)
					    ||
					    (ohs_left + ohs_down > 0))
						putAt(i, j, SW);
					if (forcedMove(i - 1, j) &&
					    forcedMove(i + 1, j)
					    && forcedMove(i, j - 1) &&
					    forcedMove(i, j + 1)) {
						getTraxMoveString(i, j,
							moves[movesIndex],
							'\\');
						movesIndex++;
					}
					restoreState();
				}
				if (!directionList[i][j][2]) {
					saveState();
					if ((ohs_up + ohs_down > 0)
					    ||
					    (eks_left + eks_right > 0))
						putAt(i, j, NS);
					if ((eks_up + eks_down > 0)
					    ||
					    (ohs_left + ohs_right > 0))
						putAt(i, j, WE);
					if (forcedMove(i - 1, j) &&
					    forcedMove(i + 1, j)
					    && forcedMove(i, j - 1) &&
					    forcedMove(i, j + 1)) {
						getTraxMoveString(i, j,
							moves[movesIndex],
							'+');
						movesIndex++;
					}
					restoreState();
				}
			}
		}
	}
	return movesIndex;
}
Exemplo n.º 13
0
static int canMoveDown(void)
{
	return (getRowSize() < BOARD_SIZE);
}