Im new to coding and Ive seen that my program can be written

I\'m new to coding and I\'ve seen that my program can be written much simpler, but what I have now should be just fine. However I am having a problem getting what I think should be a while loop to execute. In the case of this program when the player either rolls a 1 or \"holds\" the program passes to the devil\'s turn. The devil then rolls until he has 21 points if he is ahead or tied, or 30 points if he is losing. The devil can also roll a 1 and lose his turn and the points that he acquired during that turn. When I run my program the devil scores 0. I\'ve been able to make some adjustments, but it seems to kick out after the devil rolls once and goes back to being the players turn. The devil roll function is on line 47.

Solution

import java.awt.Color;
import java.util.Comparator;

/**
* a straightforward red-black tree category.
*/
public category RedBlackTree extends BinarySearchTree Associate in Nursing empty RedBlackTree which will solely settle for Comparables as
* items.
*/
public RedBlackTree()

/**
* Constructs Associate in Nursing empty RedBlackTree that orders its things in keeping with the
* given comparator.
*/
public RedBlackTree(Comparator c)

/**
* The nodes during a red-black tree store a color beside the particular information
* within the node.
*/
category Node extends LinkedBinaryTreeNode
}

/**
* Adds one information item to the tree. If there\'s already Associate in Nursing item within the
* tree that compares up to the item being inserted, it\'s \"overwritten\"
* by the new item. Overrides BinarySearchTree.add as a result of the tree must
* be adjusted when insertion.
*/
public void add(Object data)
BinaryTreeNode n = root;
whereas (true) else if (comparisonResult < 0)
n = n.getLeft();
} else zero
if (n.getRight() == null)
n = n.getRight();
}
}
}

/**
* Removes the node containing the given price. will nothing if there\'s no
* such node.
*/
public void remove(Object data) else if (node.getLeft() != null && node.getRight() != null) 2 kids, Copy forerunner information in.
BinaryTreeNode forerunner = predecessor(node);
node.setData(predecessor.getData());
node = (Node) predecessor;
}
// At this time node has zero or one kid
Node pullUp = leftOf(node) == null ? rightOf(node) : leftOf(node);
if (pullUp != null) regulate if pullUp could be a double black.
if (node == root) else if (node.getParent().getLeft() == node) else
if (isBlack(node))
} else if (node == root) to drag up once deleting a root means that we have a tendency to empty the tree
setRoot(null);
} else lookout
if (isBlack(node))
node.removeFromParent();
}
}

/**
* Classic formula for fixing up a tree when inserting a node.
*/
personal void adjustAfterInsertion(Node n) issues, if they exist
if (n != null && n != root && isRed(parentOf(n))) to ascertain if additional work
// needed
if (isRed(siblingOf(parentOf(n))))

// Step 2b: reconstitute for a parent United Nations agency is that the left kid of the
// forebear. this may need one right rotation if n is
// also
// a left kid, or a left-right rotation otherwise.
else if (parentOf(n) == leftOf(grandparentOf(n)))
setColor(parentOf(n), Color.black);
setColor(grandparentOf(n), Color.red);
rotateRight(grandparentOf(n));
}

// Step 2c: reconstitute for a parent United Nations agency is that the right kid of the
// forebear. this may need one left rotation if n is
// also
// a right kid, or a right-left rotation otherwise.
else if (parentOf(n) == rightOf(grandparentOf(n)))
setColor(parentOf(n), Color.black);
setColor(grandparentOf(n), Color.red);
rotateLeft(grandparentOf(n));
}
}

// Step 3: Color the foundation black
setColor((Node) root, Color.black);
}

/**
* Classic formula for fixing up a tree when removing a node; the
* parameter to the present technique is that the node that was force up to wherever the
* removed node was.
*/
personal void adjustAfterRemoval(Node n) {
whereas (n != root && isBlack(n)) {
if (n == leftOf(parentOf(n))) {
// force up node could be a left kid
Node relative = rightOf(parentOf(n));
if (isRed(sibling)) {
setColor(sibling, Color.black);
setColor(parentOf(n), Color.red);
rotateLeft(parentOf(n));
relative = rightOf(parentOf(n));
}
if (isBlack(leftOf(sibling)) && isBlack(rightOf(sibling))) else {
if (isBlack(rightOf(sibling))) {
setColor(leftOf(sibling), Color.black);
setColor(sibling, Color.red);
rotateRight(sibling);
relative = rightOf(parentOf(n));
}
setColor(sibling, colorOf(parentOf(n)));
setColor(parentOf(n), Color.black);
setColor(rightOf(sibling), Color.black);
rotateLeft(parentOf(n));
n = (Node) root;
}
} else {
// force up node could be a right kid
Node relative = leftOf(parentOf(n));
if (isRed(sibling)) {
setColor(sibling, Color.black);
setColor(parentOf(n), Color.red);
rotateRight(parentOf(n));
relative = leftOf(parentOf(n));
}
if (isBlack(leftOf(sibling)) && isBlack(rightOf(sibling))) else {
if (isBlack(leftOf(sibling))) {
setColor(rightOf(sibling), Color.black);
setColor(sibling, Color.red);
rotateLeft(sibling);
relative = leftOf(parentOf(n));
}
setColor(sibling, colorOf(parentOf(n)));
setColor(parentOf(n), Color.black);
setColor(leftOf(sibling), Color.black);
rotateRight(parentOf(n));
n = (Node) root;
}
}
}
setColor(n, Color.black);
}

// the subsequent helpers dramatically modify the code by obtaining
// all the null pointer sorting out of the adjustment strategies.

personal Color colorOf(Node n) come back n == null ? Color.black : n.color;
}

personal mathematician isRed(Node n) come back n != null && colorOf(n) == Color.red;
}

personal mathematician isBlack(Node n) come back n == null || colorOf(n) == Color.black;
}

personal void setColor(Node n, Color c)

personal Node parentOf(Node n) come back n == null ? null : (Node) n.getParent();
}

personal Node grandparentOf(Node n) come back (n == null || n.getParent() == null) ? null : (Node) n
.getParent().getParent();
}

personal Node siblingOf(Node n) come back (n == null || n.getParent() == null) ? null : (n == n
.getParent().getLeft()) ? (Node) n.getParent().getRight()
: (Node) n.getParent().getLeft();
}

personal Node leftOf(Node n) come back n == null ? null : (Node) n.getLeft();
}

personal Node rightOf(Node n) come back n == null ? null : (Node) n.getRight();
}
}

I\'m new to coding and I\'ve seen that my program can be written much simpler, but what I have now should be just fine. However I am having a problem getting wh
I\'m new to coding and I\'ve seen that my program can be written much simpler, but what I have now should be just fine. However I am having a problem getting wh
I\'m new to coding and I\'ve seen that my program can be written much simpler, but what I have now should be just fine. However I am having a problem getting wh
I\'m new to coding and I\'ve seen that my program can be written much simpler, but what I have now should be just fine. However I am having a problem getting wh

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site