// Search the node using key.
void bPlusTree::Lookup(int key)
{
	int pos, i, n, level = 0;
	struct bPlusTreeNode *ptr = root;
	cout << "\nSearch path\n";
	while (ptr != NULL)
	{
		n = ptr->count;
		for (i = 1; i <= ptr->count; i++)
			cout << ptr->value[i] << "  ";
		cout << "\n";
		pos = searchPosition(key, ptr->value, n);
		if (pos <= n && key == ptr->value[pos])
		{
			cout << key << " is found in position " << pos << " of node at level " << level;
			return;
		}
		ptr = ptr->child[pos - 1];
		level++;
	}
	cout << "Key " << key << " is not available";
}
int main() {
    while (scanf("%d", &n) != EOF) {
        int *dp = new int[n];
        for (i = 0; i < n; i++) {
            dp[i] = 10000000;
        }
        int low = 0;
        int high = 0;
        for (i = 0; i < n; i++) {
            scanf("%d", &colNum);
            for (j = 0; j < colNum; j++) {
                scanf("%d", &array[j]);
                posArr[j] = searchPosition(dp, low, high, array[j]);
            }
            for (j = 0; j < colNum; j++) {
                dp[posArr[j]] = dp[posArr[j]] < array[j] ? dp[posArr[j]] : array[j];
                high = high > posArr[j] + 1 ? high : posArr[j] + 1;
            }
        }
        printf("%d\n", high);
    }
    return 0;
}
Esempio n. 3
0
void consoleLoop(board& b, searchInfo* search) {

	printf("Welcome to PENIQLIOTUV In Console Mode!\n");
	printf("Type help for commands\n\n");

	search->gameMode = CONSOLEMODE;
	search->postThinking = true;
	setbuf(stdin, NULL);
  setbuf(stdout, NULL);

	int depth = MAXDEPTH, moveTime = 3000;
	int engineSide = BOTH;
	int move = NOMOVE;
	char inBuf[80], command[80];

	engineSide = BLACK;
	parseFen(START_FEN, b);

	while(true) {
		fflush(stdout);
		if(b.side == engineSide && checkResult(b) == false) {
			search->startTime = getTime();
			search->depth = depth;

			if(moveTime != 0) {
				search->timeSet = true;
				search->stopTime = search->startTime + moveTime;
			}
			searchPosition(b, search);
		}
		std::cout << std::endl << "PENIQLIOTUV > ";

		memset(&inBuf[0], 0, sizeof(inBuf));
		fflush(stdout);
		if (!fgets(inBuf, 80, stdin))
		continue;

		sscanf(inBuf, "%s", command);

		if(!strcmp(command, "help")) {
			printf("Commands:\n");
			printf("quit - quit game\n");
			printf("force - computer will not think\n");
			printf("print - show board\n");
			printf("post - show thinking\n");
			printf("nopost - do not show thinking\n");
			printf("new - start new game\n");
			printf("go - set computer thinking\n");
			printf("depth x - set depth to x\n");
			printf("time x - set thinking time to x seconds (depth still applies if set)\n");
			printf("view - show current depth and movetime settings\n");
			printf("** note ** - to reset time and depth, set to 0\n");
			printf("enter moves using b7b8q notation\n\n\n");
			continue;
		}

		if(!strcmp(command, "quit")) {
			search->quit = true;
			break;
		}

		if(!strcmp(command, "post")) {
			search->postThinking = true;
			continue;
		}

		if(!strcmp(command, "print")) {
			printBoard(b);
			continue;
		}

		if(!strcmp(command, "nopost")) {
			search->postThinking = false;
			continue;
		}

		if(!strcmp(command, "force")) {
			engineSide = BOTH;
			continue;
		}

		if(!strcmp(command, "view")) {
			if(depth == MAXDEPTH) printf("depth not set ");
			else printf("depth %d",depth);

			if(moveTime != 0) printf(" movetime %ds\n",moveTime/1000);
			else printf(" movetime not set\n");

			continue;
		}

		if(!strcmp(command, "depth")) {
			sscanf(inBuf, "depth %d", &depth);
		  if(depth==0) {
				depth = MAXDEPTH;
			}
			continue;
		}

		if(!strcmp(command, "time")) {
			sscanf(inBuf, "time %d", &moveTime);
			moveTime *= 1000;
			continue;
		}

		if(!strcmp(command, "new")) {
			engineSide = BLACK;
			parseFen(START_FEN, b);
			continue;
		}

		if(!strcmp(command, "go")) {
			engineSide = b.side;
			continue;
		}

		move = parseMove(inBuf, b);
		if(move == NOMOVE) {
			printf("Command unknown:%s\n",inBuf);
			continue;
		}
		makeMove(b, move);
		b.ply=0;
    }
}
Esempio n. 4
0
int nextMove(char ** arr,int row,int col,char * dir)
{
	int y,speed;
	int i=0,j=0;
	searchPosition(arr,row,col,&i,&j);
	arr[i][j]='-';
	if(strcmp(dir,"right")==0)
	{
		if(j+2>=col)
			j=col-1;
		else
			j=j+2;
		speed =newSpeed(arr[i][j]);
		while(speed!=4)
		{
			arr[i][j]='-';
			if(speed==0)
				moveLeft(&i,&j,row,col);
			else if(speed==1)
				moveRight(&i,&j,row,col);
			else if(speed==2)
				moveUp(&i,&j,row,col);
			else if(speed==3)
				moveDown(&i,&j,row,col);
			speed=newSpeed(arr[i][j]);
		}		
		arr[i][j]='G';
		return speed;
	}
	else if(strcmp(dir,"left")==0)
        {
                y=-2;
		if(j+y<0)
			j=0;
		else
			j=j+y;
		speed =newSpeed(arr[i][j]);
		while(speed!=4)
		{
			arr[i][j]='-';
			if(speed==0)
				moveLeft(&i,&j,row,col);
			else if(speed==1)
				moveRight(&i,&j,row,col);
			else if(speed==2)
				moveUp(&i,&j,row,col);
			else if(speed==3)
				moveDown(&i,&j,row,col);
			arr[i][j]='-';
			speed=newSpeed(arr[i][j]);
		}		
		arr[i][j]='G';
		return speed;
        }
	else if(strcmp(dir,"up")==0)
        {
                y=-1;
		if(i+y<0)
			i=0;
		else
			i=i+y;
		speed =newSpeed(arr[i][j]);
		while(speed!=4)
		{
			arr[i][j]='-';
			if(speed==0)
				moveLeft(&i,&j,row,col);
			else if(speed==1)
				moveRight(&i,&j,row,col);
			else if(speed==2)
				moveUp(&i,&j,row,col);
			else if(speed==3)
				moveDown(&i,&j,row,col);

			arr[i][j]='-';
			speed=newSpeed(arr[i][j]);
		}		
		arr[i][j]='G';
		return speed;
        }
	else
	{
		if(i+1>=row)
			i=row-1;
		else
			i=i+1;
		speed =newSpeed(arr[i][j]);
		while(speed!=4)
		{
			arr[i][j]='-';
			if(speed==0)
				moveLeft(&i,&j,row,col);
			else if(speed==1)
				moveRight(&i,&j,row,col);
			else if(speed==2)
				moveUp(&i,&j,row,col);
			else if(speed==3)
				moveDown(&i,&j,row,col);

			arr[i][j]='-';
			speed=newSpeed(arr[i][j]);
		}		
		arr[i][j]='G';
		return speed;
	}
}