Skip to content

Instantly share code, notes, and snippets.

@skeeto
Last active December 20, 2021 14:00
Show Gist options
  • Save skeeto/da7b2ac95730aa767c8faf8ec309815c to your computer and use it in GitHub Desktop.
Save skeeto/da7b2ac95730aa767c8faf8ec309815c to your computer and use it in GitHub Desktop.
AI driving simulation
@hashemi
Copy link

hashemi commented Feb 5, 2021

Thanks @Kaligule! I'd figured that s likely means scale but didn't realize that the map and final PPM had different dimensions, that clarifies why the code works on the given example.

I guess the code only works correctly if s (scale between map and final ppm) was 2 or more, otherwise vehicles won't get drawn.

Have you considered publishing your rust implementation? I'd love to read it to see how you decided to organize your code. I'm trying to stay as close to C at first but have plans for reorganizing it to be more idiomatic Swift.

@Kaligule
Copy link

Kaligule commented Feb 5, 2021

@hashemi I am a bit hesitant to publish it, because it is a learning project - I am still new to rust and this code is not much prettier then the original (though I gave my best when naming the variables). But I guess there is no shame in learning and not being perfekt. I'd be glad to hear feedback.

Here is the repo.

@Kaligule
Copy link

Kaligule commented Feb 6, 2021

@hashemi I just added the scaling to my implementation (I had just not used the overlay until now, instead I drew onto the collision map). It was interesting and I definitelly had to iterate over it multiple times.

My bigest realization was that it is not enough to just adjust the position of every car pixel. That would spread out the cars pixels over a bigger area, making it less dense. The scale really has to get into the car length and car width before you iteratate over them.

Your problem persists, of course. I decided to make the cars thicker in my simulation, so this is not as big of an issue anymore.

@hashemi
Copy link

hashemi commented Feb 8, 2021

I realized if you don't specify an overlay image file, the code will just create a blank PPM file that is 12 times larger than the map.

@hashemi
Copy link

hashemi commented Feb 9, 2021

In case someone is interested, I just made my Swift port public.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment