PROG0260 - Darts

no tags 

History

Darts is an age-old game that originates among soldiers who started competitions as a pastime between battles. They threw short arrows at the bottom of wine barrels and later at discs made of the trunks of trees. Scores were added onto the discs. Out of necessity, the sport was played inside during the winter months, which forced the soldiers to replace the arrows with darts and led to a new set of rules for practicing the indoor sport. As the game continued to develop, the richer layers of population gained an interest in darts. It is written that Hendrik VIII's second wife Anne Boleyn gave him a richly decorated Biscayan darts set.

Dartboard

The current game board comes from London. The board consists of a round fiber plate of 18 millimetres thick, on which sisal fiber bristles are glued and pressed under large pressure. The whole is framed by a metal band. The board is provided with a section division using different colours. After that, a metal web is fixed on top of the plate, provided with the same division. The function of this web is to make sure it is always clear in which section the dart landed. On the outer border, a metal ring is placed on which numbers are fixed according to the section division. This ring can be unlinked from the rest of the board, making it possible to shift the numbers with regards to the plate.

The idea is that the section (bed) 20 is in the middle on top. This section is usually the most favorite target. This is why the bottom plate of this section is likely to break first. Every dart that is thrown affects the fibers of the board. The glue layer prevents the board from falling apart, but after a while, an accumulation of fibers will be visible under the form of lumps. To prevent this, the board should be turned around on regular time intervals, so that 20 is always on top of another section. Do note that 20 should always be on top of a black section. Modern sisal fiber boards shouldn't be made wet (unlike what is often thought).

dartbord
A dartboard.

The measurements of a dartboard are indicated in the picture above. The double ring and triple ring are always 9.6 mm wide.

Scoring

The dartboard is divided in rings and sections. The numbers at the rim indicate the amount of points you receive for throwing a dart in that particular section. In this exercise, the sectors are numbered starting at 1 and clockwise starting at the top sector. The sections are further subdivided in a number of smaller partitions.

  • in the middle is the double bull or bull's eye (red), 50 points
  • around the double bull is the single bull (green), 25 points
  • around that a wide ring, the bed (black and white), for which the amount of points that is indicated on the rim of the board is granted
  • around that a smaller ring, the triple (or treble) ring (red and green); this yields a triple score of the bed
  • around that is another bed
  • around that is the double ring (red en green) yields a double score of the bed

If you throw a dart in the outer black rim (where the numbers are) or next to the board, you don't get any points. A bouncer, which is a dart that bounces back from the board, doesn't get a score. You also won't receive any points if one of your darts falls from the board before you were able to take your darts out (please note, officially this isn't called a bouncer). If a player throws in one of his formerly thrown darts (a Robin Hood), the last dart doesn't receive a score.

Assignment

We consider a Cartesian coordinate scale with its origin in the centre of the bull's eye of a dartboard. A player throws a dart to the board that lands on coordinates $(x, y)$, with coordinates expressed in millimetres. Determine the score that is obtained by this dart. In order to do so, it is best to first convert the Cartesian coordinates $(x, y)$ of the position where the dart has landed into polar coordinates, and then to determine the score of the corresponding sector based on the angle $\theta$.

From Cartesian coordinates to polar coordinates

The first step towards the solution is to convert the position $P$ where the dart has landed on the dartboard from the coordinates $(x, y)$ in the Cartesian coordinate scale into polar coordinates $(r, \theta)$. The tuple $(r, \theta)$ of real valued numbers expresses the position of the point $P$ in polar coordinates, where the pole $O$ coincides with the centre of the bull's eye, and the pole axis coincides with the $X$ axis. The coordinate $r$ of the point $P$ is the distance $OP$. The coordinate $\theta$ indicates the oriented angle between the positive $X$ axis and the half straight line of O through P. This angle is expressed in radians, and it must hold that $-\pi < \theta \leq \pi$.

poolcoordinaten
$(r, \theta)$ is a set of pole co-ordinates of the point $P$.

The connection between the Cartesian coordinates $(x, y)$ and the polar coordinates $(r, \theta)$ is given by $$\begin{cases} r = & \sqrt{x^2+y^2} \\ \\ \theta = & \arctan\left(\frac{y}{x}\right) \end{cases}$$

From angle to sector

The sketch given below illustrates how an angle in polar coordinates ($\theta$; the green angle) can be converted into an angle ($\beta$; the red angle) that can be used to determine the corresponding sector.

van hoek naar sector

Using a little bit of trigonometry, it is easy to see that $$ \beta + \theta = \frac{\pi}{2} + \frac{\pi}{20}\,, $$ or in other words, $$ \beta = \frac{\pi}{2} + \frac{\pi}{20} - \theta\,. $$ Once $\beta$ has been computed and you know that each sector covers an angle of $\frac{\pi}{10}$, you can convert the angle $\beta$ into the index of the sector. The first sector (the one on top of the $Y$-axis) has index 0, the one to the right of it has index 1, and so on in a clockwise manner.

Input

The input contains the numbers $x, y \in \mathbb{R}$, each on a separate line. These numbers represent the position $(x, y)$ of the point $P$ in the Cartesian coordinate scale with its origin in the centre of the bull's eye of a dartboard. The units of the coordinate scale are expressed in millimeter.

Output

The output contains the score that is given to dart thrown at position $P$ on the dartboard.

Example

Input:

-30.0
22.0

Output:

18

Geschiedenis

Darts (of darten) is een eeuwenoud spel dat zou ontstaan zijn toen soldaten wedstrijden begonnen te houden als tijdverdrijf tussen veldslagen door. Daarbij werden korte speren gegooid op omgekeerde bodems van wijntonnen en later op doorgezaagde boomstamschijven. Op de schijven werd een puntentelling aangebracht. In de wintermaanden werd de sport noodgedwongen binnen gehouden, wat tot gevolg had dat men de kleine speren moest vervangen door darts en er een nieuwe regelgeving voor het beoefenen van de binnensport werd bedacht. Naarmate het spel zich verder ontwikkelde, begonnen de rijkere lagen van de bevolking ook interesse te tonen in darts. Zo staat er geschreven dat Hendrik VIII in 1530 van zijn tweede vrouw Anne Boleyn een kostbaar versierde Biscayan-dartset geschonken kreeg.

Een oude Nederlandse en in de Vlaamse spreektaal nog gebruikelijke naam van het spel is vogelpik. Deze term is afkomstig van een soortgelijk spel dat vroeger gespeeld werd in cafés. Dit spel bestond uit een roos met ringen, niet zoals het actueel dartbord dus, en een nagemaakte vogel met een scherpe snavel. De vogel werd met een koord aan het plafond opgehangen en de spelers probeerden de snavel van de vogel in de roos te zwieren.

Dartbord

Het wedstrijdbord dat tegenwoordig gebruikt wordt, komt uit Londen. Het bord bestaat uit een ronde vezelplaat van 18 millimeter dik, waarop sisalvezelborsteltjes onder grote druk gelijmd en geperst worden. Het geheel wordt omlijst door een metalen band. Het bord wordt voorzien van een vakindeling door middel van verschillende kleuren. Vervolgens wordt er een metalen web op bevestigd dat diezelfde vakindeling heeft. De functie van dit web is er voor te zorgen dat altijd duidelijk is in welk vak een dart gegooid is. Op de buitenzijde wordt een metalen ring aangebracht waarop volgens de vakindeling bepaalde cijfers zijn bevestigd. Deze ring is los te maken, zodat de cijfers ten opzichte van het bord verschoven kunnen worden.

Het is de bedoeling dat het vak (bed) 20 middenboven zit. Op deze 20 wordt normaal gesproken het meest gegooid. Hierdoor zal de bodemplaat in dit vak dan ook het eerste kapot gaan. Elke dart die gegooid wordt tast de vezeltjes van het bord aan. Door de lijmlaag valt het bord niet uit elkaar, maar na verloop van tijd wordt op bepaalde plaatsen een opeenhoping van vezeltjes zichtbaar, in de vorm van bulten. Om dit te voorkomen dient het bord om de zoveel tijd gedraaid te worden, zodat het cijfer twintig weer boven een nieuw, minder gehavend deel van het bord staat. De 20 staat wel altijd boven een zwart deel. Moderne sisalvezelborden moeten beslist niet worden natgemaakt zoals nog wel wordt gedacht.

dartbord
Een dartbord.

De afmetingen van het dartbord worden aangegeven in bovenstaande figuur. De double ring en triple ring zijn telkens 9.6 mm breed.

Puntentelling

Het dartbord is verdeeld in ringen en sectoren. De getallen langs de rand geven het aantal punten aan voor een pijltje in de desbetreffende sector. Voor deze opgave zijn de sectoren genummerd vanaf 1 en in wijzerzin vanaf de bovenste sector. De sectoren zijn onderverdeeld in nog een aantal kleinere vakken.

  • in het midden is de double bull of bull's eye (rood), 50 punten
  • daaromheen de single bull (groen), 25 punten
  • daaromheen een brede ring, het bed (zwart en wit), waarvoor het aantal punten geldt dat op de rand van het bord staat
  • daaromheen een smalle ring, de triple (of treble) ring (rood en groen); deze levert drie maal het puntenaantal op
  • daaromheen weer een bed
  • daaromheen de double ring (rood en groen) met twee keer het aantal punten dat bij het betreffende vak staat

Een dart in de buitenste zwarte rand (waar de cijfers staan) of naast het bord levert geen punten op. Een bouncer, een dart die van het bord terugkaatst, heeft geen score tot gevolg. Daarnaast is er ook geen score wanneer een dart na geworpen te zijn plots uit het bord valt voordat de speler in de gelegenheid was alle drie zijn pijlen uit het bord te halen (let wel, dit wordt officieel geen bouncer genoemd). Als een speler een dart in één van zijn eerder gegooide darts gooit (een Robin Hood), wordt de laatste van die twee darts wel gezien als zijnde 'geworpen', maar wordt er geen score aan die dart toegekend.

Opgave

We beschouwen een carthesisch coördinatenstelsel met oorsprong in het centrum van de bull's eye van een dartboard. Een speler werpt een pijltje naar het dartbord dat belandt op de coördinaten $(x, y)$, waarbij beide coördinaten worden uitgedrukt in millimeter. Bepaal het aantal punten dat met dit pijltje behaald wordt. Hiervoor kan je best eerst de carthesische coördinaten $(x, y)$ van de positie waar het pijltje belandt omzetten naar poolcoördinaten, om daarna op basis van de hoek $\theta$ de score van de corresponderende sector te bepalen.

Van carthesische coördinaten naar poolcoördinaten

De eerste stap naar de oplossing bestaat erin de positie $P$ waar het pijltje beland is op het dartbord om zetten van coördinaten $(x, y)$ in het carthesisch coördinatenstelsel naar poolcoördinaten $(r, \theta)$. Het koppel reële getallen $(r, \theta)$ drukt dus de positie van het punt $P$ uit in poolcoördinaten, waarbij de pool $O$ samenvalt met het centrum van de bull's eye, en de poolas samenvalt met de $X$-as. De coördinaat $r$ van het punt $P$ is de afstand $OP$. De coördinaat $\theta$ geeft de georiënteerde hoek aan tussen de positieve $X$-as en de halfrechte van O door P. Deze hoek wordt uitgedrukt in radialen, en er moet gelden dat $-\pi < \theta \leq \pi$.

poolcoordinaten
$(r, \theta)$ is een stel poolcoördinaten van het punt $P$.

Het verband tussen de carthesische coördinaten $(x, y)$ en de poolcoördinaten $(r, \theta)$ wordt dan gegeven door $$\begin{cases} r = & \sqrt{x^2+y^2} \\ \\ \theta = & \arctan\left(\frac{y}{x}\right) \end{cases}$$

Van hoek naar sector

Onderstaande schets maakt duidelijk hoe je een hoek in poolcoördinaten ($\theta$; de groene hoek) kunt omzetten naar een hoek ($\beta$; de rode hoek) die je kunt gebruiken om de index van de overeenkomstige sector te bepalen, en dus ook rechtstreeks de score (die een eenheid hoger is dan de index van de sector).

van hoek naar sector

Met een beetje goniometrie is het makkelijk in te zien dat $$ \beta + \theta = \frac{\pi}{2} + \frac{\pi}{20}\,, $$ met andere woorden $$ \beta = \frac{\pi}{2} + \frac{\pi}{20} - \theta\,. $$ Als je eenmaal $\beta$ bepaald hebt, en je weet dat elke sector een hoek van $\frac{\pi}{10}$ beslaat, dan kan je de hoek $\beta$ omzetten naar de index van de sector. De eerste sector (deze bovenaan de $Y$-as) heeft dan index 0, die rechts ervan index 1, enzoverder in wijzerzin.

Invoer

De invoer bevat twee getallen $x, y \in \mathbb{R}$, elk op een afzonderlijke regel. Deze getallen stellen de positie $(x, y)$ van een punt $P$ in het carthesisch coördinatenstelsel met oorsprong in het centrum van de bull's eye van een dartboard. De eenheden van het coördinatenstelsel zijn uitgedrukt in millimeter.

Uitvoer

De uitvoer bevat de score die behaald wordt met een pijltje dat gegooid wordt in punt $P$ op het dartbord.

Voorbeeld

Invoer:

-30.0
22.0

Uitvoer:

18


Added by:Peter Dawyndt
Date:2014-09-21
Time limit:10s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:PY_NBC
Resource:None