void moveTower (int disks, char start, char end, char temp) { if (disks == 1) ; else { moveTower (disks-1, start, temp, end); // move one disk from start to end moveTower (disks-1, temp, end, start); } }
void moveTower(int n , int origin, int dest, int temp) // a = org , b = dest , c = buffer { if(n==0)return; moveTower(n-1 , origin , temp , dest); int topVal = S[origin].pop(); S[dest].push(topVal); moveTower(n-1 , temp , dest , origin); }
void moveTower(int n, char start, char finish, char temp) { if (n == 1) moveSingle(start, finish); else { moveTower(n-1, start, temp, finish); moveSingle(start, finish); moveTower(n-1, temp, finish, start); } }
void moveTower (int num_of_disc, char start_axis, char end_axis, char tmp_axis) { if (1 == num_of_disc) { moveDisc(start_axis, end_axis); } else { moveTower (num_of_disc-1, start_axis, tmp_axis, end_axis); moveDisc (start_axis, end_axis); moveTower (num_of_disc-1, tmp_axis, end_axis, start_axis); } }
void moveItem(int x, int y) { point p; if (item) { p.x = x; p.y = y; moveTower(item, p); } }
int main() { int TowerSize = 20; for(int i = TowerSize ; i>=1; i--) S[0].push(i); moveTower(TowerSize, 0, 2, 1); while(!S[2].isEmpty()) { cout<< S[2].pop() <<endl; } }
void initMenu() { int i; point p; item = NULL; p.x = 290; p.y = 43; for (i = 0; i < MAX_TOWERS; i++) { itens[i] = towers[i]; moveTower(&itens[i], p); p.x += 75; } }
int main (int argc, char* argv[]) { if (argc != 2) return; int num_of_disc = atoi(argv[1]); char start_axis = A; char end_axis = B; char tmp_axis = C; moveTower(num_of_disc, start_axis, end_axis, tmp_axis); return 0; }
void BaseTower::onTouchMoved(Touch* pTouch, Event* pEvent) { //停止炮塔的渐隐动画 this->towerSprite->stopAllActions(); this->towerSprite->setOpacity(255); Vec2 pos = this->getParent()->convertToNodeSpaceAR(pTouch->getLocation()); //map是parent //如果被选中,哨戒炮不能移动 if (isSelected) { //这里还需要误差处理 listener->setSwallowTouches(true);//只移动炮塔,不移动地图 moveTower(pos); } }
int main(int argc, char *argv[]) { int target; char start='A'; char finish='B'; char temp='C'; if (argc != 2) return 0; target = atoi(argv[1]); moveTower(target, start, finish, temp); return 0; }
int main() { int totalDisks; totalDisks = 3; moveTower(totalDisks, 'A', 'B', 'C'); }