Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (AemStones, AndrewAMD, gamers, Kingware), 1,679 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19054 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Calculate distance in a board game #172068
12/10/07 16:38
12/10/07 16:38
Joined: Oct 2004
Posts: 290
Latvia
Leonardo Offline OP
Member
Leonardo  Offline OP
Member

Joined: Oct 2004
Posts: 290
Latvia
Hi! I am writing a board game AI, that moves and attacks the player's pieces. Let's say I have a board that is 8x8 squares large and I need to calculate the shortest distance from one square to another, keeping in mind that some of the squares in the path cannot be used, because they are full, so the AI player needs to get around these squares.
Anything is appreciated - ranging from simple ideas to full pieces of c-script code.
Oh, another thing - it would be good if someone could explain to me how to do this using nodes.

Leonardo


"Things of the mind left untested by the senses are useless."
Re: Calculate distance in a board game [Re: Leonardo] #172069
12/10/07 17:20
12/10/07 17:20
Joined: Dec 2000
Posts: 4,608
mk_1 Offline

Expert
mk_1  Offline

Expert

Joined: Dec 2000
Posts: 4,608
Check out Dijkstra's algorithm. It is easy and for a 8x8 board it's more than fast enough.


Follow me on twitter
Re: Calculate distance in a board game [Re: mk_1] #172070
12/11/07 04:56
12/11/07 04:56
Joined: Jan 2006
Posts: 968
EpsiloN Offline
User
EpsiloN  Offline
User

Joined: Jan 2006
Posts: 968
The Manhattan distance
Quote:


H can be estimated in a variety of ways. The method we use here is called the Manhattan method, where you calculate the total number of squares moved horizontally and vertically to reach the target square from the current square, ignoring diagonal movement, and ignoring any obstacles that may be in the way. We then multiply the total by 10, our cost for moving one square horizontally or vertically.

Reading this description, you might guess that the heuristic is merely a rough estimate of the remaining distance between the current square and the target "as the crow flies." This isn't the case. We are actually trying to estimate the remaining distance along the path (which is usually farther). The closer our estimate is to the actual remaining distance, the faster the algorithm will be. If we overestimate this distance, however, it is not guaranteed to give us the shortest path. In such cases, we have what is called an "inadmissible heuristic."

Technically, in this example, the Manhattan method is inadmissible because it slightly overestimates the remaining distance. But we will use it anyway because it is a lot easier to understand for our purposes, and because it is only a slight overestimation. On the rare occasion when the resulting path is not the shortest possible, it will be nearly as short. Want to know more? You can find equations and additional notes on heuristics here.




Source :
http://www.igda.org/Forums/showthread.php?threadid=22955
(But thats not the original tutorial, I dont have time to find it right now and btw , there was a whole section in a site , I forgot it , but there was an explanation to many ways of calculating distance to a target square )


Extensive Multiplayer tutorial:
http://mesetts.com/index.php?page=201
Re: Calculate distance in a board game [Re: Leonardo] #172071
12/11/07 16:05
12/11/07 16:05
Joined: Dec 2000
Posts: 4,608
mk_1 Offline

Expert
mk_1  Offline

Expert

Joined: Dec 2000
Posts: 4,608
Quote:

<...>keeping in mind that some of the squares in the path cannot be used, because they are full, so the AI player needs to get around these squares.




Manhattan distance doesn't work here.


Follow me on twitter
Re: Calculate distance in a board game [Re: mk_1] #172072
12/11/07 19:38
12/11/07 19:38
Joined: Jan 2006
Posts: 968
EpsiloN Offline
User
EpsiloN  Offline
User

Joined: Jan 2006
Posts: 968
Quote:

ignoring any obstacles that may be in the way



Thats for the pathfinding to 'check'


Extensive Multiplayer tutorial:
http://mesetts.com/index.php?page=201
Re: Calculate distance in a board game [Re: EpsiloN] #172073
12/11/07 21:09
12/11/07 21:09
Joined: Dec 2000
Posts: 4,608
mk_1 Offline

Expert
mk_1  Offline

Expert

Joined: Dec 2000
Posts: 4,608
no need for heuristics on an 8x8 map


Follow me on twitter

Moderated by  adoado, checkbutton, mk_1, Perro 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1