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

Reframing The Problem - TrueNorthPHP 2014

Reframing The Problem - TrueNorthPHP 2014

Daniel Cousineau

November 08, 2014
Tweet

More Decks by Daniel Cousineau

Other Decks in Technology

Transcript

  1. 4 1 2 6 3 7 5 8 1 2

    4 6 3 7 5 8 up
  2. 4 1 2 6 3 7 5 8 1 2

    4 6 3 7 5 8 up 1 2 4 6 3 7 5 8 right
  3. 4 1 2 6 3 7 5 8 1 2

    4 6 3 7 5 8 up 1 2 4 6 3 7 5 8 right 4 1 2 6 3 7 5 8 right
  4. A* -> queue = expand(initial) while queue is not empty:

    dequeue move from queue if move is solution: return move concat expand(move) to queue sort queue by heuristic
  5. expand(state) -> moves = [] if left valid move: add

    state.move(left) to moves if right valid move: add state.move(left) to moves if up valid move: add state.move(left) to moves if down valid move: add state.move(left) to moves return moves
  6. 4 1 2 6 3 7 5 8 4 2

    6 1 3 7 5 8 4 1 2 6 3 7 5 8 4 1 2 6 5 3 7 8 4 1 2 6 3 7 5 8