...

/

Feature #2: Maximum Points You Can Obtain from Cards

Feature #2: Maximum Points You Can Obtain from Cards

Description

In this scenario, you will be working on a custom card game named Fizzle. In Fizzle, the dealer shuffles the deck and spreads out all the cards facing upwards in a linear fashion. Then, players take turns rolling a dice. Suppose the number rolled is kk. Players will then take turns to remove kk cards from the deck, but the players can only pick cards from either the deck’s right or left side. Each player’s goal is to pick out the cards with maximum points. Each numbered card has points corresponding to its number, and the faced cards, jack, queen, king, and ace, have 11, 12, 13, and 14 points, respectively.

Our task is to create a feature for Fizzle’s computer player. We will be given the deck’s current state and the number the player rolled. We need to determine the maximum score that the player can obtain on that turn.

Let’s take a look at the following example:

In the example above, the player picked the cards 5, 3, 6, and 3, in the given order, to obtain the maximum points possible. During implementation, we will receive this deck of cards in the form of an array, like [5, 3, 4, 4, 2, 3, 4, 6, 3]. The number after rolling dice will be given as an integer, such as 4. Your module should return the maximum number of points obtained as an integer.

Solution

To implement this feature, we will test every possible combination in which k cards can be picked from the deck from either the left or right side. Few things to consider are that we cannot pick the nthn \text{th} card from the right unless the (n−1)th(n-1)\text{th} card from ...

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy