java - Sliding Block Puzzle, how to approach this -


i taking ai course, , first problem assigned create program solve sliding brick puzzle.

now, our professor hasn't given information on how approach this. 2 classes in , covered definition of ai, , agents.

i lost how approach problem. given text files represent board, , code set translate board 2d array, print out, etc. (the easy stuff). need work towards solving clueless about.

here example of board:

1,1,1,1,1,1, 1,3,2,2,4,1, 1,5,2,2,6,1, 1,7,7,8,8,1, 1,9,9,10,10,1, 1,0,0,0,0,1, 1,0,0,0,0,1, 1,1,-1,-1,1,1, 

1 represents wall

0 represents blank space

-1 represents winning area

2 represents "special block"

anything greater 2 "non special" block

does know algorithms use approach problem with? or possibly resource.

here example of game itself: http://www.mathplayground.com/slidingblock.html

suppose represent states as

class state {     int[][] a; } 

then should implement following functions

  • list<state> getneighbors(state s) - function should give possible states obtained s making valid move. should find pieces , try translate them up, down, left, right.

  • void solve(state s) - function should solve puzzle using standard algorithm dfs, bfs, a* etc. may want keep track of states you've visited in list list<state> visited or more in hash set hashset<state> visisted, hash set you'd have implement hash function.

note represent states @ string eliminate necessity implement hash function.

if don't want search bricks in every state represent bricks as

class brick {     list<point> points; }  class point {     int x, y; } 

and, alternatively, represent state as:

class state {     int[][] a;     list<brick> bricks; } 

in way, finding of possible moves easier:

list<state> getneighbors(state s) {     list<state> neighbors = new arraylist<state>();     (brick b : s.bricks) {          // if can move brick          // create new state new_state_up update 'a'          // , 'bricks' , add neighbors.          // same rest of directions     }     return neighbors; } 

Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -