[Community Puzzle] Let's make a cheap ASCII 3D engine!

https://www.codingame.com/training/hard/lets-make-a-cheap-ascii-3d-engine

Send your feedback or ask for help here!

Created by @pardouin,validated by @tutubalin,@DaNinja and @rozbrajaczpoziomow.
If you have any issues, feel free to ping them.

Great puzzle, clear statement, once again I learned something new… Maybe a bit more test cases wouldn’t have hurt.
With my newly acquired skill, I think I will rewrite Castle Wolfenstein and make big bucks with it! :slight_smile:

2 Likes

I think the second note inviting to do the same with a better resolution is a very good thing here. Don’t limit to what is asked, explore further!

1 Like

Hello,
I pass all the tests in the IDE but when I submit my results, the first three validators fail. Only le last one pass.
How can I find the differences between validators to debug ?
thanks

The first validator is:

130 570 0
7
#######
#..#..#
#..#.##
#.....#
#...###
#.....#
#######

Expected output:

                                      .......................
,,,,,,,,,,,,,,,,                     ........................
,,,,,,,,,,,,,,,,...                 .........................
,,,,,,,,,,,,,,,,.....              ..........................
,,,,,,,,,,,,,,,,......,,,,,,,,,,,,...........................
,,,,,,,,,,,,,,,,......,,,,,,,,,,,,...........................
,,,,,,,,,,,,,,,,......,,,,,,,,,,,,...........................
,,,,,,,,,,,,,,,,......,,,,,,,,,,,,...........................
,,,,,,,,,,,,,,,,......,,,,,,,,,,,,...........................
,,,,,,,,,,,,,,,,......,,,,,,,,,,,,...........................
,,,,,,,,,,,,,,,,......,,,,,,,,,,,,...........................
,,,,,,,,,,,,,,,,.....              ..........................
,,,,,,,,,,,,,,,,...                 .........................
,,,,,,,,,,,,,,,,                     ........................
                                      .......................

Once you understand your bug, thell us here what it was. It’s always interesting to know.

Thanks, I figured out.
I used 3.14 insted of Math.PI, so the result of my calculation wasn’t precise enough… Not very smart.

2 Likes

Hi thanks for giving us the first validator I was stuck with all the IDE tests passing as well.
However I’m still facing difficulties matching your expected output. I don’t seem to have the right result on ray 19 (angle -12 degrees).
I find {462,499}, -12.001 degrees, D’= 334, H= 4.4910 rounded to 4
Looks like you have a H of 5 on that angle. I clearly have the wrong point but it is the one closer to -12 degrees I can find.
Do you mind sending the stringified array of the points of collision for each ray or just the one I am facing issues with?

Ok here’s full log for validator 1, angle -12 degrees:

check for closest h-wall ; potential collisions:
459.3241076634918, 500 -> h-wall
dist: 336.68140413208914

check for closest v-wall ; potential collisions:
200, 555.1210406830985 -> no wall behind
300, 533.8653845160962 -> no wall behind
400, 512.609728349094 -> no wall behind
500, 491.3540721820918 -> v-wall
dist: 378.2660201000608

d = best of 2: 336.68140413208914
d' = 329.3241076634918
h = 4.554783464357617

Your process for detection collision seems too imprecise, you shouldn’t have a coordinate of 499, you’re supposed to check the exact point of collision, so in this case your y should be exactly 500 (and don’t round the x value if not asked, keep it a float until the end).

1 Like

Thanks for the reply.
Turns out my way of solving the problem with a [Nx100][Nx100] matrix was not optimal nor practical.
I managed to make it work though but I am rewriting a more effective algorithm. And while doing so I once again stumble on a issue…
This time on the 3rd IDE test.
Camera coordinates are {1850, 1750}, angle is 180.
On ray -13 degrees from A, my collision occur on {1200,1900} which is told not to be possible on the exercice description.
Distance on Y axis from the wall is 150, we have X axis distance = 150/tan(13) = 649.72 rounded to 650. {1850-650, 1750+150} = {1200,1900}
What am I missing there?
Thanks for your kind help

You’re not supposed to round to 650.
So the collision doesn’t happen exactly on the corner and it’s enough to tell if it’s a h-wall or v-wall.

A real undecidable case would be for example a ray of 45 degree with a camera placed in the center of a tile. It would collide exactly on a corner.

Here is the full log for IDE test 3, ray -13 (167 degrees):

check for closest h-wall ; potential collisions:
1633.4262062857924, 1800 -> no wall behind
1200.2786188573773, 1900 -> h-wall
dist: 666.8117223878695

check for clostest v-wall ; potential collisions:
1800, 1761.5434095562782 -> no wall behind
1700, 1784.6302286688347 -> no wall behind
1600, 1807.717047781391 -> no wall behind
1500, 1830.8038668939475 -> no wall behind
1400, 1853.890686006504 -> no wall behind
1300, 1876.9775051190604 -> no wall behind
1200, 1900.0643242316169 -> v-wall
dist: 667.0976700657047

d = best of 2: 666.8117223878695
d' = 649.7213811426227
h = 2.308681911255633

OK my ray casting method was very sub optimal. I now check the presence of a wall only when my ray cross a %100=0 X or Y and I have the precise point of collision for an accurate D’.
Thanks again for your help

Hey new here, any way to view the solution ?

If you have solved it, you can check some other people’s solution.
If you haven’t solved it, it is not possible. if you are stuck, you can ask for specific hints (but not complete solution code) here or on Discord. When asking for help, pls describe (in algorithmic terms, not with code excerpt) what you have tried so far or what specific help do you need.

How is this only worth 50xp, yet I solved a 350xp with half the effort?

1 Like

All community puzzles are only 50 xp