Page 1 of 1

Streetcar

Posted: 14 June 2024, 17:32
by AxeCrazy
G'day,

I am (also :P ) in progress of buidling streetcar in which a player needs to travel for his start terminal to the endterminal after the track is possible (players lay track part by turn.

That i managed to get automated (detection if it is possible at least),
But the player also needs to pass by at least 2 buidlings (marked by letters A-I).
The train can not "turn around" so it has to pass by alll locations ad travel from his start to end position

Anyone got a briljant idea on how to check this via code?
Or should i ask all opponents to agree the route is possible before the player can start his journey

[fimg=https://imgur.com/a/gzuPdIG]

Re: Streetcar

Posted: 14 June 2024, 18:55
by RicardoRix
There is a thing called A* path search algorithm
https://en.wikipedia.org/wiki/A*_search_algorithm
I remember watching a youtube video about it once.
https://www.youtube.com/watch?v=ySN5Wnu ... FsZ29yaXRt

I had to do this for a hex map in my game Finity, but I came up with my own algorithm. CheckRoutes(), but it's pretty hairy.

Other games must have had to do this, a few train games come to mind.

Re: Streetcar

Posted: 14 June 2024, 19:59
by AxeCrazy
Found that A* algorithm indeed, but that does not take driving directions into account I believe.

But I’ll check again

Re: Streetcar

Posted: 14 June 2024, 21:39
by tchobello
AxeCrazy wrote: 14 June 2024, 17:32 G'day,

I am (also :P ) in progress of buidling streetcar in which a player needs to travel for his start terminal to the endterminal after the track is possible (players lay track part by turn.

That i managed to get automated (detection if it is possible at least),
But the player also needs to pass by at least 2 buidlings (marked by letters A-I).
The train can not "turn around" so it has to pass by alll locations ad travel from his start to end position

Anyone got a briljant idea on how to check this via code?
Or should i ask all opponents to agree the route is possible before the player can start his journey

[fimg=https://imgur.com/a/gzuPdIG]
what are you struggling with ?

Re: Streetcar

Posted: 17 June 2024, 10:25
by AxeCrazy
Struggeling not really, since i do not have a briljant idea of how to get started in the first place.
See available trackparts below.
[fimg=https://imgur.com/a/vgH1SVo]
See example gameboard [fimg=https://imgur.com/a/gzuPdIG]

The idea is that there is a track starting at a tram station have to drive to the endstation of the same number passing 2 (or 3 in a <3 players game) location on the board in a path , without reversing.
Eg. fro above example Start on the left 6, passing location M and C ending at the right 6.
no >90 degree angles can be taken.

Will look into A* for this, but that does not take the 90degrees option into account, so i have build an exception for that also.

Once i get to it, i wiil probably get it done, just thinnking about which starting point of the algoritm i should take :)

Thanx

Re: Streetcar

Posted: 17 June 2024, 13:33
by Tisaac
Any usual path algorithm in a graph would work here, you dont even need to find the shortest path so BFS or DFS are ok.
The trick is to not take one node per tile but instead to have node on the edges (so 4 nodes per tiles, but shared with the neighbours).
So for a given tile, you would have T_N, T_S, T_E, T_W, and you connect two of them if and only if the current tile allow you to go from one to the other.
For instance for the first tile at location 6, you would only connect T_W and T_E.
The tile on the H would give the following links : T_W and T_E / T_E and T_N (but not T_N and T_W because of the tile).

Hope it helps !

Re: Streetcar

Posted: 17 June 2024, 20:06
by AxeCrazy
I already have each possible route described based on the North,east, south and west.
Depending on the rotation of the track (yes it can also be rotated :))
array(
array(
"N" => "ES",
"E" => "N",
"S" => "Nw",
"W" => "S",
),
array(
"N" => "W",
"E" => "SW",
"S" => "W",
"W" => "NE",
),
array(
"N" => "ES",
"E" => "N",
"S" => "Nw",
"W" => "S",
),
array(
"N" => "W",
"E" => "SW",
"S" => "W",
"W" => "NE",
),
),

I think this should be a good base for determining the route.

thanx