|
|
back to boardSo easy ! In this website, there are many problems similar to this problem. So, it costs me no efforts to solve it ! Hint for you : int travel(int player,int node) { int value; if(isLeaf(node)) return getValue(node); // If the first player is at this node, he prefer getting the maximal value among -1, 0 and +1. if(player == 0) { value = MinValue(); for(int a=0;a<numberOfChild(node);a++) { int v = travel((player+1)%2,getChild(node,a)); if(value < v) value = v; } } // Get the minimal value. else { value = MaxValue(); for(int a=0;a<numberOfChild(node);a++) { int v = travel((player+1)%2,getChild(node,a)); if(value > v) value = v; } } return value; } Edited by author 24.02.2011 15:14 |
|
|