不知道

状态空间搜索算法
vi oldId = id( oldState );
int& oldDir = direction[oldId];
//--- Apply all applicable moves to it and handle the new state.
for( int move=0; move<18; move++ ){
if( applicableMoves[phase] & (1 << move) ){
//--- Apply the move.
vi newState = applyMove( move, oldState );
vi newId = id( newState );
int& newDir = direction[newId];
//--- Have we seen this state (id) from the other direction already?
//--- I.e. have we found a connection?
if( newDir && newDir != oldDir ){
//--- Make oldId represent the forwards and newId the backwards search state.
if( oldDir > 1 ){
swap( newId, oldId );
move = inverse( move );
}
//--- Reconstruct the connecting algorithm.
vi algorithm( 1, move );
while( oldId != currentId ){
algorithm.insert( algorithm.begin(), lastMove[ oldId ] );
oldId = predecessor[ oldId ];
}
while( newId != goalId ){
algorithm.push_back( inverse( lastMove[ newId ] ));
newId = predecessor[ newId ];
}
//--- Print and apply the algorithm.
for( int i=0; i<(int)algorithm.size(); i++ ){
cout << "UDFBLR"[algorithm[i]/3] << algorithm[i]%3+1;
currentState = applyMove( algorithm[i], currentState );
}
//--- Jump to the next phase.
goto nextPhasePlease;
}
//--- If we've never seen this state (id) before, visit it.
if( ! newDir ){
q.push( newState );
newDir = oldDir;
lastMove[ newId ] = move;
predecessor[ newId ] = oldId;
}
}
}
}
nextPhasePlease:
;
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值