Search In
• More options...
Find results that contain...
Find results in...

# help in pascal

## Recommended Posts

In pascal i have an 2 dimensional array for a gameboard and another one for mines. I have the game randomly place an user selected number of mines in the field. you have to get from point a to point b without colliding with an mine.

AXXXXXXXX
X*XXXXXX*
XXX***XXX
XXXXXXXXX
XXXX*XXXB

THE 135,145,436,413,145,145\$ QUESTION IS:
How can i make sure thatthere is a path from point a to point b that there are no mines on? Diagonals count.

I can't figure it out by myself.

And also there is buffer space on the outside so i can fill it up with mines if I have to

By the way, it resembles an old dos game. Text mode though.

##### Link to post

hmm I dont know pascal, but here's how I'd suggest it.

Step 1: get the info of where the start tile is
Step 2: get info about the tile to the left of it
Step 3: if this isnt a mine then get info about the tile to the left of that
if it is a mine go back to the previous tile and look at the tile below it and repeat.

In otherwords, keep checking for tiles which arent mines from the current position of the check until it reaches a tile which is marked as the exit. In other words, send the computer through the maze, but whenever it hits a mine, it doesnt die but instead goes to the previous tile and checks the next one.

##### Link to post

i'd imagine a* would be useful for this

##### Link to post

Yeah, I can't think of any way a program can do that besides recursively. Go with what wacky said.

##### Link to post

A* is probably the best pathing algorithm you'll find. At each "node" on the grid, both the cost from the starting point, and the estimated cost (guess a rough guess, usually based on distance) of getting to the goal are recorded. Since the algorithm at each node cares about how costly it is to get there, and roughly how costly it is to get to the goal node, you end up getting really efficent paths.

There's some really good pages out there that do a good job of explaining A* in detail. If you have any questions, let me know and I'll do the best I can to help.

Oh yeah, and stop using Pascal :P

##### Link to post

A* is really efficient, but it's definitely more complicated than a quick and dirty backtracking algorithm.

Pascal will work for what you're doing now, but I'd suggest you kick that shit and do it in C.

DC

##### Link to post
Doom-Child said:

A* is really efficient, but it's definitely more complicated than a quick and dirty backtracking algorithm.

Pascal will work for what you're doing now, but I'd suggest you kick that shit and do it in C.

DC

1) I am 15
2) I don't know C yet.

##### Link to post
doom2day said:

1) I am 15

That's not an excuse for using Pascal.

Though, you're young enough that you may still have a chance to recover.

##### Link to post

Would be great if this was C, but some help with pascal please!

##### Link to post

Pascal and Qbasic are the only languages I know. I prefer pascal.

##### Link to post
Fredrik said:

That's not an excuse for using Pascal.

Though, you're young enough that you may still have a chance to recover.

Hey, I first used it when I was 17. :P

##### Link to post

Actually, thinking about it, yeah, you may want to stick to Pascal until you get some more grounding in data structures. In particular, this problem is perfect for the application of both a stack and a graph.

And until you've got a good grip on those, I don't think you're going to be able to do a great job on something like this.

DC

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account