Darts Checkout code java

Darts Checkout code java



I am pretty new to java and programming in general. I am tinkering around trying to make a basic darts scorer app for the 501 game. I have most of it set up, but I am wanting to get the app to tell you a possible finish,



ie in 501 you have to finish on a double or centre bull) so for 170 you can finish with T20 T20 bull. I have been looking online and seen a few suggestions for a recursive method, but this seems way above my knowledge at present and I have watched a few youtube vids and understood the basic idea about a method calling itself until a certain criteria is reached, but I don't really understand how this will help in this case. At the moment I have hard coded all possible outs 2,3,4.......170 with a combination of scores that will = that out, as below,


if (scoreTeamA == 150)

teamACheckout.setText("T20, T18, D18");




This is an awful lot of code and I am sure there is a better way, in fact there is most likely a better way to do most of what I have done so far but it's a good learning curve. Will doing the code this way be far more resource intensive than another way of doing it?



btw I am using android studio



Many thanks





You could just have a static method somewhere that accepts the score as a parameter and returns the String output of the available outs in a switch statement. It’s not really that much code.
– achAmháin
Aug 29 at 19:38




2 Answers
2



I am not familiar with the game but i will try to explain how i would approach this problem.



What you want to do is search in a finite space for all available solutions. You can think of all the possible states of the game as a graph. Lets say you start with 10 points and you have 4 possible outcomes (1, 2, 3, 0) your graph will be:


10
1/ 2| 3| 0
/ | |
9 8 7 10



Now 10 is our root node and we got 4 options. Score 1 point and go to 9 or score 2 points and go to 8 etc.



9, 8, 7, 10 are the child nodes of the root (10) and 1, 2, 3, 0 are the paths that we can take.



Now we can continue expanding the graph. Lets expand 9


10
1/ 2| 3| 0
/ | |
9 8 7 10
1/ 2| 3| 0
/ | |
8 7 6 9



You can see that we have 4 new paths that gets us to 4 new nodes. So lets say that we are in our root node (10) and we want to go to 7 we have to find all the available paths. In this case we have 2: a) score 3 to go directly to 7 b) score 1 to go to 9 then score 2 to go to 7



We can expand the graph until we reach the nodes with 0 which we will call leaf nodes.



Now all the paths from our root node to a leaf node are a possible solution. Be careful though since we have 0 (miss) as an option we will reach a never ending loop e.g. We got 10 points and we miss (0 path) we go to the same node (10) then we miss again and so on.



In general you should give a look at graph theory since it is really useful in approaching a lot of problems. As for how to find all paths look at DFS and BFS algorithms (can be implemented with recursion too).



Of course there is not a single answer but i hope i gave you a good starting point



You can find finishes just by searching exhaustively. There aren't that many.



There are 20 segments of the dart board, each of which has a double and a treble. Plus the half bull and bull; and you could miss the board entirely (or not have to throw a dart, because you finished). So there are 63 places you can throw each dart; hence 63^3 places to throw 3 darts, or 250047.



That's... A few, but not so many that you couldn't just check each possible combination each time you wanted to know the finish.



But you can cut this down: if the last dart you throw has to be a double or a bull, then the number of places to throw the dart is 21*63^2=83349.



So, just go through each of the valid permutations, calculating the score for each, and just pick the ones which equal your current score.



And, of course, there are only 501 possible scores, but you can't finish from all of them. So, you could just pre-calculate all of the finishes once and for all, store them in a map, and look up in the map when you need it.





So if I create a map and store all the possible finishes in it ie, 170, "T20, T20, Bull"...... 120, "T20, 20, D20" etc. Then can I use the variable 'score' (Which stores the points remaining) to find the value in the map and display the string in the checkout EditText view? Thanks
– Danny Jebb
Aug 30 at 13:04




Required, but never shown



Required, but never shown






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

How do I collapse sections of code in Visual Studio Code for Windows?

ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ