Stunts Forum

Stunts - the Game => Stunts Reverse Engineering => Topic started by: Cas on January 23, 2021, 07:28:14 AM

Title: Opponent's path
Post by: Cas on January 23, 2021, 07:28:14 AM
I'm starting this thread without much information just so there is a place where we can drop whatever we have about this topic. The idea is  getting to fully understand how Stunts resolves what is going to be the opponent's path on a track. There has been some discussion about this in the past in different threads, but I think there isn't a thread specially for this, so it'd be better to put everything together.

We know, of course, that Stunts will try to find the shortest path for the opponent and it seems it first adds the number of tiles for each path and apparently ignores the numbers and types of obstacles there may be. However, I've made experiments in which I tried to force two equally long paths in different orientations and I haven't been able to find a theory that can predict Stunts' choice in those cases.

To show how counting tiles is non-trivial, when counting, single-tiled objects count as one tile and two-tiled objects count as two tiles, of course. Then, four-tiled objects are less clear because you can either turn or go straight and, in the case of the cork u/d, you go straight, but you follow a whole circle in the middle. My guess is Stunts ignores this and takes it as two tiles. But what if you turn?  Is it two tiles or three tiles?

My original guess was that, when path lengths were equal, Stunts would pick either the first path it resolved from the group of candidates or would display a preference either towards going straight or towards turning. I also suspected that orientation could break this, that is, rotate the track 90 degrees and the path may change. I don't remember the results of this test, but it's worth trying again.

Anyway... shoot everything you can think of!

EDIT: Maybe this should be moved to reverse-engineering...
Title: Re: Opponent's path
Post by: Daniel3D on January 25, 2021, 11:08:57 AM
I did a first test with mirror tracks,
with equal laps the opponent favors the left lap.
I think by design because that's the side they start on.

it does not matter which lap split comes first,
(oppT1 and oppT2 track both favor left side)

If the right side is shorter (oppT3) then the right side is taken,

If oppT2 has an obstacle on the left side (single slalom) then also the right is taken, (oppT2o1)

So first careful conclusions:
when equal take left,
track piece properties are taken into account,

(test are done with skid, don't know if opponent weaknesses are taken into account)
Title: Re: Opponent's path
Post by: Daniel3D on January 25, 2021, 11:21:35 AM
On default its more complex.
The outer lap is clearly longer but skid favors it anyway.
(it is the first left, so it complies with favoring left)

I know that skid sometimes does go straight at the first split,
Tested with different cars and with or without false start,

Title: Re: Opponent's path
Post by: Daniel3D on January 25, 2021, 04:22:12 PM
Quote from: Daniel3D on January 25, 2021, 11:21:35 AM
I know that skid sometimes does go straight at the first split,
Tested with different cars and with or without false start,

Maybe path data in opponent files is the key in this case..
Title: Re: Opponent's path
Post by: Daniel3D on January 25, 2021, 09:22:26 PM
OK, test with unequal laps,
Left lap 10 straits longer than right lap.
Bernie chooses right (no surprises here)
-----
test 1 - OPPT3o1
When I change road for slalom on the right lap the first 5 don't change the preference.
When I place 6 Bernie chooses the long road.
------
test 2 - OPPT3o2
changed on the long lap two corners and two straights to banked road.
Now only two slalom tiles on the short road tip the favor to the long road.

So
the slalom has a negative modifier.  [-2?]
the banked road has a positive modifier.  [+2?]

Title: Re: Opponent's path
Post by: Duplode on January 26, 2021, 03:38:18 AM
Sorry for being a bit late to this thread, as there's something you'll want to be aware of for the next round of experiments.

Quote from: Daniel3D on January 25, 2021, 11:21:35 AM
On default its more complex.
The outer lap is clearly longer but skid favors it anyway.
(it is the first left, so it complies with favoring left)

I know that skid sometimes does go straight at the first split,
Tested with different cars and with or without false start,

Below are attached two replays of races against Skid on Default. Same track, same cars, same settings -- and yet, Skid chooses the long way in the first lap and the short way in the second. The only meaningful difference is that in the first lap I jumped over the right slalom block on the hill, as you normally would with a sufficiently fast car, while in the second one I switched lanes before the hill and took the jump from the left lane, swerving to the right just enough to avoid the left slalom block.

Why does that happen? Something I found through restunts in 2016 (only to lose the results with a fried HD before getting to document the results) is that dual-way tracks have invisible checkpoints on the road which change the path of the opponent when you hit them. While the checkpoints are set up in arbitrary positions, said positions are fixed for each track (I believe the algorithm uses a pseudo-RNG seeded with the track data, so while the positions are reproducible there shouldn't be nice patterns like those you found for the F4 cameras). As for Default, there presumably is a checkpoint somewhere on the left side of the road near the slalom blocks.

I'm reasonably sure the checkpoints are the one source of unpredictability in the opponent path choices. They might make things quite confusing in your experiments, so you'll likely want to, at least for now, do them without moving your car so that they don't become a factor. (Ideally, of course, we'd want to know where the checkpoints are. I will try to find again where their positions are in memory, though it might take me a little while to actually do it.)   
Title: Re: Opponent's path
Post by: Daniel3D on January 26, 2021, 04:39:31 AM
Thanks, that kind of makes sense.
(It's 4AM, just got woken up by one of my kids. So if I jump to a insane conclusion that might be the reason)

The opponent favours left on equal tracks. Because the player starts on the right lane. If you go through a checkpoint on the left lane this switches.
It's a simple solution for a simple AI.

(That would make default.trk have a equal left and right lap for lap calculation..)

Quote from: Duplode on January 26, 2021, 03:38:18 AM
(Ideally, of course, we'd want to know where the checkpoints are. I will try to find again where their positions are in memory, though it might take me a little while to actually do it.)   
That would be awesome
Title: Re: Opponent's path
Post by: Daniel3D on January 26, 2021, 10:46:59 AM
Quote from: Duplode on January 26, 2021, 03:38:18 AM
I'm reasonably sure the checkpoints are the one source of unpredictability in the opponent path choices. They might make things quite confusing in your experiments, so you'll likely want to, at least for now, do them without moving your car so that they don't become a factor. (Ideally, of course, we'd want to know where the checkpoints are. I will try to find again where their positions are in memory, though it might take me a little while to actually do it.)   
I've made a copy of default.trk to test this. For some reason in my test version of stunts (with edited files everywhere) opponents always go straight...
Don't know why.
In my competition version the game crashes at opponent selection,
Don't know why.

So I ran this test on the 4DSportsDriving1.1 Feb-25-1991 version *(doesn't alter core files, so it ok I guess).
When unattended the favorite route is the long way around.
When overtaking the opponent en driving on the left side (and crashing on the slalom block)
the opponent will go straight.
When left unattended again I have to put 5 slaloms on the track before the other path is favored.

So the checkpoints apparently weigh heavy in this decision. I think its to avoid collision, but that's me jumping to conclusions again.
Title: Re: Opponent's path
Post by: Cas on January 26, 2021, 06:12:43 PM
Uhm... I didn't expect this. I have downloaded the files, but I'm working and can't test right now. I think that the most certain conclusion so far is that the path the opponent will follow is not resolved when the track paths are generated before the race, by somehow dynamically during the race. The reasons could be many... To avoid collisions makes sense. I think that, if DSI chose to make this dynamic on purpose, it should've been for a reason like that one or similar, something useful. If they had decided that they wanted to make opponents more random (without losing "replayability", i.e.: determinism) then they could just issue a PRN at certain frequent events that depend on the player, such as pushing and releasing the accelerator.

The random checkpoints sound like a very complex system to have been made just for this, so with them, I would expect that checkpoints be made for something different, but happen to affect the opponent. We know that DSI were very commercial-oriented. If they spent more time on a feature, it was in hope that it'd sell better. Anyway, I don't know, the complexity of car features would be thus unexplained.

Another thing that surprised me is that even letting the opponent drive alone, their choice does depend partially on the contents of the path. I would've bet it was all about number of tiles and perhaps, placement of split points.
Title: Re: Opponent's path
Post by: Daniel3D on January 26, 2021, 08:54:47 PM
Quote from: Cas on January 26, 2021, 06:12:43 PM
The random checkpoints sound like a very complex system to have been made just for this, so with them, I would expect that checkpoints be made for something different, but happen to affect the opponent.
Good point.
I don't think they are random. I think they are a simple way to track the player.

To be the eyes of the opponent (I don't believe there is real-time tracking and the ability for the opponent to drive around the player is poor.)

A other use for this can be penalty time calculation.
Title: Re: Opponent's path
Post by: Daniel3D on January 26, 2021, 09:07:59 PM
Quote from: Cas on January 26, 2021, 06:12:43 PM
Another thing that surprised me is that even letting the opponent drive alone, their choice does depend partially on the contents of the path. I would've bet it was all about number of tiles and perhaps, placement of split points.
I've been wondering about this for a long time. I didn't understand why the opponent would choose the long road.
I figured that slowing Stunts like slalom and the loop would have influence. But that wouldn't be enough.

I don't know
If flat corners give a negative or
If banked corners give a positive modifier...
But that I can test I think...
Title: Re: Opponent's path
Post by: Duplode on February 01, 2021, 04:21:17 AM
You folks are right: my fanciful checkpoint theory was wrong. Back in 2016, a handful of coincidences about the data I was looking at, plus a dose of impatience after a long series of experiments, led me astray. (See this post (http://forum.stunts.hu/index.php?topic=3474.msg78129#msg78129) for an explanation of what it was all about.)

Going a bit further, I no longer believe the opponent path choices change during a lap. The path choices do change sometimes before a lap is driven or replayed. Though those changes aren't necessarily random, they seem arbitrary, being apparently influenced by which menu options you use. My working hypothesis right now is that starting to drive from the main menu or loading a replay from the options menu leads to the preferred (in the sense Daniel3D has been analysing here) choice being made (for instance, Skid turns left in both Default laps in my previous reply, even though he originally went straight in the second one). Beyond that, all bets are off. That perhaps can be better appreciated with a mazier track, such as ZCT078:

(https://i.imgur.com/1B7ZpH9.png)

I have attached a sample replay below. By loading or continuing the lap in various ways, you can look for the secret endings.
Title: Re: Opponent's path
Post by: Cas on February 01, 2021, 06:02:53 AM
I think I should make some more tests on this and verify it. This track really is ideal for these experiments.

By the way, looking at the track map with the graphics from Cartography reminds me of an idea I had had some time ago and never implemented: that in Bliss, one could pick among different track graphic sets, including Bliss original, that of the internal Stunts editor, Cartography and Track Blaster. Of course, I wouldn't be able to include the ones from Stunts with the editor, because it's free software, but I could have it detect the presence of Stunts and read them from there. For Cartography, I could have your permission, but for Track Blaster, I don't think I can get to ask the author, although I'm pretty sure he wouldn't mind.
Title: Re: Opponent's path
Post by: Daniel3D on February 01, 2021, 08:14:21 AM
Quote from: Duplode on February 01, 2021, 04:21:17 AM
My working hypothesis right now is that starting to drive from the main menu or loading a replay from the options menu leads to the preferred (in the sense Daniel3D has been analysing here) choice being made (for instance, Skid turns left in both Default laps in my previous reply, even though he originally went straight in the second one).
I had a fluke like that when testing the truck.

After I made the nice shot of the two starting line trucks getting ready to race, I did.
And I went straight on default. I drove beautifully through the corkscrew and I wanted to have a animated gif of it.
But in the replay my opponent kept crashing into me just before.
(I distinctly remember him taking the long road)

So one thing is sure. The opponent driven path is not stored in the replay. It is regenerated, and can differ from the original run.
Title: Re: Opponent's path
Post by: Daniel3D on February 01, 2021, 08:33:49 AM
Quote from: Cas on February 01, 2021, 06:02:53 AM
I wouldn't be able to include the ones from Stunts with the editor, because it's free software, but I could have it detect the presence of Stunts and read them from there.
Why not? Bliss is not a commercial product so there is no financial gain. And those using the editor probably have Stunts anyway.
You should make the source of the set very clear with a link to more information if possible.
(At least, that's how I see it)
Title: Re: Opponent's path
Post by: Cas on February 01, 2021, 08:37:00 PM
The thing is that the graphics from Stunts are not free software and you can't distribute a bundle as free software if it contains non-free software. The graphics from Track Blaster are also non-free software, as Track Blaster is freeware. In fact, I don't see Track Blaster mentioning a license anywhere, so we could say it's "all rights reserved", but we use it because the author made it for the community, so we know we have permission. For the graphics in Stunts, as I said, you can load them from the game if detected, but Track Blaster generates its graphics algorithmically, so there's a trick there: I can just create my own code to generate the graphics that look similar, but not the same. Anyway, Bliss uses stored graphics, not algorithms.
Title: Re: Opponent's path
Post by: Duplode on February 01, 2021, 10:26:39 PM
Quote from: Cas on February 01, 2021, 06:02:53 AM
For Cartography, I could have your permission

Sure!  :) I have attached 22 pixels/tile SVG and PNG palettes on green and transparent backgrounds, using the default style settings of Cartography. Let me know if you'd like different sizes or settings, such as wider roads.

(Note the shade of green I have used for the low ground is not the same as that in the latest release, as I changed it yesterday to improve contrast. The transparent background was also set up by changing the code, to avoid image manipulation artifacts. Also, note the elevated spans in your sprites will look slightly different than in Cartography, as there they are rendered with 70% opacity over the terrain.)

By the way, something I'll add to Cartography one of these days is an option to render the terrain in this style (http://forum.stunts.hu/index.php?topic=2855.msg53711#msg53711), which has the advantage of only requiring two colours for grass.
Title: Re: Opponent's path
Post by: Cas on February 02, 2021, 07:13:58 AM
Thanks!  Bliss uses fixed size bitmaps with alpha channel, so it is possible to give the image the percentage of transparency. I'll see how I can put it together with the graphics.
Title: Re: Opponent's path
Post by: Cas on February 04, 2021, 06:18:52 AM
Here I append the adaptation for Bliss for anybody who would like to use the graphics from Cartography. This file can be placed in Bliss main directory and could be swapped with biggfx.tga at any time to use the graphics. The editor still does not have any method to directly change the file selected for graphics, though, so only renaming the file works, but it does.
Title: Re: Opponent's path
Post by: Duplode on February 12, 2021, 11:36:42 PM
It felt good to see the Cartography graphics in Bliss -- it's a nice crossover episode  :)

Over this week I have fixed a few minor display bugs in some of the Cartography sprites. For instance, if you look very hard at the palettes in my previous post you will notice a slight mistake in the proportions of the highway divider at the transition. I have attached corrected versions of the four images, in case you want to regenerate the TGA file.
Title: Re: Opponent's path
Post by: Cas on February 13, 2021, 08:02:59 AM
Oh, I had not noticed that!  Well, I actually didn't generate the TGA file automatically. I manually edited it. It took some time  :P  But I think if it's just a couple of items, it'll be quick to fix :)
Title: Re: Opponent's path
Post by: Duplode on February 13, 2021, 12:07:48 PM
Quote from: Cas on February 13, 2021, 08:02:59 AM
But I think if it's just a couple of items, it'll be quick to fix :)

Here is the full list of changed items, then: highway transitions, windmills, and Joe's.
Title: Re: Opponent's path
Post by: Cas on February 13, 2021, 10:44:30 PM
I'll go straight for them! :)
Title: Re: Opponent's path
Post by: JTK on February 15, 2021, 03:22:34 PM
Quote from: Cas on February 01, 2021, 08:37:00 PM
In fact, I don't see Track Blaster mentioning a license anywhere, so we could say it's "all rights reserved", but we use it because the author made it for the community, so we know we have permission.

I also think, there's no problem! But if you want to I can contact Mark Nailwood to declare Track Blaster Pro as freeware (and probably share its code).
Title: Re: Opponent's path
Post by: Cas on February 15, 2021, 08:45:57 PM
Quote from: JTKBut if you want to I can contact Mark Nailwood
You can?  It would be amazing to be able to have contact with him. Track Blaster allowed for things that changed Stunts community and it took a long time till Bliss came up much, much later, so it would've been very different without his work.

About the licensing, of course I know it's not a problem, but if I want to respect the GPLv3 that I use for Bliss, I can't bundle it with non-free software, so freeware is not enough. On the other hand, his permission to use the graphics would be enough as long as I don't include the graphics with Bliss, but separately somewhere else.

Anyway, at the time TB was made, it was not so common for people to make their work free software. Freeware was the rule. If he had been making TB recently, surely, it would have been free software and its source would've been placed in a repository. I mean, it's not that he didn't intend his software to be free. It was the times. That's my guess or understanding of it. In fact, I used to make freeware back then too.
Title: Re: Opponent's path
Post by: JTK on February 16, 2021, 07:19:44 AM
I try and come back to you. Hopefully with Mark Nailwood in the backseat.  :)
Title: Re: Opponent's path
Post by: JTK on May 28, 2021, 07:35:33 AM
Yes! I managed to dig Mark out! Now let's see, what he'll say about Track Blaster. He already told me, that you may use the graphics whatsoever and he is trying to find the old Turbo Pascal files. Probably he'll write here himself! The return of a legend, by the way! ;D
Title: Re: Opponent's path
Post by: Duplode on May 28, 2021, 02:47:17 PM
Quote from: JTK on May 28, 2021, 07:35:33 AM
Probably he'll write here himself! The return of a legend, by the way! ;D

Forum registration approved  :)
Title: Re: Opponent's path
Post by: Cas on May 29, 2021, 01:10:05 AM
:D  That'd be amazing!  It'd be an honour!  I'd like him to also take a look at Bliss and give any opinions. If he can make Track Blaster free software, that'd also be great.
Title: Re: Opponent's path
Post by: Mark Nailwood on May 31, 2021, 01:05:43 AM
Hello everyone! :D

Yes, thanks to JTK I'm finally back in the community. He made me aware of the forum and this thread. Let me use it to post a short (or maybe long) update message.

Well, after my last races in JTK's competition of 2001, I didn't have so much time any more to take part in contests. I knew that there was still an active community that considered new contests and even the implementation of a new version of Stunts, but I never thought that this community would be active for two decades - and still going strong in 2021.

Even more, I am feeling really honored that my Stunts tools are still remembered today. :)
The first one was Track Blaster, which made it possible to create new terrain landscapes for existing tracks by placing the water and hill elements on the grid. Then I extended it into the "Pro" version, which offered also an editor for the track elements. By the way, the idea for the name was influenced by my desktop PC's sound card, the "Sound Blaster Pro". 8)  Over the time, I implemented new features like a previous/next track function (for browsing through a directory of tracks), a copy/cut and paste function of a selection, transformation of a selection with mirroring or 180 deg. rotation, and so on. I was too lazy to properly code the correct editing of multi-block track elements (2x1 like corkscrews and loopings or 2x2 like banked corners or curved bridges), so you had to select and place all 2 or 4 sub-elements manually. But this also made it possible to create special visual effects, like bridge curves where you could drive below, or banked corners where you could drive through. ;)  I'm sure you all found out how to do it - but if needed, I can also explain it in detail, of course.
The next tool, Score Blaster, was useful for cleaning up highscore files. Additionally, it could be used as a file preview plugin in the popular file manager Norton Commander, to quickly show the highscores when browsing through a directory of tracks.
Finally, I started to hack the car files. To discover the meaning of the various bytes I created a graphic visualizer of the raw car file that could also highlight the byte differences of two cars. So I was able to find the section where the torque curve of the engine was coded, for example. This evolved into Car Blaster.

Back then, I played countless races with some friends, and we also created many tracks with interesting terrain or special effects, so these tools proved to be really useful for us. Around 1995, when we started using the Internet in our University, I thought that these tools could also be useful for others. So with just some basic HTML knowledge I created some quick and dirty web pages for publishing my Stunts tools.

As JTK wrote, these tools were created with Turbo Pascal, the development environment that I also used during my study of Computer Science. I am sure I'll find the Track Blaster source code somewhere in my backups, but the real challenge will be to understand the code and logic (even for me). It started as a quick and dirty implementation for my personal use and over the time it was just enhanced with features, not with coding style cleanup or documentation. ::)  But feel free to try, I will assist whenever my time permits.

I have already seen that there are now so many great new software tools and game enhancements, so please allow me some time to become up to date - and who knows, maybe you'll also see me back on the racing tracks in a not too distant future. After two decades it could be time to try it again. 8)

All the best - stay safe and keep driving!
Mark Nailwood
Title: Re: Opponent's path
Post by: KyLiE on May 31, 2021, 03:20:12 AM
Welcome back Mark!  It's great to hear your stories about Stunts from decades past.  I look forward to racing with you if you get the chance! :)
Title: Re: Opponent's path
Post by: llm on May 31, 2021, 09:28:34 AM
Quote from: Mark Nailwood on May 31, 2021, 01:05:43 AM
As JTK wrote, these tools were created with Turbo Pascal, the development environment that I also used during my study of Computer Science. I am sure I'll find the Track Blaster source code somewhere in my backups, but the real challenge will be to understand the code and logic (even for me). It started as a quick and dirty implementation for my personal use and over the time it was just enhanced with features, not with coding style cleanup or documentation. ::)  But feel free to try, I will assist whenever my time permits.

we all like the smell of legacy programs and source code :)
can you try to find the source of all your tools and upload them here - we all love to archive, understand and port your stuff

Title: Re: Opponent's path
Post by: Cas on May 31, 2021, 09:32:43 PM
Mark Nailwood!  The legend! :D  It's great to see you're here. It definitely would be an honour to race with you!

I've been making a couple of tools for Stunts and yours have totally served as inspiration. I miss the times when programming was all real mode DOS. No dependencies, no hassle. At the same time, it was more challenging in many aspects, but it was great to go for that challenge!
Title: Re: Opponent's path
Post by: Mark Nailwood on June 01, 2021, 10:12:25 AM
Good news: I found the source code of my tools. :)  Where would be the best place in this forum to post it?

I also managed to install DOSBox and Stunts on my Win10 laptop and also found the DOSBox settings to improve the game performance (it feels somehow laggy with the default settings). Then I did some test runs on the Default track to check my remaining racing skills after 20 years of retirement. Current times: 1:07.60 on the right track and 1:09:95 on the left (Indy, of course). ::)
Well, don't expect me to get close to my performance of the good old days, but I'm sure it will be fun to compete again. :D
Title: Re: Opponent's path
Post by: llm on June 01, 2021, 03:00:31 PM
make a new post in the "Stunts Related Programs" forum, just describe what it is an attach it
or make a github project where others can contribute
Title: Re: Opponent's path
Post by: Cas on June 01, 2021, 10:41:31 PM
Yes, the forum is good :)
Title: Re: Opponent's path
Post by: Duplode on June 02, 2021, 02:25:45 AM
Welcome back, Mark Nailwood; it's fantastic to see you here! Thanks a lot for those tools, of which I, like many of us, have been a happy user for so many years  :)