示例#1
0
int Settings::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QWidget::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: refreshViews(); break;
        case 1: preInitialize(); break;
        case 2: initialize(); break;
        case 3: load(); break;
        case 4: createGUI(); break;
        case 5: lexiconChanged((*reinterpret_cast< const QString(*)>(_a[1]))); break;
        case 6: alphabetChanged((*reinterpret_cast< const QString(*)>(_a[1]))); break;
        case 7: boardChanged((*reinterpret_cast< const QString(*)>(_a[1]))); break;
        case 8: addBoard(); break;
        case 9: editBoard(); break;
        case 10: deleteBoard(); break;
        case 11: setQuackleToUseLexiconName((*reinterpret_cast< const string(*)>(_a[1]))); break;
        case 12: setQuackleToUseAlphabetName((*reinterpret_cast< const string(*)>(_a[1]))); break;
        case 13: setQuackleToUseBoardName((*reinterpret_cast< const QString(*)>(_a[1]))); break;
        }
        _id -= 14;
    }
    return _id;
}
示例#2
0
void initWindow::on_addBoardbtn_clicked()
{
    QString n = ui->editBoardName->text();
    if(!n.isEmpty())
        addBoard(n);
    ui->editBoardName->clear();
    ui->addBoardbtn->hide();
    ui->editBoardName->hide();
}
示例#3
0
void processCommand(enum command command, uint8_t *buffer, uint16_t length) {

    int j;

    switch(command) {

    case IDENT:

        for(int i = 2; i < 32 + 2; ++i)	{

            module_t m = findModule(buffer[i]);

            if(m.type != NONE.type)
                addBoard (m, i - 2);
        }

        if(buffer[1] > 32)
            for (int i = 0; i < 6; i++)
                version[i] = buffer[34 + i];

        setVersion(version);
        break;

    default:

        j = 2;

        for (int i = 0; i < pboards_c; i++) {

            if (j + pboards[i].board.module.readBytesCount + 2 <= length)
                for (int w = 0; w < pboards[i].board.module.readBytesCount + 2; w++) {
                    pboards[i].board.readBytes[w] = buffer[j];
                    j = j + 1;
                }
        }

        break;
    }
}
示例#4
0
int main(){
	//set up moves
	Move moves[4] ={{0, -1}, {1, 0}, {0, 1}, {-1, 0}};
	
	//set up hash table
	HashTable *hashTable;
	HashTable *queueTable;
	int tableSize = pow(SIZE, 9) - SIZE + 1;

	int nos[SIZE * SIZE];
	int g[SIZE * SIZE];
	char *nums = (char *)calloc(SIZE * SIZE, sizeof(char));
	//char nums[9] = {'7', '2', '4', '5', '6', '0', '8', '3', '1'};
	nums = readData();
	char *gl = (char *)calloc(SIZE * SIZE, sizeof(char));
	//char gl[9] =  {'2', '4', '1', '7', '8', '6', '5', '0', '3'};
	gl = readData();
	int i;
	//converts char* to int*
	for(i = 0; i < SIZE * SIZE; i++) nos[i] = (int)nums[i] - '0';
	for(i = 0; i < SIZE * SIZE; i++) g[i] = (int)gl[i] - '0';
	goal = (Board *)calloc(1, sizeof(Board));
	insertTiles(goal, g);
	setNumbers(goal);
	start = (Board *)calloc(1, sizeof(Board));
	insertTiles(start, nos);
	setNumbers(start);
	start->depth = 0;
	printf("\nSTART:\n");
	printBoard(start);
	printf("\nGOAL:\n");
	printBoard(goal);
	Queue *queue;
	Board *newBoard;
	int f;
	for (f = 0; f < 5; f++){
		success = 0;
		hashTable = (HashTable *)createHashTable(tableSize);
		queueTable = (HashTable *)createHashTable(tableSize);
		solution = (Board *)calloc(1, sizeof(Board));
		Board *board = (Board *)calloc(1, sizeof(Board));
		board = start;
		switch(f){
			case 0:
				board->f = getH(board);
				break;
			case 1:
				board->f = getHout(board);
				break;
			case 2:
				board->f = getHmanhattan(board);
				break;
			case 3:
				board->f = getHgreat2(board);
				break;
			case 4:
				board->f = getHgreat3(board);
				break;
			default:
				printf("error\n");
		}
		//set up queue
		queue = (Queue *)createQueue();
		int error;
		if((error = insert(queue, board)) == 1){
			printf("failed to insert starting board\n");
			exit(1);
		}
		Node *current;
		//Board *newBoard;
		int m;
		int fVal;
		int tries = 0;
		//iterate through queue until done
		while(!success){	
			current = queue->head;
			if((fVal = lookupBoard(hashTable, current->b)) == -1) {
				if((error = addBoard(hashTable, current->b)) == 1) {
					printf("failed to add board to hashtable\n");
					exit(1);
				}
				//moves
				for(m = 0; m < 4; m++){
					if(!success) {
						if((newBoard = makeBoardOnMove(current, moves[m], f)) != NULL){
							if(newBoard->value == goal->value){
								success = 1;
								solution = newBoard;
							}
							if((fVal = lookupBoard(queueTable, newBoard)) == -1){
								tries++;
								if((error = insert(queue, newBoard)) == 1) {
									printf("failed to insert new board\n");
									exit(1);
								}
								if((error = addBoard(queueTable, newBoard)) == 1) {
									printf("failed to add new Board to queuetable\n");
									exit(1);
								}
							} else if(newBoard->f < fVal) {
								tries++;
								if((error = replace(queue, newBoard)) == 1) {
									printf("failed to replace with new board\n");
									exit(1);
								} 
								error = addBoard(queueTable, newBoard);
							} else {
								free(newBoard);
							}
						}
					}
				}
			}
			pop(queue);
			if(queue->head == NULL)printf("Empty Queue\n");
		}
		//print out results
		printf("\nTRIES:  %d\n", tries);
		printf("COST:  %d\n", solution->depth);
		printf("EST. DIST. START TO GOAL:  %d\n", start->f);
		printf("\nSOLUTION:  ");
		printPath(solution);
		int ql = getQueueLength(queue);
		printf("QUEUE LEN:  %d\n\n", ql);
		freeQueue(queue);
		free(queue);
		free(hashTable);
		free(queueTable);
		hashTable = NULL;
		queueTable = NULL;
		queue = NULL;
	}
	return 1;
}
示例#5
0
void setStageBackground(int bn) {
  int i, j, k;
  bdIdx = 0;

  switch ( bn ) {
  case 0:
  case 6:
    addBoard(9000, 9000, 500, 25000, 25000);
    for ( i=0 ; i<4 ; i++ ) {
      for ( j=0 ; j<4 ; j++ ) {
	if ( i > 1 || j > 1 ) {
	  addBoard(i*16384, j*16384, 500, 10000+(i*12345)%3000, 10000+(j*54321)%3000);
	}
      }
    }
    for ( j=0 ; j<8 ; j++ ) {
      for ( i=0 ; i<4 ; i++ ) {
	addBoard(0, i*16384, 500-j*50, 20000-j*1000, 12000-j*500);
      }
    }
    for ( i=0 ; i<8 ; i++ ) {
      addBoard(0, i*8192, 100, 20000, 6400);
    }
    if ( bn == 0 ) {
      boardMx = 40; boardMy = 300;
    } else {
      boardMx = -40; boardMy = 480;
    }
    boardRepx = boardRepy = 65536;
    boardRepXn = boardRepYn = 4;
    break;
  case 1:
    addBoard(12000, 12000, 400, 48000, 48000);
    addBoard(12000, 44000, 400, 48000, 8000);
    addBoard(44000, 12000, 400, 8000, 48000);
    for ( i=0 ; i<16 ; i++ ) {
      addBoard(0, 0, 400-i*10, 16000, 16000);
      if ( i < 6 ) {
	addBoard(9600, 16000, 400-i*10, 40000, 16000);
      }
    }
    boardMx = 128; boardMy = 512;
    boardRepx = boardRepy = 65536;
    boardRepXn = boardRepYn = 4;
    break;
  case 2:
    for ( i=0 ; i<16 ; i++ ) {
      addBoard(7000+i*3000, 0, 1600-i*100, 24000, 5000);
      addBoard(7000+i*3000, 50000, 1600-i*100, 4000, 10000);
      addBoard(-7000-i*3000, 0, 1600-i*100, 24000, 5000);
      addBoard(-7000-i*3000, 50000, 1600-i*100, 4000, 10000);
    }
    boardMx = 0; boardMy = 1200;
    boardRepx = 0;
    boardRepy = 65536;
    boardRepXn = 1;
    boardRepYn = 10;
    break;
  case 3:
    addBoard(9000, 9000, 500, 30000, 30000);
    for ( i=0 ; i<4 ; i++ ) {
      for ( j=0 ; j<4 ; j++ ) {
	if ( i > 1 || j > 1 ) {
	  addBoard(i*16384, j*16384, 500, 12000+(i*12345)%3000, 12000+(j*54321)%3000);
	}
      }
    }
    for ( i=0 ; i<4 ; i++ ) {
      for ( j=0 ; j<4 ; j++ ) {
	if ( (i > 1 || j > 1) && (i+j)%3 == 0 ) {
	  addBoard(i*16384, j*16384, 480, 9000+(i*12345)%3000, 9000+(j*54321)%3000);
	}
      }
    }
    addBoard(9000, 9000, 480, 20000, 20000);
    addBoard(9000, 9000, 450, 20000, 20000);
    addBoard(32768, 40000, 420, 65536, 5000);
    addBoard(30000, 32768, 370, 4800, 65536);
    addBoard(32768, 0, 8, 65536, 10000);
    boardMx = 10; boardMy = 100;
    boardRepx = boardRepy = 65536;
    boardRepXn = boardRepYn = 4;
    break;
  case 4:
    addBoard(32000, 12000, 160, 48000, 48000);
    addBoard(32000, 44000, 160, 48000, 8000);
    addBoard(64000, 12000, 160, 8000, 48000);
    for ( i=0 ; i<16 ; i++ ) {
      addBoard(20000, 0, 160-i*10, 16000, 16000);
      if ( i < 6 ) {
	addBoard(29600, 16000, 160-i*10, 40000, 16000);
      }
    }
    boardMx = 0; boardMy = 128;
    boardRepx = boardRepy = 65536;
    boardRepXn = 2; boardRepYn = 2;
    break;
  case 5:
    for ( k=0 ; k<5 ; k++ ) {
      j = 0;
      for ( i=0 ; i<16 ; i++ ) {
	addBoard(j, i*4096, 200-k*10, 16000, 4096);
	addBoard(j+16000-j*2, i*4096, 200-k*10, 16000, 4096);
	if ( i < 4 ) j += 2000;
	else if ( i < 6 ) j -= 3500;
	else if ( i < 12 ) j += 1500;
	else j -= 2000;
      }
    }
    boardMx = -10; boardMy = 25;
    boardRepx = boardRepy = 65536;
    boardRepXn = boardRepYn = 2;
    break;
  }
}