Project G2 EightPuzzle.docx

download Project G2 EightPuzzle.docx

of 22

Transcript of Project G2 EightPuzzle.docx

  • 7/21/2019 Project G2 EightPuzzle.docx

    1/22

    GAME 8-PUZZLE

    Group Members:

    - Jose Vizueta

    - Manuel Sanchez

    Group # 2

  • 7/21/2019 Project G2 EightPuzzle.docx

    2/22

    Introduction

    The 8-puzzlea!e consist o" 8 di#erentl$ nu!%ered chips are &tted into 'spaces on a rid( )ne space is le"t %lan* so that tiles can %e !o+ed aroundto "or! di#erent patterns(

    The oal is to &nd a series o" !o+es o" tiles that places the %oard in a oalcon&uration( This is a co!!on a!e that !ost o" us pla$ed as children(

    This a!e has so!e interestin aspects that ha+e !ade it an e,cellentapplicant in pro%le! sol+in the a!e states are eas$ to represent it has

    si!ple to de&ne heuristics and a !anaea%le state space(The use o" .euristics is one o" the %est alternati+es in pro%le!s /here thestate space ro/s e,ponentiall$ or "actoriall$ and search techni0ues such asdepth-&rst or %readth-&rst !a$ "ail to &nd the solution or ta*e too lon ti!e(

    Guidin the search alon the !ost 1pro!isin2 path throuh the space anda+oidin unpro!isin states and their descendants "ro! consideration aheuristic alorith! can &nd 0uic*l$ an accepta%le solution(

    In this pro3ect /e used a .euristic Search alorith! li*e 4est 5irst Search toreach the Goal State or solution "ro! an$ Initial State o" the %oard o" the 8-Puzzle a!e usin t/o di#erent .euristics6 Manhattan 7istances andMisplaced hips(

  • 7/21/2019 Project G2 EightPuzzle.docx

    3/22

    Methodolo$

    RepresentationGa!e states can %e represented usin a si!ple 9 : 9inteer arra$ co!posed o" nu!%ers %et/een ; and 8considerin zero as the e!pt$ space in the %oard/here each ele!ent represents the correspondin chipin the sa!e position6

    state=[0 1 2

    3 4 5

    6 7 8]

    Details of concepts for developer the application

    Initial State:an$ state con&uration possi%le /ith chips in an$ position(

    Goal State:state that speci"$ a particular con&uration to %e achie+ed(

    State space:The state space is represented %$ a raph /here each noderepresent a %oard con&uration and its children the resultin set o" %oardsa"ter !o+e the e!pt$ space on < possi%le directions = up do/n le"t riht >(

    Set of operators and Restrictions: To represent the leal !o+es in ourpro%le! /e de&ne rules that trans"or! our 9,9 !atri, =representin a state>in another 9,9(

    In the ph$sical puzzle !o+es are !ade %$ !o+in an$ o" the =;-8> tiles %ut"or our i!ple!entation it?s %etter to thin* in ter!s o" 1!o+in the e!pt$

    space2( This si!pli&es the de&nition o" a leal !o+e %ased onl$ in this sinlee!pt$ space(

    In order to appl$ a !o+e /e !ust !a*e sure that it does not !o+e the %lan*ta o# the %oard(

    The leal !o+es are6

    Operat Precondit Answer Comments

    ; @9 <

    B C 8

  • 7/21/2019 Project G2 EightPuzzle.docx

    4/22

    or ion

    up A=i3>DiF;

    A=i-;3>DH A=i3>D A=i-;3>

    Mo+e chip to up

    right A=i3>D39

    A=i3;>DH A=i3>DA=i3;>

    Mo+e chip toriht

    left A=i3>D3F;

    A=i3-;>DH A=i3>DA=i3-;>

    Mo+e chip to le"t

    down A=i3>Di9

    A=i;3>DH A=i3>DA=i;3>

    Mo+e chip todo/n

    Meta Check:This "unction chec*s i" the state corresponds to the &nal statei+en %$ the con&uration o" the chips in the order o" the taret node(

    Cost function:it ta*es into account the cost o" operations and the cost o" thepath is the su! o" the costs o" the operations used to reach the oal(

    Heuristic Function

    The 8-puzzle a!e is rich enouh to pro+ide a nu!%er o" interestinheuristics(

    In our i!ple!entation /e used t/o heuristics6

    - Misplaced Chips:The si!plest heuristic counts the chips out o" placein each state /hen co!pared /ith another state(

    - Manhattan Distance: This heuristic su! all the distances %$ /hicheach !isplaced chip !ust %e !o+ed to reach its position in the oalstate(

    Search Algorithm

    est !irst Search4est 5irst is a .euristic Search alorith! it "ollo/s one path at a ti!e %ut itcan chane the search path accordinl$ %ased on the %est pro!isin pathahead than the current path(

    This alorith! uses t/o lists o" nodes and a heuristic "unction that esti!atesthe !erits o" each node to %e e,plored6

    "# Openlist K it contains the enerated nodes( The heuristic "unction has%een applied to the!H %ut the$ ha+e not %een tested $etH that is theirsuccessors ha+e not %een enerated $et( )pen can %e considered as apriorit$ 0ueue in /hich the ele!ents are ordered accordin to so!eheuristic esti!ate o" their 1closeness2 to a oal

    $# Closelist K It record states alread$ +isited that /ere not the oal node(

  • 7/21/2019 Project G2 EightPuzzle.docx

    5/22

    The pseudocode "or the "unction %est&rstsearch appears %elo/(

    At each iteration %est&rstsearch re!o+es the &rst ele!ent "ro! the openlist( I" it !eets the oal conditions the alorith! returns the solution paththat led to the oal(

    I" the &rst ele!ent on open is not a oal the alorith! enerates itsdescendants(

    I" a child state is not on open or closed %est&rstsearch e+aluates that stateand then is added to the open list and the open list is sorted accordin tothe heuristic +alues o" those states( This %rins the 1%est2 states to the "ronto" open(

    I" a child state is alread$ on open or closed the alorith! chec*s to !a*esure that the state records the shorter o" the t/o partial solution pathsa+oidin duplicate paths( 4$ updatin the path histor$ o" nodes on open andclosed /hen the$ are redisco+ered the alorith! /ill &nd a shortest path toa oal(

  • 7/21/2019 Project G2 EightPuzzle.docx

    6/22

    "unction %est&rstsearchH%ein

    open 6D StartNH Oinitialize

    closed 6D NH/hile open N do O states

    re!ain%ein

    re!o+e the le"t!ost state "ro! open call it QHi" Q D oal then return the path "ro! Start to Qelse %ein

    enerate children o" QH"or each child o" Q docase

    the child is not on open or closed6%ein

    assin the child a heuristic +alueH

    add the child to openendHthe child is alread$ on open6

    i" the child /as reached %$ a shorter paththen i+e the state on open the shorter

    paththe child is alread$ on closed6i" the child /as reached %$ a shorter path then

    %einre!o+e the state "ro! closedHadd the child to open

    endH

    endH O caseput Q on closedHre-order states on open %$ heuristic !erit =%est le"t!ost>

    endH

  • 7/21/2019 Project G2 EightPuzzle.docx

    7/22

    I!ple!entation

    The Application that /ill %e de+eloped as a +isual representation o" theprocedure "ollo/ed %$ the 4est 5irst Search /ith an o" the heuristic selected=Misplaced hips and Manhattan distances > this sho/ a tree that representthe solution path "ro! the oal state to the &nal state de&ned %$ the user (

    Re used the Ja+a prora!!in lanuae %ecause it?s an o%3ect-orientedlanuae and it "acilitates the representation o" the %oard tree nodes andits relationships(

    %oolsRe used the JUG li%rar$ to raph trees JUG the Ja+a Uni+ersal

    et/or*Graph 5ra!e/or*--is a so"t/are li%rar$ that pro+ides a co!!on ande,tendi%le lanuae "or the !odelin anal$sis and +isualization o" data thatcan %e represented as a raph or net/or*( It is /ritten in Ja+a /hich allo/sJUG-%ased applications to !a*e use o" the e,tensi+e %uilt-in capa%ilities o"the Ja+a API as /ell as those o" other e,istin third-part$ Ja+a li%raries(

    DesignThe user /ill ha+e access to a si!ple inter"ace /here he can select the initialand &nal state %oards o" a "e/ prede&ned con&urations or !anuall$ %$ user

    input and then select the heuristic utilized in the search(

    Initial State Goal State

    In each interaction @ 9 or < %elo/ possi%le states are al/a$s enerateddependin o" the !o+es the e!pt$ space could do6 up do/n le"t and riht(

  • 7/21/2019 Project G2 EightPuzzle.docx

    8/22

    The 4est 5irst Search use an e+aluation "unction "=> /here6

    f()=g ()+h()

    - 5unction gis the cost deter!ined to reach the current state "ro! the

    initial state( In our case the step cost:one !o+e!ent o" the chip(- 5unction his the esti!ated cost to reach the o%3ecti+e state "ro! the

    current state( This is deter!ined %$ the heuristic "unction(

    The result path o%tained should %e as %elo/6

  • 7/21/2019 Project G2 EightPuzzle.docx

    9/22

  • 7/21/2019 Project G2 EightPuzzle.docx

    10/22

    &se Case Diagram

    Class Diagrams

  • 7/21/2019 Project G2 EightPuzzle.docx

    11/22

  • 7/21/2019 Project G2 EightPuzzle.docx

    12/22

  • 7/21/2019 Project G2 EightPuzzle.docx

    13/22

    Se'uence Diagrams

    est !irst Search ( Search !unction

    )euristic !unction * Get Manhattan Distance +alue

  • 7/21/2019 Project G2 EightPuzzle.docx

    14/22

    )euristic !unction * Get Misplaced Chips +alue

    %ree!rame * draw %ree

  • 7/21/2019 Project G2 EightPuzzle.docx

    15/22

    ,ightPu--le!rame * Generate Solution Path

    4oard K an Mo+e Gap

  • 7/21/2019 Project G2 EightPuzzle.docx

    16/22

    E,peri!ents

    %ests

    Tests /ere realized /ith three di#erent initial con&urations o" the %oardrepresentin 9 diculties accordin to the deree to /hich the chips are!isplaced and the sa!e Goal state6

    ;(

    2 3

    1 4

    7

    easy=[58 ]

    @(

    2 4 3

    1 6 8

    7 5

    medium=

    Goal State6

    1 2 3

    4 5 6

    7 8

    goal=

    9(

    2 4

    7 8

    6

    hard=[ 15 ]

    The tests /ere realized /ith each o" the t/o heuristics =ManhattanMisplaced> a nd the e+aluation /as per"or!ed %ased on the ti!e in /hichthe solution is "ound and the nu!%er o" states /ere reached ande+aluated /ith the heuristics(

    Results

    %est " ( ,as.

    Manhattan Distance Misplaced Chips%ime 9(C secs 9(8 secs

  • 7/21/2019 Project G2 EightPuzzle.docx

    17/22

    States evaluated ; ;

    Search Path

    ( Manhattan Distance

    ( Misplaced Chips

  • 7/21/2019 Project G2 EightPuzzle.docx

    18/22

    ( %est $ ( Medium

    Manhattan Distance Misplaced Chips%ime

  • 7/21/2019 Project G2 EightPuzzle.docx

    19/22

    ( Misplac

    ed

  • 7/21/2019 Project G2 EightPuzzle.docx

    20/22

    Chips

    ( %est / ( )ard

    Manhattan Distance Misplaced Chips%ime (B9 secs ;;('; secsStates evaluated ;

  • 7/21/2019 Project G2 EightPuzzle.docx

    21/22

    onclusion

    The 4est 5irst Search pro+ed to %e a re!ar*a%le heuristic search!ethod !ore than "ollo/ the !ost pro!isin path it *eeps a record o"

    its histor$ allo/in it to step %ac* in case its path %eins to %e

    unpro!isin(

    .o/e+er the ecienc$ o" this depends !ostl$ on the heuristic used

    and ho/ representati+e it is %ased on reachin the oal state(

    As o%ser+ed in Test ; the .euristics o" Manhattan and Misplaced hipssho/ed si!ilar results as the solution /as easil$ achie+a%le ho/e+er

    /ith the increasin dicult$ the Misplaced .euristic sho/ed 0uite

    in"erior and not as ecient as the Manhattan .euristic especiall$ in

    Test 9 ha+in to e+aluate ; ti!es !ore states than the other heuristic

    and ta*in al!ost t/ice as lon ti!e(

  • 7/21/2019 Project G2 EightPuzzle.docx

    22/22

    We"erences

    ontent o" Archi+es o" Arti&cial Intellience %$ Enri0ue PelXez Ph(7(

    Geore 5( Luer Arti&cial Intellience Structures and Strateies "or

    o!ple, Pro%le! Sol+in Si,th Edition @; Addison Resle$(

    Wussel Stuart or%i Peter Arti&cial Intellience A Modern ApproachThird Edition

    ( illson( Inteliencia Articial6 una nue+a sYntesis( McGra/-.ill @;(

    ///(&c(udc(es&lesasinaturas;8IAMe!oriaPractica(pd" - a%rero .ernandez