Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone help me solve this in Javascript? Introduction King Domino is a board game where you try to lay down dominos representing various terrain

Can someone help me solve this in Javascript?

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribedimage text in transcribed

Introduction King Domino is a board game where you try to lay down dominos representing various terrain types to score the most points. Specifically in King Domino, you get points for having contiguous areas with crowns on them. Your job is to take a completed board and figure out how many points it scores. As an example, here's a completed board For each contiguous area (as shown above in the dotted white lines), you get points equal to the number of squares times the number of crowns in that area. For example, the green forests in the bottom has 3 crowns and 7 squares, so it's worth 21 points. The 3 lakes are in separate regions, so they are worth 1, 4, and 0 points. Doing the same across all of the different areas would add up to 44 points for this board. The input will come as 255 arrays, one for the terrains and one for the crowns. For the image above, the terrains will appear as 1 SSSLL 2 SWWWL 3 LWKWL 4 FWWFF 5 FFFFL Where the possible terrains are: - s= Swamp - L= Lake - W= Wheat - F= Forest - G= Grass (does not appear above) - M = Mine (does not appear above) And the crowns for the board above are 123450000010110100010001000110 Note that up to 3 crowns can appear on a single tile. Given these 2 arguments, return an integer for the number of points the board will score. Edge Cases - Contiguous areas are defined as touching on one of the 4 sides. If two squares only touch at a corner, then they are not considered part of the same area - In actual King Domino, it's possible for the board to not be a 55 or for there to be gaps. Do not worry about those cases. Assume that it will be exactly 55 and all of the squares are filled - The Kingdom square is typically, but does not have to be, in the middle. However, it's not worth any points in any case What We're Looking For 1. Provide your code along with any test cases you come up with as part of your solution 2. Although the problem itself is designed to solve a complete 55 grid, we expect the solution to generalize to larger grids e.g. 77 3. Given that, we believe the optimal solution is O(n2) where n is the width (or length) of the grid

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David J. Auer

3rd Edition

0131986252, 978-0131986251

More Books

Students also viewed these Databases questions

Question

Did you build a strong close, with a call to action as needed?

Answered: 1 week ago