本文整理汇总了C++中MoveList::getRowCol方法的典型用法代码示例。如果您正苦于以下问题:C++ MoveList::getRowCol方法的具体用法?C++ MoveList::getRowCol怎么用?C++ MoveList::getRowCol使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MoveList
的用法示例。
在下文中一共展示了MoveList::getRowCol方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
/*board is the board right now. lvl is the lvl of the node we are creating,
row and col is the position of the most recently added piece. row and col are
not relevant when lvl is 0 and are invalid*/
Cathy::Node* Cathy::GameTree::CreateTree(int board[][NUMSQUARES],int lvl){
Node* nn=new Node();
int whowon;
int whomoves=(lvl%2)?-player_:player_;
MoveList p1;
MoveList p2;
MoveList flips;
int nump1,nump2;
int r,c;
int newboard[NUMSQUARES][NUMSQUARES];
wchar_t debugStr[255 + 1];
int maxOrMin = lvl%2; // 0 is max, 1 is min
if(!canMove(board, p1, p2) || boardFull(board)){ //game over, neither player can move
getScores(board,nump1,nump2);
if(nump1==nump2)
whowon=0;
else if(nump1>nump2)
whowon=1;
else
whowon=-1;
//Base case 1: someone has won the game, game is over score is 100
if(whowon) {
nn->score_=whowon * player_* MAXSCORE; //if player_ is 1 and they won the whowon would be +ve so
//we have score being +1, otherwise if player_ is -1 and
//player 2 won, then whowon would be -1 so score will still
//be +1.
}
}
else if(lvl==height_-1){ //tree has reached its max height
nn->score_=Eval(board,player_, p1, p2); //always evaluate for player at root!
}
else{
if(whomoves==1){
if(p1.numMoves()==0){
nn->noMove_=CreateTree(board,lvl+1);
}
else{
for(int i=0,prev_r=0,prev_c=0;i<p1.numMoves();i++){
p1.getRowCol(i,r,c);
flips.clear();
addPiece(board,r,c,1,flips);
if( i == 0 ){ // if it is the first node, then create it
nn->child_[r][c] = CreateTree(board,lvl+1);
prev_r = r, prev_c = c;
}
else{
if(maxOrMin == 0){ //otherwise, check before create, depending on lvl
if(nn->child_[prev_r][prev_c]->score_ < Eval(board,player_,p1,p2) ){
nn->child_[prev_r][prev_c] = NULL;
//delete nn->child_[prev_r][prev_c];
nn->child_[r][c] = CreateTree(board,lvl+1);
prev_r = r, prev_c = c;
}
}
else if(maxOrMin ==1){
if(nn->child_[prev_r][prev_c]->score_ > Eval(board,player_,p1,p2) ){
nn->child_[prev_r][prev_c] = NULL;
//delete nn->child_[prev_r][prev_c];
nn->child_[r][c] = CreateTree(board,lvl+1);
prev_r = r, prev_c = c;
}
}
}
/*undo the changes before testing the next move*/
board[r][c]=0;
for(int j=0;j<flips.numMoves();j++){
flips.getRowCol(j,r,c);
board[r][c]=-1;
}
}
}
}
else{
if(p2.numMoves()==0){
nn->noMove_=CreateTree(board,lvl+1);
}
else{
for(int i=0,prev_r=0,prev_c=0;i<p2.numMoves();i++){
p2.getRowCol(i,r,c);
flips.clear();
addPiece(board,r,c,-1,flips);
if( i == 0 ){ // if it is the first node, the create it
nn->child_[r][c] = CreateTree(board,lvl+1);
prev_r = r, prev_c = c;
}
else{
if(maxOrMin == 0){ //otherwise, check before create, depending on lvl
if(nn->child_[prev_r][prev_c]->score_ < Eval(board,player_,p1,p2) ){
//.........这里部分代码省略.........