|
Scientific Computing (P05 Spring,
2004) |
Knight's Tour Problem
The problem of striking on a good solution through random guessing seems to take forever
I played a million games and kept tally of how many times it lasted n moves. The results I put into an Excel spreadsheet and made a bar chart of the distribution. Here's what I got starting in a corner. I then repeated starting in the 4th row and 6th column and got the following results. These are, though it's hard to tell, actually stlightly different. What accounts for their similarity? Maybe it's something to do with the random number generator. When I allow thecomputer to pick the first position on the board, I get a significantly different result:
The code outline below may or may not help you in working in the access heuristic for this exercise.
#include <iostream>
#include <stdlib.h>
#include <iomanip.h>// These are the prototypes for the showBoard and updateAccess functions void showBoard(// specify input here ); void updateAccess(// specify input here );// The book suggests using two separate arrays for horizontal and vertical, // but you could combine them as a single 2dimensional array like so: // This is defined globally here so that it is available in functions... int move[8][2] = {{2,-1},{1,-2},{-1,-2},{-2,-1},{-2,1},{-1,2},{1,2},{2,1}};int main() { // Each number represents how many squares the square is accessible from, originally // This matrix needs to be updated each time you move and is used to help strategize // about how to visit all the squares on a knight's tour. int access[8][8] = {{2,3,4,4,4,4,3,2}, {3,4,6,6,6,6,4,3}, {4,6,8,8,8,8,6,4}, {4,6,8,8,8,8,6,4}, {4,6,8,8,8,8,6,4}, {4,6,8,8,8,8,6,4}, {3,4,6,6,6,6,4,3}, {2,3,4,4,4,4,3,2}}; int board[8][8] = {{0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}}; int currentRow, currentColumn; // define other variables here, as needed // To get started, prompt the user for an // initial position on the board and mark it with a "1" cout << "What row and column would you like to start at? "; cin >> currentRow >> currentColumn; board[currentRow][currentColumn] = 1; // You'll need a way of keeping track of your progress on the hunt // Introduce variables to keep track of how many squares have been visited // and whether or not your knight is stuck. int squareCounter = 1; bool stuck = false; while (!stuck && squareCounter < 64) { // Initialize variables here, as needed, before reentering the for loop. // The for loop should check each of the 8 (theoretically) possible moves // to see if it's on the board and never before been visited. // Later, improve the code to use the information about accessibility. for(int i = 0; i < 8; i++) { //check if the move is on the board and the square is available // if it's a legal move // check the accessibility of the square // and choose the square with strategic accessibility // As a final touch (part d), // If there are two (or more) // different squares with the same // optimal accessibility, // find a way to check ahead // one move to see which of those // choices leads to more choices. // Remember, if your knight is stuck, the tour is over. // Update all parameters. // Update the board // Update the access table // Show the board // system("PAUSE"); } return 0; } void showBoard(// specify input) { // Write code to show the board } void updateAccess(// specify input) { // Write code to update the access table }
Link:http://www.inficad.com/~ecollins/knights-tour.htm
References:
Go to the MESA center and see if you can find and copy the Mathematics Magazine article from the Vol. 75, No. 3, June 2002, titled Pillow Chess.
1. W. Ahrens, Mathematische Unterhaltungen and Spiele, B.G. Teubner, Leipzig, 1921.
2. W. W. R. Ball, Mathematical Recreations and Essays, Revised by H. S. M. Coxeter, Macmillan and Co., London, 1947.
3. S. Barr, Experiments in Topology, Dover Publications, Inc., Mineola, NY, 1989.
4. J. D. Beasley, The Mathematics of Games, Oxford Uni. Press, Oxford, 1989.
5. C. Berge, The Theory of Graphs, Methuen and Co., London, 1962.
6. -, Graphs and Hypergraphs, North Holland Publ., Amsterdam, 1973.
7. J-P. Bode and H. Harborth, Independent chess pieces on Euclidean boards, J. Combin. Math. Combin. Comput. 33 (2000), 209-223.
8. J. Boyer, Nouveaux Jeux d'Echecs Non Orthodoxes, J. Boyer, Paris, 1954.
9. A. Bruen and R. Dixon, The n-queens problem, Discrete Math. 12:4 (1975), 393-395.
10. P. J. Campbell, Gauss and the eight queens problem: a study in miniature of the propagation of historical error, Historia Math. 4:4 (1977), 397-404.
11. A. K. Chandra, Independent permutations, as related to a problem of Moser and a theorem of P61ya, J. Combinatorial Theory Ser. A 16 (1974), 111-120.
12. M.R. Chen, R. G. Sun, and J. C. Zhu, Partial n-solution to the modular n-queens problem II, Combinatorics and graph theory, 1-4, World Sci. Publishing, River Edge, NJ, 1993.
13. D. S. Clark, A combinatorial theorem on circulant matrices, Amer. Math. Monthly 92:10 (1985), 725-729.
14. D. S. Clark and 0. Shisha, Invulnerable queens on an infinite chessboard, Ann. New York Acad. Sci. 555 (1989), 133-139.
15. A. Conrad, T. Hindrichs, H. Morsy, and 1. Wegener, Solution of the knight's Hamiltonian path problem on chessboards, Discrete Appl. Math. 50 (1994), no. 2, 125-134.
16. P. Cull and J. De Curtins, Knight's tour revisited, Fibonacci Quarterly 16:3 (1978), 276-286.
17. R. B. Eggleton and A. Eid, Knight's circuits and tours, Ars Combin. 17A (1984), 145-167.
18. C. Erbas and M. M. Tanik, Generating solutions to the N-queens problem using 2-circulants, this MAGAZINE 68:5 (1995), 343-356.
19. C. Erbas, M. M. Tanik, and Z. Aliyazicioglu, Linear congruence equations for the solutions of the N-queens problem, Inform. Process. Lett. 41:6 (1992), 301-306.
20. B-J. Falkowski and L. Schmitz, A note on the Queens' problem, Inform. Process. Lett. 23:1 (1986), 39-46.
21. N. J. Fine, Solution of problem E 1699, Amer Math. Monthly 72 (1965), 552-553.
22. M. Gardner, Problems that are built on the knight's move in chess, Scientific American 217 (1967), no. 4, 128-132.
23. Further Mathematical Diversions, Penguin Books, New York, 1977.
24. Fractal music, hypercards and more.... Mathematical recreations from Scientific American magazine, W. H. Freeman and Company, New York, 1992.
25. Z. Goldstein, Solution of problem E2698, Amer. Math. Monthly 86 (1979), 309-3 10.
26. S. W. Golomb, Sphere packing, coding metrics, and chess puzzles, Proc. Second Chapel Hill Conf. on Combinatorial Mathematics and its Applications, Univ. North Carolina, Chapel Hill, NC, 1970, pp. 176-189.
27. R. K. Guy, Unsolved Problems in Number Theory, Springer-Verlag, New York, 1994.
28. 0. Heden, On the modular n-queen problem, Discrete Math. 102:2 (1992), 155-161.
29. -, Maximal partial spreads and the modular n -queen problem, Discrete Math. 120:1-3 (1993), 75-9 1; 11, ibid. 142:1-3 (1995), 97-106.
30. S. M. Hedetniemi, S. T. Hedetniemi, and R. Reynolds, Combinatorial Problems on chessboards 11, Domination in graphs, advanced topics (T. W. Haynes, S. T. Hedetniemi, P. J. Slater eds.), Marcel Dekker, Inc., New York, 1998, pp. 133-162.
31. E. J. Hoffman, J. C. Loessi, and R. C. Moore, Constructions for the solution of the m queens problem, this MAGAZINE 42 (1969), 66-72.
32. R. Honsberger, Mathematical Gems from Elementary Combinatorics, Number Theory, and Geometry, MAA, Buffalo, 1973.
33. D. Hooper and K. Whyld, The Oxford Companion to Chess, Oxford Uni. Press, Oxford, New York, 1984.
34. S. P. Hurd and D. A. Trautman, The knight's tour on the 15-puzzle, this MAGAZINE 66:3 (1993) 159-166.
35. F. K . Hwang and K. W. Lih, Latin squares and superqueens, J. Combin. Theory Ser. A 34:1 (1983), 110-114.
36. E. Just, Solution of problem E2302, Amer. Math. Monthly 79:5 (1972), 522-523.
37. D. A. Klarner, The problem of reflecting queens, Amer. Math. Monthly 74 (1967), 953-955.
38. -, Mathematical Review 48 #10849 of "On pairings of the first 2n natural numbers", by G. B. Huff, Acta Arith. 23 (1973), 117-126.
39. -, Queen squares, J. Recreational Math. 12:3 (1979/80), 177-178.
40. T. Klove, The modular n-queen problem, Discrete Math. 19:3 (1977), 289-291; 11, ibid. 36:1 (1981), 33-48.
41. M. Kraitchik, Le Probleme du Cavalier, Gauthiers-Villars, Paris, 1927.
42. -, Mathematical Recreations, Dover Publ., New York, 1953.There's twice as many of these, actually...