本文整理汇总了C++中Pos::price方法的典型用法代码示例。如果您正苦于以下问题:C++ Pos::price方法的具体用法?C++ Pos::price怎么用?C++ Pos::price使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pos
的用法示例。
在下文中一共展示了Pos::price方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getNextCloseTo
int Board::getNextCloseTo(int s, int d, bool diag, int lastIndex)
{
if(s == d)
return(-1); // What can I say, we're here! ;o)
const int firstN = diag ? 4 : 0;
const int lastN = diag ? 8 : 4;
Pos *root = new Pos(0, s, 0), *list = root;
// List of indexes.
for(; list; list = list->listNext()) {
Pos *p;
// Check if current list node is the destination position.
if(list->index() == d) {
// Find first movement after root.
for(; ; list = p) {
p = list->parent();
if(p == root) {
// This is our move.
int nextSq = list->index();
delete root;
index(nextSq);
return(nextSq);
}
}
qFatal("Never here");
}
// Make possible moves.
for(int n = firstN; n < lastN; n ++) {
int i = getNext(n, list->index());
int pri = list->price() + 1;
// getNext returned valid place?
if(! inBounds(i) || (! isEmpty(i) && i != d)) {
// Or place is out of map or it's not empty,
// so go to the next possible move.
continue;
}
int pi = list->parent() ? list->parent()->index() : lastIndex;
if(pi != -1 && direction(pi, list->index()) !=
direction(list->index(), i)) {
pri += 10;
}
// Check if position wasn't processed yet.
if( (p = root->searchBTree(i))) {
// Position already processed.
// Check price of found position with current one.
if(p->price() > pri) {
// We found a cheapear way to reach the same
// place, so let's change the parent and price of p.
p->setPrice(list->price() + 1);
p->setParent(list);
list->addList(p);
}
continue;
}
// Create new Pos class instance.
p = new Pos(list, i, pri);
// Add.
list->addList(p);
root->addFList(p);
root->addBTree(p);
}
}
// Solution not found.
delete root;
return(-1);
}