Create a function drop_piece that simulates a player dropping their piece into a column of the...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Create a function drop_piece that simulates a player dropping their piece into a column of the game board. When dropping a piece into the selected column, the player token needs to be placed into the bottom-most empty cell of that column. Like with the real board, a player's token falls down the column and sits on top of any tokens already in that column. This means that the board should be updated if the drop is possible. Arguments This function takes two arguments: board: a 2D array player: an integer representing the player's token, 1 or 2 column: an integer representing the column chosen by the player, 1-7 Example >>> board = [ [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 2, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 1, 2, 0, 0], [0, 0, 0, 2, 1, 0, 0], [0, 0, 0, 1, 2, 0, 0] >>> print (drop_piece (board, 1, 4) True >>> board = [0, 0, 0], [0, 0, 0, 2, 0 1 0, 0], 2 0, 0], [0, 0, 0, 1. 0 - [0, 0, 0, 1, 2, 0, 0], [0, 0 0, 2, 1, 0, 0], [0, 0, 0, 1, 2, 0, 0] 0 2 2 0, 1, 0 " >>> print (drop_piece (board, 2, 4) False Create a function drop_piece that simulates a player dropping their piece into a column of the game board. When dropping a piece into the selected column, the player token needs to be placed into the bottom-most empty cell of that column. Like with the real board, a player's token falls down the column and sits on top of any tokens already in that column. This means that the board should be updated if the drop is possible. Arguments This function takes two arguments: board: a 2D array player: an integer representing the player's token, 1 or 2 column: an integer representing the column chosen by the player, 1-7 Example >>> board = [ [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 2, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 1, 2, 0, 0], [0, 0, 0, 2, 1, 0, 0], [0, 0, 0, 1, 2, 0, 0] >>> print (drop_piece (board, 1, 4) True >>> board = [0, 0, 0], [0, 0, 0, 2, 0 1 0, 0], 2 0, 0], [0, 0, 0, 1. 0 - [0, 0, 0, 1, 2, 0, 0], [0, 0 0, 2, 1, 0, 0], [0, 0, 0, 1, 2, 0, 0] 0 2 2 0, 1, 0 " >>> print (drop_piece (board, 2, 4) False
Expert Answer:
Answer rating: 100% (QA)
Answer def droppieceboard player column Check if the column is v... View the full answer
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Posted Date:
Students also viewed these programming questions
-
Arthur, CPA, is auditing The Home Improvement Store as of December 31, 2021. As with all audit engagements, Arthur's initial procedures are to analyze the entity's financial data by reviewing trends...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Connect Four is a turn-based game normally played with anupright 6 x 7 (height x width) rectangular grid cage in which checkers are dropped through holesin the top. Playing: Each player is...
-
How do the Uniform Trade Secrets Act (UTSA) and the Economic Espionage Act of 1996 differ? Why don't these acts always provide a sufficient remedy for the theft of trade secrets?
-
Suggest reasonable explanations for each of the following observations. (a) Both hydrogens are anti to each other in the most stable conformation of formic acid. (b) Oxalic acid has a dipole moment...
-
. Assume that you were recently hired as Wilson's assistant and that your first major task is to help her develop the formal financial forecast. She asks you to begin by answering the following...
-
Determine whether the events are mutually exclusive. Then determine whether the events are independent or dependent. Explain your reasoning. Event A: A bowler having the highest game in a 40-game...
-
During the current month, Reyes Corporation completed Job 310 and Job 312. Job 310 cost $60,000 and Job 312 cost $50,000. Job 312 was sold on account for $90,000. Journalize the entries for the...
-
A company has established that the relationship between the sales price for one of its product and the quantity sold per month is approximately p = 75 - 0.1D units (D is the demand or quantity sold...
-
Top Quality ApplianceLong Beach has just purchased a franchise from Top Quality Appliance (TQA). TQA is a manufacturer of kitchen appliances. TQA markets its products via retail stores that are...
-
Find the value of X Cumulative Class Frequency Frequency Percent 15-19 20 22.989% 20 - 24 15 40.230% 25-29 12 54.023% 30-34 10 65.517% 35-39 11 78.161% 40-44 X 85.057% 45-49 13 100.000% Report your...
-
Solve S x + x 11 (x4 + 2x + 3) dx =?
-
ces Primare Corporation provided the following data for last month's manufacturing operations. Purchases of raw materials Indirect materials used in production Direct labor Manufacturing overhead...
-
What is the difference between sale of assets and the sale of stocks? How would you Compare the sale of assets and the sale of stocks.
-
Chesterfield Company holds cash of $61,000, inventory worth $112,000, and a building worth $141,000. Unfortunately, the company also has accounts payable of $191,000, a note payable of $91,000...
-
What sort of buyer strategic or financials is more likely to give a bigger purchase premium? Explain.
-
Amtrack operates train routes all over the United States.They are considering a new route from Rocky Mount, NC to Washington, D.C.All seats will be business class and they are needing to make some...
-
Given the table below, about how much force does the rocket engine exert on the 4.0 kg payload? Distance traveled with rocket engine firing (m) Payload final velocity (m/s) 500 320 490 310 1020 450...
-
Design and write a complete test program to test if the BST class in Listing 25.5 meets all requirements. Listing 1 public class BST 2 extends AbstractTree { protected TreeNode root; protected int...
-
Write a program that displays a flag rising up, as shown in Figure 15.14. As the national flag rises, play the national anthem. (You may use a flag image and anthem audio file from Listing 16.15.)...
-
Implement the following method using binary search. public static int binarySearch(E[] list, E key)
-
A company expects to receive which of the following benefits when it uses its budgeting process? a. The planning required to develop the budget helps managers foresee and avoid potential problems...
-
The following budgets are all financial budgets except for the a. combined cash budget. b. budgeted balance sheet. c. budgeted income statement. d. capital expenditures budget.
-
The income statement is part of which element of a companys comprehensive budget? a. The operating budgets b. The capital expenditures budget c. The financial budget d. The cash budget
Study smarter with the SolutionInn App