Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. /* board is n*n squares;
  2. there are l = 2*n*(n-1) possible places to put a line;
  3. so there are b=2^l possible board configurations;
  4. so for n=10, l=180, b=2^180 board configurations
  5. there is a symmetry factor of 8;
  6. so there are B=b/8 unique board configurations
  7. so for n=10, B=(2^180)/8 = 2^177
  8. n=9, l=144, b=2^144, B=2^143
  9. n=8, l=112, b=2^112, B=2^109
  10. n=7, l=84, b=2^84, B=2^81
  11. n=6, l=60, b=2^60, B=2^57
  12. n=5, l=40, b=2^40, B=2^37
  13. n=4, l=24, b=2^24, B=2^21 - brute-forceable
  14.  
  15. Global symmetry is not the only relevant part - Local symmetry works just as well
  16.  
  17. -.-.-.-.-.-.-.-
  18. |1|1|? ?|2|2|1|1|
  19. -.-. . .-.-.-.-
  20. |1|1|? ?|2|2|1|1|
  21. -.-.-.-.-.-.-.-
  22.  
  23. Local symmetry is obvious in the case of a 3x3-line square (2x2-squares - whoever
  24. is forced to play within the region first loses all of the squares within the region), but
  25. actually applies to all contiguous sub-regions. If we can find an efficient way
  26. to canonicalise and lookup the sub-region then it might be searchable for higher n.
  27.  
  28. DFS on the graph of square-edges to find the set of all points in a given sub-region.
  29. Normalise this so that the top-left point of the bounding box is
  30. at (0,0). Serialise and lookup the shape in the table to see if
  31. we have a result already. If so, return it. Otherwise, search, and then insert the result into
  32. the table, including all 8 symmetries (this is time-efficient; space-efficient alternative is to
  33. only store a result for 1 symmetry but to lookup against all 8...).
  34.  
  35. Search: given a sub-region: for each place we are allowed to play a move (i.e.
  36. each "empty" square-edge which touches a "non-empty" square-edge), play that move,
  37. and then recurse to find the best score, and then return that score. Remember that
  38. if the move we played completed a square, then the next move is again played by the
  39. same player, so the score should not be inverted!
  40.  
  41. So the key insight is that we're not playing moves on a *board*, but on a *sub-region* of
  42. the board. This allows much better caching, but how much better?
  43.  
  44. What is the time complexity, and what is the memory complexity?
  45.  
  46. Serialise the sub-regions (and, more generally, boards) by use of a bit vector of length
  47. 2*n*(n-1), where each bit corresponds to one square-edge. Use this serialisation as
  48. the key for the lookup table. Sub-regions will all be rooted at top-left.
  49.  
  50. Perhaps we should add an extra 2 rows and columns to the bit vector so that we can represent
  51. the initial boundary? It will make a difference to the sub-regions.
  52.  
  53. Questions about the game:
  54. - is it always optimal to take a square if one is available?
  55. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement