Submission.

This commit is contained in:
Alex Huddleston 2017-10-31 01:05:02 -05:00
parent 73e5f291c0
commit 24dcec83fe
3 changed files with 47 additions and 44 deletions

BIN
hw2/hw2.zip Normal file

Binary file not shown.

View file

@ -214,10 +214,11 @@ int main(int argc, char **argv)
tree = makeTree(input.substr(1), root, 1);
root = get<0>(tree);
printTree(root);
//printTree(root);
minmax(&root);
printTree(root);
//printTree(root);
cout << root.getValue() << endl;
return 0;
}

View file

@ -20,36 +20,37 @@ void minmax(node *n)
if(n->getLevel() % 2 == 0)
{
int max = n->getValue();
if(n->getChildren().size() > 0)
{
for(int c = 0; c < n->getChildren().size(); c++)
{
n->getChildAt(c)->setBeta(n->getBeta());
n->getChildAt(c)->setAlpha(n->getAlpha());
n->getChildAt(c)->setBeta(n->getBeta());
n->getChildAt(c)->setAlpha(n->getAlpha());
cout << "Alpha: " << n->getAlpha() << " Beta: " << n->getBeta() << endl;
//cout << "Alpha: " << n->getAlpha() << " Beta: " << n->getBeta() << endl;
minmax(n->getChildAt(c));
minmax(n->getChildAt(c));
if(n->getChildAt(c)->getValue() > max)
{
max = n->getChildAt(c)->getValue();
}
if(n->getChildAt(c)->getValue() > n->getAlpha())
{
n->setAlpha(n->getChildAt(c)->getValue());
}
if(n->getChildAt(c)->getValue() > n->getAlpha())
{
n->setAlpha(n->getChildAt(c)->getValue());
}
if(n->getAlpha() >= n->getBeta())
{
cout << "Beta pruning" << endl;
break;
}
if(n->getAlpha() >= n->getBeta())
{
cout << "Beta pruning" << endl;
break;
}
}
}
n->setValue(max);
//cout << n->getValue() << endl;
}
else
@ -59,32 +60,32 @@ void minmax(node *n)
{
for(int c = 0; c < n->getChildren().size(); c++)
{
n->getChildAt(c)->setBeta(n->getBeta());
n->getChildAt(c)->setAlpha(n->getAlpha());
n->getChildAt(c)->setBeta(n->getBeta());
n->getChildAt(c)->setAlpha(n->getAlpha());
cout << "Alpha: " << n->getAlpha() << " Beta: " << n->getBeta() << endl;
//cout << "Alpha: " << n->getAlpha() << " Beta: " << n->getBeta() << endl;
minmax(n->getChildAt(c));
minmax(n->getChildAt(c));
if(n->getChildAt(c)->getValue() < min)
{
min = n->getChildAt(c)->getValue();
}
if(n->getChildAt(c)->getValue() < n->getBeta())
{
n->setBeta(n->getChildAt(c)->getValue());
}
if(n->getChildAt(c)->getValue() < n->getBeta())
{
n->setBeta(n->getChildAt(c)->getValue());
}
if(n->getBeta() <= n->getAlpha())
{
cout << "Alpha pruning." << endl;
break;
}
if(n->getBeta() <= n->getAlpha())
{
cout << "Alpha pruning." << endl;
break;
}
}
}
n->setValue(min);
//cout << n->getValue() << endl;
}
}
@ -140,16 +141,16 @@ tuple<node, string> makeTree(string input, node n, int level)
{
node tempnode;
tempnode.setLevel(level);
int negatemp = stoi(tempn);
if(negate)
{
negatemp = -negatemp;
}
int negatemp = stoi(tempn);
if(negate)
{
negatemp = -negatemp;
}
tempnode.setValue(negatemp);
tempnode.setParent(&n);
n.addChild(tempnode);
tempn = "";
negate = false;
negate = false;
}
}
@ -160,16 +161,16 @@ tuple<node, string> makeTree(string input, node n, int level)
{
node tempnode;
tempnode.setLevel(level);
int negatemp = stoi(tempn);
if(negate)
{
negatemp = -negatemp;
}
int negatemp = stoi(tempn);
if(negate)
{
negatemp = -negatemp;
}
tempnode.setValue(negatemp);
tempnode.setParent(&n);
n.addChild(tempnode);
tempn = "";
negate = false;
negate = false;
}
tuple<node, string> tempt(n, input);
return tempt;
@ -242,10 +243,11 @@ int main(int argc, char **argv)
tree = makeTree(input.substr(1), root, 1);
root = get<0>(tree);
printTree(root);
//printTree(root);
minmax(&root);
printTree(root);
//printTree(root);
cout << root.getValue() << endl;
return 0;
}