睡前XJB写两句。。
你需要这么几个helper function:
void PushToCornor(Block) //把一个俄罗斯方块推向一个NXN grid的某个角落
void Rotate(Block, direction) //向direction rotate你的方块
attach_another_square_to_this_square() //这个没想清楚signature,意思就是拿到
一个square,给他attach一个legitimate neighboring square
然后递归解:
//以下都是秀逗扣的:
vector generateBlocks(target, current, vector & current_blocks
) {
if (current == target) {
return current_blocks;
}
for(auto block: blocks) {
for(auto square: block) {
square.attach_another_square_to_this_square();
for all 3 rotation directions {
Rotate(block, direction)
PushToCorner(block)
if (find(current_blocks.begin(), cucrent_blocks.end(), block
) == current_blocks.end()) {
current_blocks.push_back(block);
generateBlocks(target, current+1, current_blocks);
current_blocks.pop_back();
}
}
}
}
}
大概就是这么个意思吧。。。直接在这个框里写代码好麻烦。。。