Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This question needs to use Dynamic Programming technique to solve. Just need to

ID: 3874465 • Letter: T

Question

This question needs to use Dynamic Programming technique to solve. Just need to write the algorithm

1. Consider a gamble with n boxes, each box i being labeled with a probability pi and a cost ci to open box i, a player needs to pay ci, and the content of the box is revealed: a voucher is in it with probability it's e independent of all other boxes. The player will get a reward W if and only if every box is opened and each yields a voucher. The player can choose the order in which she opens the boxes, and can quit at any point. For example, whenever she sees an empty box, she know:s she will never collect any reward, and therefore she should quit. This question asks for a polynomial time algorithm that, given the n labels and the reward W, outputs the optimal order in which the player should open the boxes, and determines if she should enter the game at all. (The player should enter the game if and only if the expected reward is no less than the expected cost. For example, if the two boxes are labeled pi opens the first box first, she will incur a cost of 10 on box 1, and she will continue opening box 2 with probability 0.3 (because if box 1 is empty she should quit the game), which will cost her 5. The expected cost is 10+0.3 × 5-115. Similarly, if the player opens box 2 first, the expected cost is 5 +0.5 10-10. Therefore the optimal ordering is first box 2 then box 1. The expected reward is 0.3 × 0.5W-0.15W. Therefore the player should enter the game if and only if W is at least 10/0.15. ity pi, otherwise it's empty. The event that box i contains a voucher is = 0.3, c-10, and P2- 0.5, c2 = 5. If the player

Explanation / Answer

import javax.swing.JFrame; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.BoxLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.Color; import java.awt.Dimension; public class BlackJack extends JFrame implements ActionListener { private static final int WIDTH = 400, HEIGHT = 300; private Deck deck; Draw draw = new Draw(); private JLabel main = draw.getJLabel(); private Player gambler = new Player("Gambler", 100, 75); private Player dealer = new Player("Dealer", 100, 225); private JButton hitButton = new JButton("Hit Me"); private JButton stickButton = new JButton("Stick"); private JButton dealButton = new JButton("Deal"); private JLabel status = new JLabel(" ", JLabel.CENTER); BlackJack() { setTitle("Blackjack 1.0"); setResizable(false); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // hit, stick, and deal buttons JPanel buttons = new JPanel(); buttons.add(hitButton); buttons.add(stickButton); buttons.add(dealButton); hitButton.addActionListener(this); stickButton.addActionListener(this); dealButton.addActionListener(this); hitButton.setEnabled(false); stickButton.setEnabled(false); // add the dealer, gambler, buttons, and status bar getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS)); getContentPane().add(main); getContentPane().add(buttons); getContentPane().add(status); draw.setCanvasSize(WIDTH, HEIGHT); draw.setXscale(0, WIDTH); draw.setYscale(0, HEIGHT); pack(); setVisible(true); } // deal one card to given player from the deck private void hit(Player player) { player.dealTo(deck.dealFrom()); player.draw(draw); main.repaint(); } // deal out two cards each, shuffling if too few cards private void deal() { draw.clear(Color.GRAY); gambler.reset(); dealer.reset(); if (deck == null || deck.size() < 15) { deck = new Deck(); deck.shuffle(); status.setText("Shuffling"); } hit(gambler); hit(dealer); dealer.peak().conceal(); // hide the dealer's first card hit(gambler); hit(dealer); } // who won? private void checkWinner() { dealer.peak().reveal(); // time to reveal dealer's card dealer.draw(draw); main.repaint(); if (gambler.value() > 21) status.setText("Gambler busts"); else if (dealer.value() > 21) status.setText("Dealer busts"); else if (gambler.value() == dealer.value()) status.setText("Push"); else if (gambler.value() > dealer.value()) status.setText("Gambler wins"); else status.setText("Dealer wins"); StdOut.println(status.getText()); } // process a button push public void actionPerformed(ActionEvent e) { if (e.getSource() == hitButton) { hit(gambler); if(gambler.value() > 21) { checkWinner(); hitButton.setEnabled(false); stickButton.setEnabled(false); dealButton.setEnabled(true); } } if (e.getSource() == stickButton) { while(dealer.value() < 17) hit(dealer); checkWinner(); hitButton.setEnabled(false); stickButton.setEnabled(false); dealButton.setEnabled(true); } if (e.getSource() == dealButton) { deal(); status.setText(" "); hitButton.setEnabled(true); stickButton.setEnabled(true); dealButton.setEnabled(false); } } // play Blackjack public static void main(String argv[]) { new BlackJack(); } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote