Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save okayshankha/cbdde5565387efd00ec1c34e236ca9a2 to your computer and use it in GitHub Desktop.
Save okayshankha/cbdde5565387efd00ec1c34e236ca9a2 to your computer and use it in GitHub Desktop.
Selector:= white
Foreach black tile b
do h(b):= tile-distance to the first white tile to its right
Foreach white tile w
do h(w):= tile-distance to the first black tile to its left * -1
While any tile has a non-zero h value
Do
If selector:= white then,
Select the while-tile with the highest h value, say X
If the h(X):= 0 and it does not have the blank space to its left then,
Select another while-tile with the next-highest h value, say X
Selector := black
Else
Select the black-tile with the highest h value, say X
If the h(X):= 0 and it does not have the blank space to its left then,
Select another black-tile with the next-highest h value, say X
Selector:= white
If X and the blank space is in 2-tiles distance then,
Move X to the blank space and record the cost
Foreach black tile b
do h(b):= tile-distance to the first white tile to its right
Foreach white tile w
do h(w):= tile-distance to the first black tile to its left * -1
End while
@Maruf13
Copy link

Maruf13 commented Nov 8, 2021

can you share java or python implementation on this that help me a lots? plz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment