home *** CD-ROM | disk | FTP | other *** search
- Path: news.ao.net!news
- From: Jude Anthony <jude@p3.enzian.com>
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: scramble game algorithm?
- Date: Wed, 27 Mar 1996 10:22:23 -0800
- Organization: Enzian Technology
- Message-ID: <3159875F.7951@p3.enzian.com>
- References: <3157B388.3F20@sapiens.com>
- NNTP-Posting-Host: 204.240.62.132
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (Win16; I)
-
- Avi L. wrote:
- > Hi there, i'm trying to figure out an algorithm for solving the
- > famous scramble game, i've succeeded in solving most of the game
- > however there are situations which require more logic added in
- > order to search for a better path to move the pieces around.
- > especially the following situation is troublesome:
- >
- > 1 2 3 4
- > 5 6 7 8
- > 9 10 11 12
- > 14 15 13 -1.
- >
- > -1 == empty space.
- > how do you get the 13 piece to its proper place and then manage
- > to get the other pieces back to thier original position and thus
- > solve this damn game.
- > i know how to solve the game by hand however translating
- > it to software code isn't so straight forward. guess
- > life's too complex for that, eh?!
- > thank you in advance for any information.
-
- You need a different algorythm, I think. Forget the logic; this can be
- easily solved with a simple tree. Since there is no position from which
- more than four pieces can move into the empty square, you create a tree
- with four branches at each node. A structure with four pointers will be
- necessary; I would also include an array specifying the board position
- after the move has been made and an integer specifying the array index of
- the piece moved:
-
- struct node_TAG
- {
- int moveme;
- int board[4][4];
- struct node_TAG *next[4];
- } node;
-
- Write a recursive function to tranverse this tree. Every step, move each
- possible tile into the space and create a new node for the new board
- position. Compare the node to previous board configurations to make sure
- you're not duplicating your work. Stop and return when there are no
- non-repetetive board configurations, or you reach a node with a solved
- board.
-
- If you actually create the entire tree (instead of stopping when you
- reach your first solve), this algorythm gives you the added bonus of
- being able to find the fewest moves necessary to solve the board.
-
- Thanks for making me think of this problem. I may go and write it up
- myself, for a practical exercise. I hope this solution is more useful to
- you.
-
- Later,
- GreyFox
- jude@p3.enzian.com
-