void InnerNode::balanceWithRight( InnerNode* rightsib, int pidx ) { // THIS has more than RIGHTSIB; move some items from THIS to RIGHTSIB. // PIDX is the index of the parent item that will change when keys // are moved. PRECONDITION( Psize() >= rightsib->Vsize() ); PRECONDITION( parent->getTree(pidx) == rightsib ); int newThisSize = (Psize() + rightsib->Vsize())/2; int noFromThis = Psize() - newThisSize; pushRight( noFromThis, rightsib, pidx ); }
//增加下一个地图的步骤 void addNxtStep(struct sokomap *header,struct sokomap **currentTail,struct sokomap *current,struct mappos * boxPos,int boxCount) { //计算人所在的列表 if(current->pos==NULL) { current->pos = personCanWalkPoint(current); } getBoxList(current,boxPos); //进行循环判断箱子可以移动的方向 for(int i=0;i < boxCount;i++) { int x = boxPos[i].x; int y = boxPos[i].y; //向上推的操作 if(isCanPushUp(current,x,y)) { if(isInMappos(current->pos,boxPos[i].x,boxPos[i].y+1)) { struct sokomap * tmpMap = copyMap(current); tmpMap ->parent = current; pushUp(tmpMap,x,y); //判断地图是否已经棍了,没棍的话就加入到尾步 if(isMapDead(tmpMap,x,y+1,UP)) { freeMap(tmpMap); }else if(isInSokoMap(header,tmpMap))//已经在列表中,就把这个新地图删除 { freeMap(tmpMap); }else { (*currentTail)->next = tmpMap; *currentTail = tmpMap; } } } //向下推的操作 if(isCanPushDown(current,boxPos[i].x,boxPos[i].y)) { if(isInMappos(current->pos,boxPos[i].x,boxPos[i].y - 1)) { struct sokomap * tmpMap = copyMap(current); tmpMap ->parent = current; pushDown(tmpMap,x,y); //判断地图是否已经棍了,没棍的话加入到尾部 if(isMapDead(tmpMap,x,y-1,DOWN)) { freeMap(tmpMap); }else if(isInSokoMap(header,tmpMap))//已经在列表中,就把这个新地图删除 { freeMap(tmpMap); }else { (*currentTail)->next = tmpMap; *currentTail = tmpMap; } } } //向左推的操作 if(isCanPushLeft(current,boxPos[i].x,boxPos[i].y)) { if(isInMappos(current->pos,boxPos[i].x + 1,boxPos[i].y)) { struct sokomap * tmpMap = copyMap(current); tmpMap ->parent = current; pushLeft(tmpMap,x,y); //判断地图是否已经棍了,没棍的话加入到尾部 if(isMapDead(tmpMap,x - 1,y,LEFT)) { freeMap(tmpMap); }else if(isInSokoMap(header,tmpMap))//已经在列表中,就把这个新地图删除 { freeMap(tmpMap); }else { (*currentTail)->next = tmpMap; *currentTail = tmpMap; } } } //向右推的操作 if(isCanPushRight(current,boxPos[i].x,boxPos[i].y)) { if(isInMappos(current->pos,boxPos[i].x - 1,boxPos[i].y)) { struct sokomap * tmpMap = copyMap(current); tmpMap ->parent = current; pushRight(tmpMap,x,y); //判断地图是否已经棍了,没棍的话加入到尾部 if(isMapDead(tmpMap,x + 1,y,RIGHT)) { freeMap(tmpMap); }else if(isInSokoMap(header,tmpMap))//已经在列表中,就把这个新地图删除 { freeMap(tmpMap); }else { (*currentTail)->next = tmpMap; *currentTail = tmpMap; } } } } }
void Pult::connects() { connect(bnStart, SIGNAL(pressed()), this, SLOT(pushStart())); connect(bnLeft, SIGNAL(pressed()), this, SLOT(pushLeft())); connect(bnRight, SIGNAL(pressed()), this, SLOT(pushRight())); }