r/ProgrammerHumor • • Jun 10 '23

[deleted by user]

[removed]

12k Upvotes

615 comments sorted by

View all comments

1.6k

u/[deleted] Jun 10 '23

First CS semester, we had to build an Othello player, then we were pitched against each other. Out of 50 students, more or less half implemented the standard algorithm and the other half implemented much more sophisticated stuff. The winner was one of the standard implementations.

719

u/Hubcat_ Jun 10 '23 edited Jun 10 '23

I had a similar experience, where in a CS class (also first semester) we needed to program AI for a little tank thing in assembly and have it navigate mazes using distance info from three sensors. There was a race where first place got an auto-100 in the assignment, and me and my partner's tank won with the simple wall follow algorithm that was explained to us at the beginning of the assignment

304

u/hideoutdoor Jun 10 '23

Wouldn't have worked if the maze exit was in the middle

293

u/Hubcat_ Jun 10 '23

Yea, but we were given the list of restrictions on the maze, it being on the edges was one of them

247

u/BlurredSight Jun 10 '23

Funny how they changed the structure of actual bot maze running competitions after one guy just had the bot follow the right wall and beat all the teams doing complex processing.

185

u/Surface_Detail Jun 10 '23

I mean, that's a known technique for exploring mazes. Unless it's spread over three dimensions and incorporates a drop, it will get you there.

Reliability > Speed

59

u/AnsonKindred Jun 10 '23

I believe it's enough to have loops around either the starting location or the exit, no 3d required.

55

u/Surface_Detail Jun 10 '23

A loop around it means it's not an exit, it's a goal. An exit needs to be a breach in an external wall.

→ More replies (7)
→ More replies (14)
→ More replies (2)

51

u/Giocri Jun 10 '23

I actually made a very basic way to address that a few years ago for a similar competition, the bot would keep a an extremely basic map of the labirinth and basically upon completing a loop it would create a virtual wall so it could keep exploring the rest without being stuck in a loop

32

u/katiecharm Jun 10 '23

Ahh that’s clever. Essentially, if the bots location ever repeats, next intersection, create a fake wall down the path you’ve tried before. I wonder if that has any weaknesses….

26

u/Giocri Jun 10 '23

Well it takes a bit of caution in how you mark where you have already been, my original version was extremely basic and really bad at distinguishing between backtracking and loops but it should be relatively easy to make it work reliably

37

u/MrMonday11235 Jun 10 '23

but it should be relatively easy to make it work reliably

Haunting photos taken seconds before disaster

12

u/OtherPlayers Jun 10 '23

It sounds a bit like Trémaux's Algorithm to me.

That algorithm does solve most simple wall follower issues (by essentially converting complex mazes into simply connected ones over time), though IIRC it still fails on large open spaces like a standard wall follower would.

Also another penalty is that now you need a variable amount of memory based on the size of the maze, compared to a pure algorithmic approach that can operate with a fixed amount.

→ More replies (1)
→ More replies (2)
→ More replies (2)

72

u/[deleted] Jun 10 '23

What would the alternatives be? "Follow the wall" is the actual strategy I use when I'm in a hedge maze or video game dungeon and need to make sure I find the exit and avoid circles

45

u/Hubcat_ Jun 10 '23

Not really certain, that's part of why we did the wall follow lol. I guess you could do some fancy stuff to try and detect when the wall has divets and cut across them, but that would be hard to pull off. Some students did try fancy stuff, but most of them just got stuck in a loop or hit the walls. The only things we did were adjust the numbers to turn as fast and tightly as possible, and added a goldilocks zone where the car would go full speed if the wall was in a certain range

22

u/[deleted] Jun 10 '23

Yeah I think if your sensors have sufficient range and precision you could try to spot the exit ahead of time and be able to skip some turns, or if it were an all-or-nothing competition you could try gambling on randomly skipping a couple turns in the hope you'll luck onto a faster path, but otherwise "follow the wall" is the best strategy

15

u/Hubcat_ Jun 10 '23

The mazes were really simple, they were more enclosures with random walls in the middle than anything else, so skipping turns wasn't really necessary since there weren't really "turns", just the walls going in slightly different directions. That's part of why the wall follow was so viable, because the walls were usually just a jagged path straight to the end. There were a lot of concessions that needed to be made since it was first semester students coding assembly for an actual object that needed to navigate around. It was still a fun project though

→ More replies (1)
→ More replies (1)

19

u/other_usernames_gone Jun 10 '23

Pledge algorithm also works.

Pick a direction (helps if it's the rough direction of the exit) and "pledge" to always go in that direction when possible.

When you hit a wall hug it and follow it round but disconnect when you're facing in your pledged direction(and the sum of angles turned is a multiple of 360).

It stops you getting trapped in a disconnected segment in the middle of the maze.

A Wikipedia article full of maze solving algorithms

→ More replies (1)

29

u/chrisnolet Jun 10 '23

Relevant: https://youtu.be/ZMQbHMgK2rw?t=339

The Micromouse competition tackles this, (and many other cool challenges as part of having robots complete a maze as quickly as possible)!

→ More replies (6)
→ More replies (11)

72

u/BlurredSight Jun 10 '23

Honestly my CS teacher said in life 90% of the time you'll enter a workplace where they have private optimized algorithms made for you already or the standard algorithm library in C++ is more than competent enough.

95

u/rhododenendron Jun 10 '23

Standard libraries are made by people much smarter than the average dev and if they aren’t, lots of other devs have probably had the chance to look at it and optimize it. Normally you won’t be able to do any better on your own, because if you could whatever you came up with would probably be the standard. Obviously there are exceptions.

34

u/Giocri Jun 10 '23

Yeah generally nonstandard implementations prove good only with nonstandard problems and nonstandard applications are surprisingly rare

14

u/HeadintheSand69 Jun 10 '23

There is probably a paper behind each algorithm implemented in popular libraries.

→ More replies (1)

48

u/[deleted] Jun 10 '23

My "algorithm" for Othello which used a hardcoded matrix to rank every square of the board, using a ranking from a paper, went second place. Only behind a neural network trained for quite some time. It even surpassed all the other neural networks.

→ More replies (2)
→ More replies (16)