Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Modelling Hidato Puzzle

Modelling Hidato Puzzle

Kaung Htet

April 11, 2016
Tweet

More Decks by Kaung Htet

Other Decks in Programming

Transcript

  1. RULES ➤ Given a grid with some numbers in it.

    Other squares are blank. ➤ Grid is not necessarily rectangular. ➤ Grid may have holes. ➤ Grid is connected. ➤ Starting number, “1” is present. ➤ End number is given. ➤ Every “well-formed” problem supposed to have a unique solution. ➤ A king ♚’s legal moves on an irregular chessboard
  2. Given a Hidato game that fits in a m x

    n grid, does a solution exist?
  3. #define M 8; #define N 8; #define o -1; //

    off board #define a 0; // available var board[N][M] = [ a, 33, 35, a, a, o, o, o, a, a, 24, 22, a, o, o, o, a, a, a, 21, a, a, o, o, a, 26, a, 13, 40, 11, o, o, 27, a, a, a, 9, a, 1, o, o, o, a, a, 18, a, a, o, o, o, o, o, a, 7, a, a, o, o, o, o, o, o, 5, a];
  4. var row = 4; var column = 6; var steps

    = 1; King(r, c) = [r - 1 >= 0 && c - 1 >= 0] LeftUp(r, c) [] [r - 1 >= 0 && c < N ] Up(r, c) [] [r - 1 >= 0 && c + 1 < N] RightUp(r, c) [] [r >= 0 && c - 1 >= 0] Left(r, c) [] [r >= 0 && c + 1 < N ] Right(r, c) [] [r + 1 < N && c - 1 >= 0] LeftDown(r, c) [] [r + 1 < N && c < N] Down(r, c) [] [r + 1 < N && c + 1 < N] RightDown(r, c);
  5. LeftUp(r, c) = [board[r-1][c-1]==a || board[r-1][c-1] == steps+1] leftup{steps=steps+1;board[r-1][c-1]=steps;} ->

    King(r-1, c-1); Up(r, c) = [board[r-1][c]==a || board[r-1][c] == steps+1] up{steps=steps+1;board[r-1][c]=steps;} -> King(r-1, c); RightUp(r, c) = [board[r-1][c+1]==a || board[r-1][c+1]==steps+1] rightup{steps=steps+1;board[r-1][c+1]=steps;} -> King(r-1, c+1); Left(r, c) = [board[r][c-1]==a || board[r][c-1]==steps+1] left{steps=steps+1;board[r][c-1]=steps;} -> King(r, c-1); Right(r, c) = [board[r][c+1]==a || board[r][c+1]==steps+1] right{steps=steps+1;board[r][c+1]=steps;} -> King(r, c+1); LeftDown(r, c) = [board[r+1][c-1]==a || board[r+1][c-1]==steps+1] leftdown{steps=steps+1;board[r+1][c-1]=steps;} -> King(r+1, c-1); Down(r, c) = [board[r+1][c]==a || board[r+1][c]==steps+1] down{steps=steps+1;board[r+1][c]=steps;} -> King(r+1, c); RightDown(r, c) = [board[r+1][c+1]==a || board[r+1][c+1]==steps+1] rightdown{steps=steps+1;board[r+1][c+1]=steps;} -> King(r+1, c+1); Game(r, c) = start{board[r][c] = steps} -> King(r, c); GameInstance = Game(row, column); n+1 a a 0 ♚ 0 0 0 0
  6. ➤ Not well-formed problems, very big grids with very few

    given numbers. ➤ Exponential search state space. ➤ Possible Optimisations ➤ Choose neighbour squares that points towards the next smallest given number.