This results in a matrix with 15,444 * 15,444 cells, or about a quarter of a billion cells. Calculate the cost to go from any one of these states to any other. Thus, you have 15,444 different possible states. That means the total number of rack configurations is about 1716 * 9 = 15,444. The solids can be arranged in about (14 choose 7)/2=1716 different ways. To create the matrix: note that accounting for symmetries the 8-ball can be in one of 9 positions. Since the problem is multi-stage with fixed costs and no uncertainties, a DP matrix will exist that optimally solves the problem. In the given example, the solution takes 2 moves:Īn optimal solution is best found by configuring the problem for dynamic programming (DP). Swap adjacent o and x on top and bottom left (solving four edges) Swap 8 with x on edge then with o in center (solving two edges) This has a parity of +1 so we aim for stripes in corners: x x o o x This has a parity of +1 so we aim for stripes in corners: 8 o o o xĮDIT: This works quite well for the example in the opening post, solving it in two moves: I think it's impossible to require 4 turns, but I haven't proven it to myself yet. (Notably, this one would have been solved just as fast if we aimed for stripes in corners.) x x o o x We ended up doing five swaps in a 2-2-1 series, so three moves. So we move the o on the top, left (4), the o on the right side in (2), the o on the bottom left in (2) and then swap the x top with the o in the middle (2). A swap between two balls, one on the outside, is 'worth 1' A swap between two balls on the outside is 'worth 2' A swap between two adjacent balls, one on the outside, is 'worth 2' (1 if it's our last) A swap between two adjacent balls on the outside is 'worth 4' (2 if it's our last) Order all remaining moves by this priority: x o x x oĪfter we move the 8 ball, all combinations of two adjacent swaps sharing a ball can be produced by a non adjacent swap identically, so we have to consider far less complexity at once. If you can do two adjacent swaps with it that moves two balls into position, rather than a single adjacent swap that moves just one ball into position (or a single non-adjacent if it's in a corner), do so. The next thing to do is move the 8 ball into the center. (If +0, pick +12 or randomly)įor example, this is +1 +1 +1 -1 -1 +1 -1 -1 -1 +1 +0 -1 and thus it's -1 leaning solids in corners: x o x x o This gives us a range from +12 to -12, and we aim for the extreme we are closer to. The first thing to do is calculate the parity of the exterior - +1 if it would fit 'stripes in corners', -1 if it would fit 'solids in corners', +0 if it's the 8 ball. NOTE! This answer was written before the rotation requirement. What approach is best suited for this task that minimizes the time (in the time units described)? Would greedy be best for this? (it's how I do it when I rack them up, I guess)ĮDIT: As per existing (or previous answers) - you might assume having more stripes than solids in the corners means that strides will prefer corners - not saying it isn't true, but if you make that assumption, please prove it. Since we can use both hands, let's assume we can parallelise the first operation (swap 2 couple of balls at the same time), whereas we can only swap two non-adjacent balls at a time. To formalize this, we can assume there are two three operations we can do: If you want the white ones in the corners, you have just 2 of them in place (2,11). How do you decide that upfront? Should you take into account how many balls are already in place? In my example, if you want the grey ones in the corners, you already have 3 in place (balls 1,10,14). There's also the decision of which types of balls we want in the corners to be made. 5 is not, we swap it with 2, then we swap 4 with 3 (or with 8), but this would already be inefficient because we've either moved the 4 to the center or the 8 in 4's position - i.e. So for example, we'd assume 1 is at the correct position. How do you proceed?Ī simple approach would be to start in order, top -> bottom and left -> right. The two remaining balls (a stripe and a solid) don't matter.Īssume you just finished a game, gather the balls, put them in the rack and proceed to arrange them to start a new one. the 8-ball must be in the center, and along the sides the stripes and the solids must alternate. Since racking of billiard balls for the 8-ball game can be done under multiple rules, here's the racking I refer to:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |