Click here to Skip to main content
15,892,643 members
Articles / Game Development

8/15 Puzzle using A* (A Star) Algorithm, C#

Rate me:
Please Sign up or sign in to vote.
4.65/5 (14 votes)
14 Jul 2013CPOL7 min read 114.2K   6.9K   17  
8/15 puzzle using A* (A Star) algorithm.
MZ����@���	�!�L�!This program cannot be run in DOS mode.

$PELTR�Q�b� �@ �@��K�@�L  H.text` b `.rsrc@�d@@.reloc�j@B�HpH�6Gp(
*03~(
, rp�(
o
s

�~*~*�*0'(
(
s(
�
o
( 
&�*8z,{,{o!
("
*0ts#
}s$
}s$
}s$
}s$
}s$
}	s$
}
s$
}s$
}s$
}s$
}
s$
}s%
}s&
}s'
}s(
}s)
}s)
}s)
}s*
}s)
}s)
}s)
}s)
}{o+
{o+
{o+
(+
{
o,
{ �@(-
o.
{o/
{o0
{o/
{o0
{o/
{o0
{o/
{o0
{o/
{	o0
{o/
{
o0
{o/
{o0
{o/
{o0
{o/
{o0
{s1
o2
{r9po3
{  s4
o5
{o6
{o7
{@(-
o.
{rMp" Bs8
o9
{(:
o;
{ � �s1
o2
{rwpo3
{FFs4
o5
{o6
{r�po<
{o=
{�s>
o?
{�s>
o@
{�sA
oB
{o7
{@(-
o.
{rMp" Bs8
o9
{(:
o;
{ �s1
o2
{r�po3
{FFs4
o5
{o6
{r�po<
{r�poC
{o=
{�s>
o?
{�s>
o@
{�sA
oB
{o7
{@(-
o.
{rMp" Bs8
o9
{(:
o;
{e �s1
o2
{r�po3
{FFs4
o5
{o6
{r�po<
{r�poC
{o=
{�s>
o?
{�s>
o@
{�sA
oB
{o7
{@(-
o.
{rMp" Bs8
o9
{(:
o;
{ �hs1
o2
{r�po3
{FFs4
o5
{o6
{r�po<
{r�poC
{o=
{�s>
o?
{�s>
o@
{�sA
oB
{	o7
{	@(-
o.
{	rMp" Bs8
o9
{	(:
o;
{	ehs1
o2
{	r�po3
{	FFs4
o5
{	o6
{	r�po<
{	r�poC
{	o=
{	�s>
o?
{	�s>
o@
{	�sA
oB
{
o7
{
@(-
o.
{
rMp" Bs8
o9
{
(:
o;
{
 �s1
o2
{
r�po3
{
FFs4
o5
{
o6
{
r�po<
{
r�poC
{
o=
{
�s>
o?
{
�s>
o@
{
�sA
oB
{o7
{@(-
o.
{rMp" Bs8
o9
{(:
o;
{es1
o2
{r�po3
{FFs4
o5
{o6
{rpo<
{r�poC
{o=
{�s>
o?
{�s>
o@
{�sA
oB
{o7
{@(-
o.
{rMp" Bs8
o9
{(:
o;
{s1
o2
{rpo3
{FFs4
o5
{o6
{rpo<
{rpoC
{o=
{�s>
o?
{�s>
o@
{�sA
oB
{o7
{@(-
o.
{rMp" Bs8
o9
{(:
o;
{hs1
o2
{rpo3
{FFs4
o5
{o6
{r�po<
{r�poC
{o=
{�s>
o?
{�s>
o@
{�sA
oB
{

o,
{
 � �(-
o.
{
rMp"@As8
o9
{
@(-
o;
{
 � 5s1
o2
{
r+po3
{
Ls4
o5
{
o6
{
rCpoC
{
o=
{
�sD
oE
{
o,
{ � �(-
o.
{rMp"@As8
o9
{@(-
o;
{_ 5s1
o2
{rOpo3
{Ls4
o5
{o6
{rkpoC
{o=
{�sD
oE
{oF
�K
{�{�oG
{ Ts1
o2
{r{po3
{ s4
o5
{o6
{r�poC
{oH
{r�poI
{sJ
oK
{Fs4
oL
{(M
oN
{r�poI
{s4
oL
{oF
�K{�{�oG
{s1
o2
{r�po3
{ s4
o5
{o6
{r�poC
{oO
�K{�{�{�{�oG
{r�poI
{%s4
oL
{rpoP
{r+poI
{ RoQ
{ �s4
oL
{rkpoP
{�sD
oR
{r]poI
{ SoQ
{ �s4
oL
{rCpoP
{�sD
oR
{r�poI
{ �s4
oL
{r�poI
{ XoQ
{ �s4
oL
{r�poP
{�sD
oR
{oO
�K
	{�	{�	oG
{r�poI
{Bs4
oL
{rpoP
{r5poI
{ DoQ
{ �s4
oL
{rapoP
{�sD
oR
{r�poI
{ ToQ
{ �s4
oL
{r�poP
{�sD
oR
"�@"PAsS
(T
(U
 �@(-
o.
  js4
(V
(/
{o0
(/
{o0
(/
{o0
(/
{
o0
(/
{o0
(W
{(X
(Y
r�p(3
r�poC
{oZ
{oZ
{o[
{oZ
{o[
(Z
([
*�(\
((]
u}(	*����0R	�T%�<(^
}!s_
}sC}}{�s7o?{�s;oAs`
} { {oa
{ {oa
{ {
oa
{ {oa
{ {	oa
{ {oa
{ {oa
{ {oa
{ {oa
{!(
{r�poP
{ob
{oc
{od
*0#{!�
{!{!��{!�*(
*b{={>{?(
*0>sY
}>}?}={�Zse
of
 �(g
*(
*0{A{oc
{A(h
oi
{B>�{A{�_
r;p�|BrKp(j
�rQp�{Cl#@�@[rcp(k
�rip�|DrKp(j
�(l
oP
{Arp(m
&*{A{r�p{Cl#@�@[rp(k
r
p|DrKp(j
(n
oP
{Ar)p(m
&*2{@oo
*0Ms[
}B}C}D}A�\sp
}@{�]se
oq
*0�,[{o+

+;�1{ or
�T(s
oC
+{ or
oC
X
�i2�{ot
,}"{ou
{
ou
*0F{{!{oD{oc
(v
oi
{rOpoP
}"**{"�*�(,{{!ow
{!(
*0Q(,Hu
,>ox
,6ox
oy
(z
,"{ o{
,3ox
o|
&*�(,!o}
~~
o
,o�
*o�
*0z	(,qu
,gox
,_ox
oy
(z
,K{ o{
,;37o}
~~
o�
oy
(z
,	.	(
{!(
*>(,(*�(,{{!ow
{!(
*>(,(*(�
*�(,}{od
{od
*�(,}{od
{od
*~#*Vs(�
t�#*(�
*{4*"}4*{.*�(
},}3}2(*(.}.*�(
},}3{2}2(*(.}.*0
u	
,{.{.o�
**2{.o�
*0
u	
,|/{/(�
**>{1{1�*{.*0D{3-	}1+{3{1X}1(+}0{0{1X}/*^{23(-*(,*0A
+.{,�Y�3{,�iY}-.X
X{,�i2�*0�
{,�il(�
i+_{,�Y�3{,�iY}-.,][
][	Y(�
Y(�
XX
X{,�i2�*0P
s�

+"{,��Trwp(�
o�
&X{,�i2�oy
�h*�o�
*0${,�i�T
{,{,�i(�
**{0�*{3*0[Po�
�(
(�
o�
+o�
�(3
,Po�
o�
-��u;
	,	o!
�P*+G0E(5,8{,�i�T{,{,�i(�
{-(4s$**0�
���*0�
{,�il(�
i{-]
{-[TE++6,2	
Y+)Y/"	
X+	,	Y
+
	Y/	X
..ZXTJ��*0a�
r{p�{.�r�p�{1�T�r�p�{0�T�r�p�{/�T�(�
*0){6
(�
t
|6(+
3�*0){6
(�
t
|6(+
3�*0){7
(�
t|7(+
3�*0){7
(�
t|7(+
3�*J(
s�
}5*(
*b{E{F{G(E*0.s^
}F}G}E�_s�
(�
&*0D
s�
�iZs�

�iZs�
s#	o�
(F8�	o�
X
o0,(G8�o2&o�
>�	8�	o�
	o"o�
,o(,H	o�
	o�
+6o)

o�
, o(,
o�
&
o�
--	o�
	X		o�
?l���o)o�
	o�
9���,
o0-(I(H*^{5o�
{5o�
*2{5o�
*0V,Es�

+o�
o1-�+{6o�
o/o�
�o8o�
0�*{6o8*05
+o1X
-�{7,{7{5o�
io<*�(
X�}�
s�
}�
}�
*0JX�
+({�
��{�
��X%{�
1�}�
*�{�
��{�
���o�
�*0g{�
�
{�
{�
��{�
�{�
���o{�
���o*0C+5Z
X{�
0X(�
,X
(�
-*(�
Z{�
1�*0#+[
(�
-*(�
[0�**{�
�*0x{�
{�
�iY3{�
�iZ(�
{�
%{�
X%
}�
�{�
�o{�
�oo�
{�
(�
*0�(�
:�{�
�
{�
{�
{�
��{�
���o{�
%{�
%Y}�
��{�
�oo�
&(�
*�	*:{�
o�
*0��o>��o{�
=��o
{�
{�
{�
��{�
���o{�
%{�
%Y}�
��{�
�oo�
&(�
*03(
%%(�
(�
(�
i%]ZX
s�
}�
*0!+(�

(�
X�i2�*:{�
o�
*0�
���*�����lSystem.Resources.ResourceReader, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089#System.Resources.RuntimeResourceSetPADPADP������lSystem.Resources.ResourceReader, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089#System.Resources.RuntimeResourceSetPADPADP�BSJBv4.0.30319l�#~D#StringsH*�#US�/#GUID0�#BlobW��)	�%3pG_e�

��
��
�"�'�3�XG�t��
,�
<�
��
��
��
��
�
��
�V;��
�
(�I;���������	�	R
8
}
k
�
k
�
k
�
k
�
k
k
k
8k
Q�	e�	sk
�k
�������K3b�������k
��
�
�
*
�o
�
�
�
�
��
�
�
�
�
��
�
�+�
G�
p�
u�
�
��
��

�6�
M�
W�
y�
��
��
����
�
.�
]�����=�x�����
��&�>�^�
��
������
��
�
3�
H����������&�7�_�l��;����!�3;B;	H!
#Q;$[;'�e;,p;, v;57�;5;�;5?�;8J�;;U�<YGU=Y�=YK@[�E^h
�42=CAKASA[AcAkAsA{A�A�A�A�E�I�M	Q&U<UWUpU�Y�U�U�U�]�ae.lcplyz}����V��aV�
a��V��V�!�V�'�V�*�Uy\�h�s�z����a�����g�k�u��������d?�n	y$	}e��n,	�2	�7	��]F	y\	aP ��X ��� ��� �� � ��0� �8!��3���3��45����5���7���h7���
�7��J8���U8����8���8�6�9�G��9�W��9�i��9�{��9����9���:���0:��� M:�� 7:��0 �
/� �
9� �
C�!U:�	/�!]:�	9�!f:�	C�"n:���"�:���%�:��'�:���(;��	(6;��)F;���*P;��*�;���*�;���*<���*�<��*�<�)*$=�2�*/=�?*8=�P*�=�^.+>�k5, >�p=/�>�x�1��E1���3��K5��V9��E:���<��\?��VD0?�oEh?�oF�?�0yG�?�CyH
@��ID@�YI�@�_K�A�eM�A�r�M�A�}�N\B���O�B���Q�B���RC���SPC�k�U�C���WD���XCD���YPD���Y�D���Z�E���Z�E���\TF��]�F���]�F���^�F�k�`c5��ck5�	�c�5��d�5�ld�6���d @��e(@�S�e
					$	,	2	7	F	$	L	S	L	S	L	S	L	S	L	S	L	S	L	S	L	S	L	S	L	S	
	
	U	F	\	U	F	f	f	j	t		F	�	�		�	�	�	�	$	�	$	�	�	�	�	�	,	2	�	,	2	�	�	�	�	
	
	
	
	F	\	F	\	�				


�	�	�	�	


$


(
.
2
6
�	�	


	 	�������������	������!��)��1�89��A��I��Q��a��i�q��y���	�	�(��.��79�=��J���6
0�I
Z�k
_�y
���
e�8Q�Y�a�i�q�y�������
��
r��
���
����'����1��>�	���L��U��b8��������������)�81�E������9�E���-�A�E�C�Io�Q��Y�8Y>�a��Y��YL����Y�
�i��Y-����YC�y���<N�m� �8��8�����9��C���[i�cY�8��8��E�9r�Ez�������x�x������
��������E��r���x�����8��������	x�����(��?�!T�Y��h�s�{)�f����	����t1�1��9����9���������!����I��'�I����Q/�YC
Q����a�Eiw3�$��,��$��$�����N$��$��,�,�T,�[$�����_��4�4��4��4�����D��L��D��D��)�	D��Dk�D��L�[D��D��L�TD��L�y��y��������T��T��Tk���������������)�Q.��.P.��.�.#^.+^.3^.;P.Cd.K^.[^.c|.s�.{QC��C��C��I�Q�����������#��C��c���� �����$El&j���oy�������*:Z��������(�,	X&�+��K�Q�K�Q�?@AB		 
!
"MS�?F}�����3<�*���y�
�EE//% <Module>15Puzzle.exeResourcesPuzzle.PropertiesProgramPuzzleForm1SettingsHeuristicDirectionIQueueItemStateStateChangedPuzzleSolutionPuzzleStrategyMinPriorityQueue`1LinearShuffle`1mscorlibSystemObjectSystem.Windows.FormsFormSystem.ConfigurationApplicationSettingsBaseEnumIComparableMulticastDelegateTSystem.ResourcesResourceManagerresourceManSystem.GlobalizationCultureInforesourceCulture.ctorget_ResourceManagerget_Cultureset_CultureCultureMainSystem.ComponentModelIContainercomponentsDisposeInitializeComponentPanelgamePanelButtonbutton4button7button8button6button5button3button2button1buttonStartbutton9buttonShuffleStatusStripstatusStripToolStripProgressBarprogressBarToolStripStatusLabelstatusLabelMenuStripmenuStrip1ToolStripMenuItemfileToolStripMenuItemheuristicToolStripMenuItemshuffleToolStripMenuItemsolveToolStripMenuItemToolStripSeparatortoolStripSeparator1exitToolStripMenuItemmanhattanDistanceMenumisplacedTilesMenumStrategymHeuristicmShuffleWindowsFormsSynchronizationContextmSyncContextSystem.Collections.GenericDictionary`2mButtonsmInitialStatemBusyInitializeSwapValuesOnStrategyStateChangedOnPuzzleSolvedDisplayStateStartSolvingPuzzleActionAllowedEventArgsShuffleButton_ClickMouseEventArgsButton_MouseDownDragEventArgsButton_DragEnterButton_DragDropStartButton_ClickShuffleMenu_ClickSolveMenu_ClickExitMenu_ClickManhattanDistanceMenu_ClickMisplacedTilesMenu_ClickdefaultInstanceget_DefaultDefaultvalue__MisplacedTilesManhattanDistanceLeftRightUpDownget_Indexset_Indexget_KeyIndexKeymNodesmSpaceIndexmStateCodemCostfmCosthmCostgmParentEqualsGetHashCodeCompareToIsCostlierThanGetStateCodeCalculateCostGetHeuristicCostGetMisplacedTilesCostGetManhattanDistanceCostGenerateStateCodeGetStateIsFinalStateGetParentList`1GetNextStatesGetNextStateSwapCanMoveToString<Index>k__BackingFieldInvokeIAsyncResultAsyncCallbackBeginInvokeEndInvokeSystem.DiagnosticsStopwatchmStopWatchOnStateChangedadd_OnStateChangedremove_OnStateChangedadd_OnPuzzleSolvedremove_OnPuzzleSolvedSolveStartStartMeasureEndMeasureOnFinalStatePuzzleSolvedmArraymCountmHashmapExpandLessSinkSwimIsEmptyEnqueueDequeueFindRemoveRandommRandomShuffleNextRandomvaluedisposingxystateisFinalstepstimestatesExaminednodessendereparentheuristicobjthatStatenextStatesdirectionijnewPositionSystem.Runtime.InteropServicesOutAttributeobjectmethodcurrentStatecallbackresultstateExaminedstateCountstatescapacityindexitemkeyarrayminmaxaSystem.Runtime.VersioningTargetFrameworkAttributeSystem.ReflectionAssemblyTitleAttributeAssemblyDescriptionAttributeAssemblyConfigurationAttributeAssemblyCompanyAttributeAssemblyProductAttributeAssemblyCopyrightAttributeAssemblyTrademarkAttributeAssemblyCultureAttributeComVisibleAttributeGuidAttributeAssemblyVersionAttributeAssemblyFileVersionAttributeDebuggableAttributeDebuggingModesSystem.Runtime.CompilerServicesCompilationRelaxationsAttributeRuntimeCompatibilityAttribute15PuzzleSystem.CodeDom.CompilerGeneratedCodeAttributeDebuggerNonUserCodeAttributeCompilerGeneratedAttributeReferenceEqualsTypeRuntimeTypeHandleGetTypeFromHandleAssemblyget_AssemblyEditorBrowsableAttributeEditorBrowsableStateSTAThreadAttributeApplicationEnableVisualStylesSetCompatibleTextRenderingDefaultRunExceptionget_MessageMessageBoxDialogResultShowIDisposableControlSuspendLayoutAnchorStylesset_AnchorSystem.DrawingColorFromArgbset_BackColorControlCollectionget_ControlsAddPointset_Locationset_NameSizeset_Sizeset_TabIndexset_AllowDropFontFontStyleGraphicsUnitset_Fontget_WhiteSmokeset_ForeColorset_TagButtonBaseset_UseVisualStyleBackColorDragEventHandleradd_DragDropadd_DragEnterMouseEventHandleradd_MouseDownset_TextEventHandleradd_ClickToolStripToolStripItemCollectionget_ItemsToolStripItemAddRangeset_AutoSizePaddingset_Paddingget_TransparentToolStripDropDownItemget_DropDownItemsKeysset_ShortcutKeysSizeFContainerControlset_AutoScaleDimensionsAutoScaleModeset_AutoScaleModeset_ClientSizeFormBorderStyleset_FormBorderStyleset_MainMenuStripset_MinimizeBoxResumeLayoutPerformLayoutSystem.ThreadingSynchronizationContextget_CurrentInt32<PrivateImplementationDetails>{A84D0B03-3A33-4631-9B3F-AA2C6EDA1C6B}ValueType__StaticArrayInitTypeSize=36$$method0x6000009-1RuntimeHelpersArrayRuntimeFieldHandleInitializeArrayset_ItemProgressBarStyleset_Styleset_Visibleset_Checked<>c__DisplayClass1<>4__this<OnStrategyStateChanged>b__0SendOrPostCallbackPostThreadSleep<>c__DisplayClass5Actionaction<OnPuzzleSolved>b__3<OnPuzzleSolved>b__4CursorsCursorset_CursorStringDoubleConcatIWin32WindowSendget_Itemset_Enabledget_WaitCursorget_TagTryParseTryGetValueDragDropEffectsDoDragDropIDataObjectget_DataDataFormatsTextGetDataPresentset_EffectGetDataClose.cctorSettingsBaseSynchronizedMathSqrtAbsSystem.TextStringBuilderAppendCharTrimCopyClearGetValuesSystem.CollectionsIEnumeratorGetEnumeratorMoveNextDelegateCombineInterlockedCompareExchange<Solve>b__0WaitCallbackThreadPoolQueueUserWorkItemget_CountResetStopStack`1PushPopget_ElapsedMillisecondsDateTimeget_NowTimeSpanget_TimeOfDayget_TotalSecondsNextPuzzle.Form1.resourcesPuzzle.Properties.Resources.resources7Puzzle.Properties.ResourcesgamePanel)Microsoft Sans Serifbutton98button767button8button65button54button323button21button10button4buttonStartSolvebuttonShuffleShufflestatusStripstatusStrip1progressBarstatusLabelmenuStrip1+fileToolStripMenuItem&File1shuffleToolStripMenuItem-solveToolStripMenuItem'toolStripSeparator1+exitToolStripMenuItem	Exit5heuristicToolStripMenuItem&Heuristic+manhattanDistanceMenu%Manhattan Distance%misplacedTilesMenuMisplaced TilesForm18 PuzzleOYou can drag & drop to shuffle tiles...Steps: n0, Time: n2, States: _Solution found! Click on Ok to see the steps...'Steps: none, Time: n3sec, States: %No solution found!'Finding solution...*
State:	, g:	, h:	, f:M�3:1F�?�,n�k�z\V4�! !!!% )-159=AE08IM-     Q U Y   (($	 $ $   $  $ ]$]$ $   
 ae a
 aei( (, ,  $ $M    m     �� @3System.Resources.Tools.StronglyTypedResourceBuilder4.0.0.0���� �� �� ��	���� ���?_�
:�� �� �� �� � � �
� �	��  � � �! �) �-  �1 �9  �= �E �I =�-�-�-�-�M@	�]�a8M-  �e �iD�q�y �y 	����

H   	 ����-- ��  �� --YKMicrosoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator10.0.0.0����$ 


 �� ��
�]�]]$�]�� ��$����	������
((((
,,,,��L4$M$  "$]$4$M$$$$$��$	��$ 
4M	�� �� 
8	����e).NETFramework,Version=v4.0,Profile=ClientTFrameworkDisplayName.NET Framework 4 Client Profile
15PuzzleCopyright ©  2012)$b8e3eda2-3fc2-49e9-a9a3-afbf5ae444ee1.0.0.0TWrapNonExceptionThrowsTR�QVhhaRSDS3�V��@>L�'���=E:\Projects\VS\15Puzzle\15Puzzle\obj\x86\Release\15Puzzle.pdb�� �_CorExeMainmscoree.dll�% @ �8�P�h������P���4VS_VERSION_INFO���?DVarFileInfo$Translation�StringFileInfo�000004b0<	FileDescription15Puzzle0FileVersion1.0.0.0<
InternalName15Puzzle.exeHLegalCopyrightCopyright �  2012D
OriginalFilename15Puzzle.exe4	ProductName15Puzzle4ProductVersion1.0.0.08Assembly Version1.0.0.0<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
        <requestedExecutionLevel level="asInvoker" uiAccess="false"/>
      </requestedPrivileges>
    </security>
  </trustInfo>
</assembly>
�0

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer CLSA Ltd
Hong Kong Hong Kong
A software developer, working as a Trading Algorithm developer in CLSA. I have been in software industry since November, 2007. I have experience in .NET technologies, C#, C, Java, trading algorithms, machine learning and AI.

Comments and Discussions