<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Placeholder</title>
    <description>Super duper blog about suffs
</description>
    <link>http://lapinozz.github.io/</link>
    <atom:link href="http://lapinozz.github.io/feed.xml" rel="self" type="application/rss+xml"/>
    <pubDate>Thu, 15 May 2025 01:00:30 -0400</pubDate>
    <lastBuildDate>Thu, 15 May 2025 01:00:30 -0400</lastBuildDate>
    <generator>Jekyll v3.10.0</generator>
    
      <item>
        <title>Joltron, a very shocking game</title>
        <description>&lt;h1 id=&quot;the-concept&quot;&gt;The Concept&lt;/h1&gt;

&lt;p&gt;I don&apos;t remember how I stumbled on it, but there&apos;s a party game where 4 players each hold a little handle with a button on it, there&apos;s a music playing, when the music stops the last player to press the button gets a shock. As soon as I saw that game I knew I had to make my own version.&lt;/p&gt;

&lt;h1 id=&quot;the-shock&quot;&gt;The Shock&lt;/h1&gt;

&lt;p&gt;I immediately thought of the cheap high-voltage modules you can get on AliExpress/Amazon. I had briefly experimented with them in the past and it seemed like I had finally found a &quot;practical&quot; application for them. They usually take in 3 to 6 volts and are often advertised with an output of 400Kv or something ridiculous like that, they actually output in the range of 10Kv to 20Kv. That&apos;s still enough to produce electric arc a couple of centimeters long. That might sound scary but the current is very low and depending on the specific module the shock can range from a little pinch to a full arm numbness.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/joltron/hv-module.png&quot; alt=&quot;image&quot; style=&quot;max-height:500px&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;the-games&quot;&gt;The Game(s)&lt;/h1&gt;

&lt;p&gt;At this point I knew I wanted to have a similar reaction-time game, but I also wanted more, I was looking for way to push the concept further. The idea that came to me was to make different minigames the players could compete in. The first game that would fit the format that came to my mind was the good old classic pong!&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/joltron/pong.webp&quot; alt=&quot;image&quot; style=&quot;max-height:500px&quot; /&gt;&lt;/p&gt;

&lt;p&gt;I also had a couple of little 128x64 OLED display that I really wanted to use. I planned to use at least one for menu screen but I was also looking very hard for an excuse to give one screen to each player. After much thinking I came up with a concept that did require players to have their own individual screens, a social game of voting and betrayal! Each player would vote for someone, the person with the most votes would loose and get the shock, &lt;em&gt;unless&lt;/em&gt; they got all the votes, in that case the other players would get the shock.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/joltron/menu.png&quot; alt=&quot;image&quot; style=&quot;max-height:500px&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The fourth game is a more complicated version of the reaction game, where player have to wait for multiple &quot;conditions&quot; to be fulfilled, the conditions being if the song is playing or not, how many leds of a certain color there is and how many of a certain shape there is on the main screen.&lt;/p&gt;

&lt;h1 id=&quot;the-electronics&quot;&gt;The Electronics&lt;/h1&gt;

&lt;p&gt;As usual, I reached for the trusty Arduino Nano which is cheap and compact to be the brain of this project.&lt;br /&gt;
The 5 lcd screens are connected via I2C but they all share the same address so I connected them to a TCA9548A multi-channel expansion board which lets me enable or disable channels from code. This way I can control which screen I&apos;m sending data to, or even send the same data to multiple screens at the same time.&lt;br /&gt;
For playing music and sounds I selected a DFPlayer Mini, it&apos;s a little board with a MicroSD card slot that can play MP3 and be controlled from code.
If I remember correctly, the speaker was scavenged from an old laptop.
The whole thing is powered from a single 18650 lithium battery and a tp4056 charge/discharge board plus a XL6009 step-up booster to raise the voltage to 5V.
There&apos;s also 3 push buttons on top to go through the menus and 10 addressable LEDs around them.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/joltron/inside2.png&quot; alt=&quot;image&quot; style=&quot;max-height:500px&quot; /&gt;
&lt;img src=&quot;/assets/image/joltron/inside.png&quot; alt=&quot;image&quot; style=&quot;max-height:500px&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The original plan was to have a single high voltage module and to physically switch which remote it was connected to by rotating a servo with a series of connector. But that would probably have been unreliable, fragile and bulky. Instead I opted to put a taser module in each handle. That made more sense than trying to route 20kv inside the body of the game and through long wires.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/joltron/handle.png&quot; alt=&quot;image&quot; style=&quot;max-height:500px&quot; /&gt;
&lt;img src=&quot;/assets/image/joltron/handle2.png&quot; alt=&quot;image&quot; style=&quot;max-height:500px&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The handles are made with a simple push button on the top, aluminum foils glued to pieces that come out on each side and connects to the high voltage module. These are large to ensure you will always make contact with both sides when you hold the handle, ensure you do get shocked if you lose. They connect to the body of the game through audio jacks so that if someone pulls their arm in surprise the handle can easily disconnect rather than tear or break the wires.&lt;/p&gt;

&lt;h1 id=&quot;the-interference&quot;&gt;The Interference&lt;/h1&gt;

&lt;p&gt;I tested multiple times to make sure the mosfets I selected could trigger and the high voltage modules and hat I could control them from the arduino, everything seemed to worked perfectly. But once I assembled it into a handle, every time I tried to trigger an arc from the code, the Arduino would just crash or freeze. At first I thought the modules were pulling too much current or injected noise on the ground or power rails but adding capacitors didn&apos;t seem to help. I then tried to inspect the circuit at various points using my oscilloscope but I couldn&apos;t find any voltage peak or drop like I would have expected. I thought maybe since it produced electric arcs multiple centimeters long there might have been enough EM radiation to mess with the microcontroller, but no amount of shielding or keeping it far from the arc solved the problem.&lt;/p&gt;

&lt;p&gt;In the end it turned out to be current induced into the wires for the button, which were running right next to the arc. The fix was simple, I just twisted that wire pair and the problem went away!&lt;/p&gt;

&lt;h1 id=&quot;the-playing&quot;&gt;The Playing&lt;/h1&gt;

&lt;p&gt;The game turned out great, knowing you might get a shock if you lose really raises the stakes even if the games are relatively simple. The game also keeps track of each player&apos;s score and displays a scoreboard in between each game.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/joltron/scoreboard.png&quot; alt=&quot;image&quot; style=&quot;max-height:500px&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Convincing people to play is not always easy, especially after they hear the crackling of an electric arc, which can be quite loud! But in the end it&apos;s more scary than dangerous and when they do endup getting a shock people are generally relieved that it&apos;s not too bad and willing to continue playing. Although some people have higher or lower skin resistance and that means you can have one person that barely feels anything when they get the shock playing against someone that gets a more significant jolt, not the most fair situation but still a lot of fun!&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/joltron/joltron.png&quot; alt=&quot;image&quot; style=&quot;max-height:500px&quot; /&gt;
&lt;img src=&quot;/assets/image/joltron/playing.webp&quot; alt=&quot;image&quot; style=&quot;max-height:500px&quot; /&gt;&lt;/p&gt;
</description>
        <pubDate>Wed, 14 May 2025 10:43:32 -0400</pubDate>
        <link>http://lapinozz.github.io/project/2025/05/14/joltron.html</link>
        <guid isPermaLink="true">http://lapinozz.github.io/project/2025/05/14/joltron.html</guid>
        
        <category>Electronics</category>
        
        <category>Arduino</category>
        
        <category>C++</category>
        
        <category>3D Printing</category>
        
        <category>CAD</category>
        
        
        <category>project</category>
        
      </item>
    
      <item>
        <title>Overengineered Automatic Cat Feeder</title>
        <description>&lt;h1 id=&quot;the-monsters&quot;&gt;The Monsters&lt;/h1&gt;

&lt;p&gt;Two little perfect black balls of hair have elected domicile in my home. They are lovely, cuddly and HUNGRY!&lt;br /&gt;
When 6h AM rings, they come screaming and scratching at the door. Because I value my sleep and because I love adding to my pile of unfinished projects, I decided to make them an automatic cat feeder. Little did I know it would take me years to complete it.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/catFeeder/monsters.png&quot; alt=&quot;image&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;the-idea&quot;&gt;The Idea&lt;/h1&gt;

&lt;p&gt;I had a few requirements, I wanted the machine to be:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;reliable&lt;br /&gt;
The most important thing is that it works, and that it works consistently.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;safe&lt;br /&gt;
If it doesn&apos;t work, I should be alerted one way or another.&lt;br /&gt;
Can&apos;t let the poor kittens starve because something malfunctioned.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;configurable&lt;br /&gt;
If I need to change at which hour they get fed or how much to feed them, I don&apos;t want to be required to reprogram the device, there should be some sort of interface.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;perennial&lt;br /&gt;
Ideally the reservoir should be big enough so that I can put at least a month worth of food. I want to just fill it and forget about it.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At the time we had a little litter box furniture, with an empty spot of the same size next to it. I thought it would be perfect to make my machine of the same size. I had been looking for an excuse to use an ESP32 with a camera for a while, this was the perfect opportunity. So the plan at that point was:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;A big wood box for the structure and the reservoir&lt;/li&gt;
  &lt;li&gt;An ESP32 with a cam module, so I can spy on the little creatures&lt;/li&gt;
  &lt;li&gt;A webserver running on the ESP for the configuration interface and view the video feed&lt;/li&gt;
  &lt;li&gt;An Arduino Nano for handling controlling the electronics&lt;/li&gt;
  &lt;li&gt;Some sort of mechanism that can measure and dispense the food&lt;/li&gt;
  &lt;li&gt;Some sensor to detect if the food was actually dispensed&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The reason I decided to use an Arduino in addition to the ESP is that the location I wanted to put the camera in was a bit far from where the rest of the electronics would be. Also, the ESP32-CAM board I had had a limited number of GPIO available and they can only provide 3.3V. Most of the parts I already had required 5V.&lt;/p&gt;

&lt;h1 id=&quot;the-structure&quot;&gt;The Structure&lt;/h1&gt;

&lt;p&gt;One of the first thing I designed is the box. I took the dimension of the litter box furniture then guesstimated the width and height that would be needed for the electronics and dispenser parts. Leading to that compartment I added a 30 degree slope and that was basically it.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/catFeeder/Structure.png&quot; alt=&quot;image&quot; style=&quot;max-height:500px&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Once I had all the dimension it was a matter of laying out all the different rectangles together to see which size of plywood I needed to buy.
I cut up the plywood with a circular saw and joined them with pocket holes. It was my first time trying pocket holes and I have to say, they are AWESOME.&lt;/p&gt;

&lt;p&gt;It&apos;s basically a guide you clamp on the edge of a board, you adjust it for the width of your wood and when you drill with the special bit it makes a hole of the perfect angle and depth to screw into an adjacent board. It&apos;s super easy and quick to use and I couldn&apos;t be happier with the result, the box is super sturdy and rigid!&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/catFeeder/pockethole.png&quot; alt=&quot;image&quot; style=&quot;max-height:500px&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The structure&apos;s finishing touches were a coat of primer and white cabinet paint. I also added hinge for the top lid as well as a chest latch, to prevent the little devils from opening the lid and eating all the food.&lt;/p&gt;

&lt;p&gt;The front access panel was originally on a hinge too but I later switched it to being screwed, it was easier to get right and it makes the inside much more accessible, which is nice for an access panel.&lt;/p&gt;

&lt;h1 id=&quot;the-first-prototype&quot;&gt;The First Prototype&lt;/h1&gt;

&lt;p&gt;During a failed attempt at making an automatic kombucha machine (automate all the things!) I designed an auger in &lt;a href=&quot;https://openscad.org/&quot;&gt;OpenSCAD&lt;/a&gt;. OpenSCAD is a script-based CAD program and it&apos;s super fun, I&apos;ll probably make a blog post on that subject at some point. Anyways, the auger was fully parametric and powered by a 28byj-48 stepper motor. It seemed like a perfect fit for this project!&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/catFeeder/auger.png&quot; alt=&quot;image&quot; style=&quot;max-height:500px&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The issue is that that stepper motor isn&apos;t particularly strong. I found both the speed and the torque to be pretty low, even when overpowering it a bit. It took quite a while but after many iterations I figured out the right parameter of size, taper and angle for the auger to dispense food without getting stuck all the time. It was still very slow and tended to get stuck, but I was stuck too and it was time to move on to the next part.&lt;/p&gt;

&lt;p&gt;My idea was to use a weight sensor to measure how much food to dispense. I designed a box with two compartment and the bottom of it swivels on an axis, a string was attached to the plate and connected to a wheel on a servo motor, turning the wheel pulls on the string, closing the bottom. The wire was routed over a weight sensor, so that the weight of the food on the plate would be applied on the sensor and it could be used to measure the amount of food in the compartments. In addition there&apos;s a &quot;selector&quot; tunnel, also on a servo motor, to control which compartment the food goes in, allowing the machine to dispense an equal amount of food into two bowls.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/catFeeder/distributorv1.png&quot; alt=&quot;image&quot; style=&quot;max-height:500px&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Most of it was working fine, the servo was able to rotate the wheel to open and close the bottom, the other servo rotated the selector to channel the food to one chamber or the other. The weight sensor &lt;em&gt;mostly&lt;/em&gt; worked, the issue is that I was getting very inconsistent issue, the same amount of food would give me a different weight. I think the issue was due to the string not sliding perfectly in the channel and the friction between the food and the wall of the chambers. The weight sensor worked correctly outside of the machine so it was down to mechanical issues.&lt;/p&gt;

&lt;p&gt;I tried different strings but I couldn&apos;t manage to get good results. Then I realized that design was quite tall and wouldn&apos;t fit very well inside the structure. It was time for a new prototype!&lt;/p&gt;

&lt;h1 id=&quot;the-second-prototype&quot;&gt;The Second Prototype&lt;/h1&gt;

&lt;p&gt;After reviewing how others have achieved this task, and trying to inspire myself from what I&apos;ve learned in solving the auger&apos;s constant jamming issues, I went for a design with a wheel on a vertical axis, with long paddles that divide the body into chambers, an access to fill those chamber from the top on one side and a hole to dispense from the bottom on the opposite side.&lt;/p&gt;

&lt;p&gt;And it worked very well! No jamming no nothin&apos;! It helped that I used one of those classic 5V DC motor with a little gearbox, like those you can find in toys, they have much more torque than the stepper I tried to use previously.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/catFeeder/Dispenser-V1-1.png&quot; alt=&quot;image&quot; style=&quot;max-height:500px&quot; /&gt;&lt;/p&gt;

&lt;p&gt;To keep track of the position of the wheel I used an infrared optical encoder, it simply gives you a signal depending on if something is between two black leg or not. I printed an encoder wheel that attached to the motor and voila! At the beginning I had issues with the inconsistent signals from the encoder, I tried to make the &quot;teeth&quot; of the wheel wider and wider until I realized it was simply too transparent, after giving it a couple coats of black sharpie it worked perfectly.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/catFeeder/Encoder.png&quot; alt=&quot;image&quot; style=&quot;max-height:500px&quot; /&gt;&lt;/p&gt;

&lt;p&gt;To save space I replaced the previous top part with a big funnel, printed in two part so it can fit on my printer. I printed a second part that goes on the bottom that holds the motor and the encoder, it also has two holes, one for a 5v laser and one for a photoresitor. The idea is that when the food falls through the chute it&apos;ll break the laser line and the microcontroller can monitor the photoreistor&apos;s value to detect if food was actually dispensed or not.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/catFeeder/Dispenser-V1-2.png&quot; alt=&quot;image&quot; style=&quot;max-height:500px&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The first tunnel I designed were absolutely &lt;em&gt;terrible&lt;/em&gt;, round angled shapes are not easy to interface with in CAD, they took a lot of operations to get right, Fusion360 wasn&apos;t very happy with me by the end of it. The angle was too shallow, food wouldn&apos;t slide nicely and would even get stuck at the &quot;fork&quot; between the two sides.&lt;/p&gt;

&lt;p&gt;The second one was &lt;em&gt;much&lt;/em&gt; better, the rectangle tunnels were very easy to work with and in the end turned out to be more optimal. I managed to get a steeper angle by rotating the whole mechanism 180 so that the output is already falling on the side where the food needs to exit and by optimizing the funnel and other parts to gain some height to work with.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/catFeeder/tunnels-vs.png&quot; alt=&quot;image&quot; style=&quot;max-height:500px&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;the-disruption&quot;&gt;The Disruption&lt;/h1&gt;

&lt;p&gt;At this point I had every parts working together pretty well, including the electronics but I&apos;ll touch on that further down. But I had been working on this project on and off for quite some time, so much time in fact that the requirements changed. That&apos;s right, because of life circumstances we had to take in a family member&apos;s cat. The problem is, this machine was designed for &lt;em&gt;two&lt;/em&gt; cats, not &lt;em&gt;three&lt;/em&gt;…&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/catFeeder/disrupter.png&quot; alt=&quot;image&quot; style=&quot;max-height:500px&quot; /&gt;&lt;/p&gt;

&lt;p&gt;No time to despair, we can do it, there must be a way to make it work for three cats. I figured I could just add another tunnel in the middle, and go back to a rotating &quot;selector&quot; to fill them one by one. I decided to with the an active method to split the food instead of a passive one because even with just two tunnels it had a tendency to fill one more than the other, because the dispenser rotates so the food doesn&apos;t fall equally on both sides. I didn&apos;t feel like printing a thousand prototypes to figure out exactly the geometry required to have a fair three-way split.&lt;/p&gt;

&lt;p&gt;And who would have thought, it was actually not too hard to modify the design. It was just a matter of &quot;extending&quot; one of the tunnels past the split and cut it to create the &quot;selector&quot; and adding a third tunnel that matches with the position of said selector when it&apos;s rotated midway.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/catFeeder/tunnel-3.png&quot; alt=&quot;image&quot; style=&quot;max-height:500px&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Then it&apos;s just a matter of attaching the tunnels to the rest of the machine, with the brace showed here in red. One of the reason the whole CAD file looks like Frankenstein&apos;s monster is because I designed the part one at a time, not always knowing what the next part would look like, so the later parts sometimes need to get a bit creative to fit with the previous ones without having to reprint everything.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/catFeeder/tunnel-brace.png&quot; alt=&quot;image&quot; style=&quot;max-height:500px&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;the-electronics&quot;&gt;The Electronics&lt;/h1&gt;

&lt;p&gt;With the hardware all taken care of let&apos;s take a look at how everything gets controlled. I have an Arduino Nano (or a clone of it anyways) to control the dispensing motor, the servo and read the sensors. To control the motor it uses a double-H bridge. There&apos;s a couple of resistance to read the photresistors. This board doesn&apos;t have much more on it, just bunch of connectors and a USB cable to connect to the ESP32. As always, I just mount everything on some perfboard and add wires until everything is connected as it should.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/catFeeder/arduino-board.png&quot; alt=&quot;image&quot; style=&quot;max-height:500px&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The ESP32 board isn&apos;t much more complex, it&apos;s just some headers for the chip, another USB connector and a JST header for programming the chip.&lt;br /&gt;
The JST connector was quite an improvement, before that every time I wanted to reprogram the ESP I had to press the BOOT button then press the reset button. It&apos;s not too annoying if you only have to do it once but when you to do it repeatedly and the board is in an inconvenient location it gets tiring real quick. Luckily I accidentally burned the programmer board that came with the ESP, I had to get a generic programmer and it was a perfect occasion to setup a good workflow where it automatically resets the board into programming mode when uploading code.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/catFeeder/esp32-board.png&quot; alt=&quot;image&quot; style=&quot;max-height:500px&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;the-coding&quot;&gt;The Coding&lt;/h1&gt;

&lt;p&gt;On the Arduino side the code is pretty simple, it waits for commands on the serial port, execute them and outputs a response. For dispensing it rotates the motor and reads the encoder with a bunch of timers and debouncing to make sure it actually rotated correctly. There&apos;s a pin change interrupt to read the chute laser sensor. The three failure modes are if the motor gets stuck, if the laser fence is not triggered or if the laser path is broken before it starts rotating the motor, as that would mean food is stuck in the chute. After dispensing it outputs the results, either the error code or success, back to the serial.&lt;/p&gt;

&lt;p&gt;There&apos;s a lot more business happening on the ESP32. Here&apos;s a little list of the things it handles.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Monitoring the time and triggering dispensing events&lt;/li&gt;
  &lt;li&gt;Communication with the Arduino&lt;/li&gt;
  &lt;li&gt;Serving the Interface&apos;s webserver&lt;/li&gt;
  &lt;li&gt;Handling communication on the WebSockets&lt;/li&gt;
  &lt;li&gt;Streaming the camera&lt;/li&gt;
  &lt;li&gt;Sending a Discord and Pushover notification after dispensing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The websocket&apos;s server is registered under a path that contains a password so you can&apos;t only see the camera that&apos;s streamed over WS or change the settings if you have the password. eg: ws://website.com/ws/PASSWORD_HERE&lt;/p&gt;

&lt;p&gt;For Discord notification I use the webhook feature, super simple and easy. I also added Pushover notifications, which is an app you install on your phone and it gives you push notifications, the advantage is that the push notification could include an image at the time, it doesn&apos;t seem to work anymore so that part is a bit useless for me.&lt;/p&gt;

&lt;p&gt;When the ESP32 boots up it tries to connect to the last wifi config. If it hasn&apos;t managed to connect after 30 seconds, it starts its own wifi access point, from which you can access the Interface and make it connect to one of the available wifis.&lt;/p&gt;

&lt;h1 id=&quot;the-interface&quot;&gt;The Interface&lt;/h1&gt;

&lt;p&gt;The Interface is a website in HTML, JS and SCSS. It gets built into minimized files using webpack, the hot-reload feature is also useful for development. There&apos;s one box for the last camera capture, one for the live camera stream, an area to set the actual dispensing settings, time and amount. There&apos;s also a button to get a list of available wifis and connect to one of them. The console logs all the commands that gets sent and received on the websocket and let you manually send commands. The field above the console is for putting the access password, without it nothing is accessible except the camera capture box. It uses JS localStorage to save the password so you don&apos;t need to enter it every time. I also made sure the website is responsive on mobile, as that&apos;s probably how I&apos;ll access it most of the time.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/catFeeder/interface.png&quot; alt=&quot;image&quot; style=&quot;max-height:500px&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;the-sharing&quot;&gt;The Sharing&lt;/h1&gt;

&lt;p&gt;At this point there&apos;s basically three different programs that need to talk to each others, the Arduino, the ESP32 and the Interface. To help them understand each other I listed the shared constants and enums in a JSON file and made a JS script that I can execute using NodeJs (which I&apos;m already using to build the Interface). The script generates a C++ header files with all the constants populates as well as a new JSON file with the new values. It then copies those files to each project&apos;s folder. Now each project can include either the header (for Arduino and ESP) or the JSON (for the Interface) so that they always use the same values for commands and share the same constants!&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot; data-lang=&quot;json&quot;&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;commands&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;ESP&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Capture&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Dispense&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;SetDispensingSetting&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;SaveDispensingSettings&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;WifiList&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;WifiStatus&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;WifiConnect&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Temperature&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;ARD&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Dispense&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Reservoir&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;

  &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;enums&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;DispensingResult&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Started&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Ok&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;NoOutput&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;PaddleStuck&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;FoodJammed&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;

  &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;constants&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;DispensingEventMax&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;PositionCount&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h1 id=&quot;the-heating&quot;&gt;The Heating&lt;/h1&gt;

&lt;p&gt;So everything is finally working, everything is perfect, now you just make a little cover for the ESP32 to protect it and hold the camera in place, what could go wrong?&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/catFeeder/camera-cover.png&quot; alt=&quot;image&quot; style=&quot;max-height:500px&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Somehow putting the cover on massively decrease performance, until the chip disconnect from wifi and is unreachable. Uh what&apos;s going on now…&lt;/p&gt;

&lt;p&gt;Turns out the chip was overheating and it only started happening after I trapped it inside a thick-walled enclosure. I tried drilling a bunch of holes in the box but that didn&apos;t help. I then spent a considerable amount of time trying different power settings in the hope of reducing the heat dissipated but nothing help. I finally reluctantly resigned myself to putting a fan inside the case, I already had a fan of the right size but I wasn&apos;t too happy because I knew it would end up noisy. Still, I was out of options so I printed the new case with a spot for the fan and some holes for the exhaust. And… it worked! The chip was cooler than ever! Yet I was not satisfied, as predicted the fan made noise, and so I pushed a little bit farther, that&apos;s when it hit me! The problem was the camera! After measuring the current draw when I don&apos;t initialize the camera module at all I realized it was pulling more than have the total current for that board. After playing with the settings I managed to find how to turn it off when not in use. No more overheating even without the fan, yay!&lt;/p&gt;

&lt;h1 id=&quot;the-wifi&quot;&gt;The Wifi&lt;/h1&gt;

&lt;p&gt;So everything is finally working, everything is perfect, now you just have to close up the machine and put it in its final place, what could go wrong?&lt;/p&gt;

&lt;p&gt;It seems like everything is working but the web interface is extremely slow and most of the time it can&apos;t connect at all. Uh what&apos;s going on now… Bring the machine back down the stairs, disassemble, debug, find the problem, all over again. This project sure is starting to take a long time, started it what.. hmm.. let me count, 2 years ago?? Alright time to wrap this thing up.&lt;/p&gt;

&lt;p&gt;For some reason it seems the ESP&apos;s wifi connection is really weak, even when really close to the router. What makes it even stranger is that the connetion is bad even with an external camera. Trying with a different ESP32-CAM module gave the same result. Then I realized that the wifi performance was much better when it wasn&apos;t on the machine&apos;s perfboard. Which is strange since there&apos;s almost nothing on that board. After trying all kind of things including dubious methods of shielding, I finally realized that the issue was the UART RX pin coming from the Arduino&apos;s TX. That pin was giving 5V, I never had issue with directly connecting 5V to the esp32 even though it&apos;s supposed to be used with 3.3V but I guess it was messing with RF for the wifi one way or another. That took me a long time to find, but in the end a simple voltage divider solved the problem.&lt;/p&gt;

&lt;h1 id=&quot;the-finishing-touches&quot;&gt;The Finishing Touches&lt;/h1&gt;

&lt;p&gt;The tunnel was drooping lower than it should have been, and that was a problem as they were designed to end just above the low profile stainless bowls I got especially for this project. I should have expected that with all the different 3D printed parts, the flex adds up. After probing a pushing from different places I established that holding it from the back would be the most ideal solution. I quickly designed a little piston, a 3D printed tube with a heat-set insert at the end, a long screw and a cap for that screw that also has a heat-set insert. heat-set insert are awesome and I always forget they are a great option.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/catFeeder/pusher.png&quot; alt=&quot;image&quot; style=&quot;max-height:500px&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Next was covers to put around the tunnels where they come out of the wall. There was no way I was going to cut nice holes of the perfect shape and dimension in the middle of the wood board so I intentionally oversized them and printed covers to hide it.&lt;/p&gt;

&lt;p&gt;The last thing was realizing my cats are very aggressive eater and like to push bowls around when they eat. At firs I thought of putting magnets under them but the bowls are barely magnetic so I would have to glue one set of magnets to the bowls and one to the floor of the machine, a bit cumbersome. Plus magnets near food is stressful since they can be quite a hazard when ingested. I was thinking about crazy solutions like gluing a nut to the bowl and screwing from the bottom when I remember I hold the holy power of 3d printing and can simply print little holders:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/catFeeder/bowls.png&quot; alt=&quot;image&quot; style=&quot;max-height:500px&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;the-result&quot;&gt;The Result&lt;/h1&gt;

&lt;p&gt;After many a trouble and literally years of efforts, I finally made it, the automatic cat feeder machine! It works perfectly, the cats now leave me alone in the morning and it does everything as it was supposed to. In retrospect, I could have made it smaller, especially since we don&apos;t even have the cat litter furniture that was supposed to be its companion. I&apos;m very happy with the result, and also very happy it&apos;s done!&lt;/p&gt;

&lt;p&gt;Here&apos;s come pictures of the inside&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/catFeeder/inside.png&quot; alt=&quot;image&quot; style=&quot;max-height:500px&quot; /&gt;&lt;/p&gt;

&lt;p&gt;And of the outside&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/catFeeder/outside.png&quot; alt=&quot;image&quot; style=&quot;max-height:500px&quot; /&gt;&lt;/p&gt;

&lt;p&gt;I had a lot of fun with this project, this is exactly the kind of stuff I enjoy making, as always I learned a lot and that&apos;s at least half the pleasure. I made this blog post as a way of reflecting on the adventure and sharing the fun. I&apos;m not sure if there&apos;s much to gain for other people here but if you&apos;re still reading I imagine you got something out of it! Thank you for reading and see you on the next one!&lt;/p&gt;
</description>
        <pubDate>Sat, 28 Jan 2023 09:43:32 -0500</pubDate>
        <link>http://lapinozz.github.io/project/2023/01/28/cat-feeder.html</link>
        <guid isPermaLink="true">http://lapinozz.github.io/project/2023/01/28/cat-feeder.html</guid>
        
        <category>Electronics</category>
        
        <category>Arduino</category>
        
        <category>C++</category>
        
        <category>3D Printing</category>
        
        <category>CAD</category>
        
        
        <category>project</category>
        
      </item>
    
      <item>
        <title>3D Printed RTX 3080 Keycap with working fan</title>
        <description>&lt;h1 id=&quot;the-printer&quot;&gt;The Printer&lt;/h1&gt;

&lt;p&gt;I recently purchased a used &lt;a href=&quot;https://artillery3d.com/products/artillery-sidewinder-x1-sw-x1-3d-printer-300x300x400mm-large-plus-size-high-precision-dual-z-axis-tft-touch-screen&quot;&gt;Artillery Sidewinder X1&lt;/a&gt; on Amazon which sadly arrived broken. It kept producing &quot;slanted&quot; prints like this:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/keycap/slanted.png&quot; alt=&quot;image&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Fortunately Artillery had a great customer service, they helped me try different things to resolve the issue and when none of them worked sent me a replacement motherboard for the printer. Once I swapped the old motherboard for the new one it worked perfectly. I&apos;m very happy with this printer and I definitely recommend it!&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/keycap/printer.png&quot; alt=&quot;image&quot; /&gt;&lt;/p&gt;

&lt;p&gt;To control the printer I installed Ocotprint on a used Raspberry Pi I found on Marketplace. Using &lt;a href=&quot;https://www.balena.io/&quot;&gt;balena&lt;/a&gt; to manage the RPI made it super easy to monitor and update the images, I was able to add a &lt;a href=&quot;https://pi-hole.net/&quot;&gt;pi-hole&lt;/a&gt; instance running on the side to block ADs on the network. Of course I printed a case for the RPI using the printer. In addition, I installed a relay inside the X1 directly in series with the On/Off switch and connected it to the RPI&apos;s GPIO pins so that I can turn the printer On/Off from the Octoprint interface.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/keycap/rpi.png&quot; alt=&quot;image&quot; style=&quot;max-height:500px&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;the-design&quot;&gt;The Design&lt;/h1&gt;

&lt;p&gt;When you get a 3D printer you start looking for anything to print, it&apos;s very exciting to see things appear before your eyes, it gives you a whole new creative power. I wondered if there was any keycap model to print, I found some, customized them a little to see what could be done. Here&apos;s a simple Escape key, I added 4 little holes so you could still see the rgb light of the key.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/keycap/esc_key.png&quot; alt=&quot;image&quot; style=&quot;max-height:500px&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Then I wanted to make one that would be more interesting, I asked my friends for inspiration and one of them sent me an image of a &lt;a href=&quot;https://cdn.thisiswhyimbroke.com/images/rtx-3080-mechanical-keycap.gif&quot;&gt;keycap in the shape of an RTX 3080&lt;/a&gt;, some even had a little fan that you could turn using your finger or by gently blowing on it. This gave me an idea, why not make one with an actual working fan?&lt;/p&gt;

&lt;h1 id=&quot;the-modeling&quot;&gt;The Modeling&lt;/h1&gt;

&lt;p&gt;It was my first real CAD project, I had done a couple of simple shapes in &lt;a href=&quot;https://www.autodesk.ca/en/products/fusion-360/overview&quot;&gt;Fusion 360&lt;/a&gt; before but this was far more complex. It was quite an iterative process, in retrospect I could have tried to make it more complete before trying to print it each time. At least it was quite a small print so it didn&apos;t take too long to print and didn&apos;t was too much material. It took a couple of tries to get the keycap to properly fit on my keyboard and hold in place but once I found the perfect measures it felt like just any other key.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/keycap/fusion.png&quot; alt=&quot;image&quot; /&gt;&lt;/p&gt;

&lt;p&gt;I originally planned to spray paint it black and highlight the edges with a silver sharpie but after multiple unsatisfying attempts I abandoned that idea. One of the things that made it quite hard was that I wanted the letters to stay in the color of the &lt;a href=&quot;https://www.amazon.ca/-/fr/gp/product/B08C73Y88G/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&amp;amp;psc=1&quot;&gt;PLA filament&lt;/a&gt;, I thought it would be easy to just plug them with some play dough and over it, then simply remove the play dough but it turned out much harder. The play dough wasn&apos;t really sticking to the plastic so it was really hard to get it to stay inside the indentation of the letters. Even when I managed to fill all the letters, after painting it and spending way too long removing the play dough, the result wasn&apos;t uniform enough. Maybe I&apos;ll revisit this idea, maybe if I find something else to plug the indentations, let me know if you have any suggestions!&lt;/p&gt;

&lt;p class=&quot;image-caption&quot;&gt;&lt;img src=&quot;/assets/image/keycap/iterations.png&quot; alt=&quot;image&quot; /&gt;&lt;/p&gt;
&lt;p&gt;It actually took at least twice as many as that.&lt;/p&gt;

&lt;h1 id=&quot;the-fan&quot;&gt;The Fan&lt;/h1&gt;

&lt;p&gt;The fan was surprisingly easy to model and print even though it&apos;s quite small. It&apos;s hard to remember how small some details are when you do CAD, I spent some time adding bevels and get the shape right just to realize afterwards that they won&apos;t really make any difference at this size.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/keycap/fan.png&quot; alt=&quot;image&quot; style=&quot;max-height:500px&quot; /&gt;&lt;/p&gt;

&lt;p&gt;To turn the fan I needed a really small motor. I used a little &lt;a href=&quot;https://www.amazon.ca/-/fr/gp/product/B01G3R86VI/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&amp;amp;psc=1&quot;&gt;3V vibration module&lt;/a&gt; which I had bought to add haptic feedback to a different project. After removing the case of the module you can see a little rotor with two coils and a weight. Carefully removing the weight leaves you with a mostly balanced rotor that won&apos;t vibrate.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/keycap/rotor.png&quot; alt=&quot;image&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Under the rotor is a ring magnet and two tiny brushes used to send the current to the rotor&apos;s coils. After gluing the fan to the rotor I had to very carefully adjust the position of those brushes so that the correct tension to hold the fan assembly up but not so far that it would jump out or have the brushes not make contact with the contacts. This actually took some time to get working properly. Another thing that took some time is that when removing the case of the vibration module it&apos;s extremely easy to disconnect the wires and I couldn&apos;t manage to solder them back in place. I actually ended up destroying many modules before finding the perfect technique.&lt;/p&gt;

&lt;h1 id=&quot;the-assembly&quot;&gt;The Assembly&lt;/h1&gt;

&lt;p&gt;Only things left was to fit a battery and a switch. My first instinct was to go to the pharmacie, where I knew they had multiple models of tiny batteries. Those turned too expensive for what they are and I just bought the more common LR44 button cell battery. It&apos;s slightly larger size than I had anticipated meant that I could only fit a single cell, giving me only 1.5V instead of the 3V the motor is supposed to run on. This didn&apos;t cause any issue as the motor still turned and I just went with it.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/keycap/battery.png&quot; alt=&quot;image&quot; /&gt;&lt;/p&gt;

&lt;p&gt;For the switch I found one in my &lt;em&gt;miscellaneous parts&lt;/em&gt; box that just happened to fit perfectly. It wasn&apos;t too big, gave barely any resistance when pressed and was just long enough that you don&apos;t have to press the key much before it starts making contact.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/keycap/switch.png&quot; alt=&quot;image&quot; style=&quot;max-height:500px&quot; /&gt;&lt;/p&gt;

&lt;p&gt;For the wiring I simply connected everything in series so the motor would turn when the switch is pressed.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/keycap/wiring.png&quot; alt=&quot;image&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;the-result&quot;&gt;The Result&lt;/h1&gt;

&lt;p&gt;The result is a nice golden keycap that fits very nicely and has a fan that turns when you press on the key. Even I was surprised when I got it complete, the whole project sounded a bit crazy when I first started.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/keycap/result_image.png&quot; alt=&quot;image&quot; style=&quot;max-height:500px&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/keycap/result.gif&quot; alt=&quot;image&quot; width=&quot;100%&quot; /&gt;&lt;/p&gt;
</description>
        <pubDate>Sun, 13 Jun 2021 02:21:23 -0400</pubDate>
        <link>http://lapinozz.github.io/project/2021/06/13/rtx-3080-keycap.html</link>
        <guid isPermaLink="true">http://lapinozz.github.io/project/2021/06/13/rtx-3080-keycap.html</guid>
        
        <category>Electronics</category>
        
        <category>3D Printing</category>
        
        
        <category>project</category>
        
      </item>
    
      <item>
        <title>DIY Smart Door-Lock</title>
        <description>&lt;h1 id=&quot;the-repetition&quot;&gt;The Repetition&lt;/h1&gt;

&lt;p&gt;There are things you do every day, they don&apos;t always take long, but they always make me dream of a way to automate them. A task I found of no value and wished to automate is the action of locking and unlocking my front door. The whole process of getting my keys out, selecting the right one, inserting it correctly into the keyhole and turning is incredibly gratifying. I began to dream of a system that would do it all for me, without any involvement on my part. Of course this might take more time to make then it would save me but that&apos;s without counting the fun I would have in building it and the immense satisfaction I would get each time I passed my door.&lt;/p&gt;

&lt;p class=&quot;image-caption&quot;&gt;&lt;img src=&quot;/assets/image/lock/xkcd.png&quot; alt=&quot;image&quot; title=&quot;xkcd 1205&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://xkcd.com/1205/&quot;&gt;&lt;em&gt;xkcd 1205&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1 id=&quot;the-perfect-lock&quot;&gt;The Perfect Lock&lt;/h1&gt;

&lt;p&gt;My idea was to make a lock that would automatically unlock the door as I arrive home and lock it when I leave. I started looking for a way to detect when I come close and away from home. Immediately I decided to disregard geolocalisation because I wanted something more reliable and didn&apos;t want to require having any program running on my phone. I then looked into Bluetooth, but it wasn&apos;t clear if there would be an easy and reliable way to detect my phone from an Arduino through Bluetooth. Finally, I realized my phone connects to my Wi-Fi when I get close to home and if I assign it a static IP I could simply ping it continuously to see if it was connected to the network. It might not be the cleanest solution but it was easy to get working and so I went with it.&lt;/p&gt;

&lt;p&gt;I&apos;m still amazed at the price and availability of microcontroller these days. I can get a couple of Arduino Nano and ESP8266 for a few bucks.  I already had some Nanos lying around for exactly this kind of project and had recently purchased ESP8266 and NodeMCU boards as I never had the chance to mess with Wi-Fi in my electronics project so far.&lt;/p&gt;

&lt;p&gt;Here&apos;s the Nano and ESP I used on a prototype board and a little 5v to 3v converter to power the ESP.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/lock/nano_esp2.png&quot; alt=&quot;image&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;the-hardware&quot;&gt;The Hardware&lt;/h1&gt;

&lt;p&gt;One of the requirement of my design was to not modify the current lock mechanism. My rent contract explicitly stated that I was forbidden from changing the key and I wanted something that would be simple to remove when the time comes. It was also important that you can still open the lock with the key for any of those occasions:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;landlords should still be able to access&lt;/li&gt;
  &lt;li&gt;as any maintenance personnel like a plumber&lt;/li&gt;
  &lt;li&gt;if I give a key to a friend&lt;/li&gt;
  &lt;li&gt;in the inevitable case of my system crashing&lt;/li&gt;
  &lt;li&gt;for the unfortunate situation of a power outage&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This means that I could not couple a motor directly to the lock, as the resistance of the motor would prevent you from easily turning the key.
My door fashions a deadbolt lock similar to this:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/lock/lock.png&quot; alt=&quot;image&quot; /&gt;&lt;/p&gt;

&lt;p&gt;After some time of thinking passively about it I figured out that this shape would allow the handle of the deadbolt to rotate 90 degrees from the action of the key while also allowing for the shape to rotate the lock by applying a 180 degrees rotation.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/lock/deadbolt_animation.gif&quot; alt=&quot;image&quot; /&gt;
&lt;img src=&quot;/assets/image/lock/mount_animation.gif&quot; alt=&quot;image&quot; /&gt;&lt;/p&gt;

&lt;p&gt;I made the circular piece was made out of layers of foam board panels with the middle cut in that hourglass shape. To rotate it I used a motor already integrated with a gearbox, that made it slower but gave it more torque, I extracted from a toy years ago. Since this is just a simple DC motor there wasn&apos;t a way to know the current angle of the motor. To be able to rotate it accurately I placed a little tab on the circular piece and three sensors around it, one at locking position, one at unlocking position and finally one in the center relaxed position to allow the handle to move freely without having any force from the motor on it.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/lock/sensors.gif&quot; alt=&quot;image&quot; /&gt;&lt;/p&gt;

&lt;p&gt;For the sensors I used some LM393 wheel speed sensor I had lying around. The sensor is composed of two little arms and sends a signal when there&apos;s something between them. And here&apos;s the thing with the motor and all the sensors mounted in all its glory. In retrospect I really should have trimmed all the wires a bit more.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/lock/wip.png&quot; alt=&quot;image&quot; /&gt;&lt;/p&gt;

&lt;p&gt;I also added two buttons on the top to lock/unlock and an on/off switch.&lt;/p&gt;

&lt;h1 id=&quot;the-software&quot;&gt;The Software&lt;/h1&gt;

&lt;p&gt;Controlling the motors and reading the states of the sensors was quite easy, it wasn&apos;t my first Arduino project and I got it out of the way very quickly. Now I had to get the Nano and the ESP8266 talking together. The ESP works on 3.3v, and I used a little 5v to 3v convert to power it. I also needed something so they could talk together and I tried to use a level shifter IC which is supposed to enable a 5v chip to communicate with a 3.3v chip without damaging them by shifting the voltage level on each side but I couldn&apos;t get it to work so in the end I used the cheap and dirty solution of a voltage divider using two resistors on the Arduino to ESP line and just connected the ESP to Arduino line as-is since the Arduino had no issue reading a signal at 3.3v.&lt;/p&gt;

&lt;p&gt;Once I had that working it was just a matter of reading the documentation, I used a direct serial communication so I learned about AT commands and how they work. It was really exciting when I got it working and I saw it lock when I turned off the Wi-Fi on my phone and unlock when I turned the Wi-Fi back on. Sometimes the ping would fail even if my phone was connected. That was easy to fix by adding a counter of &quot;failed&quot; ping and only locking after 3 fail in a row. Next I wanted to be able to control it from a webpage, I opened a port on the ESP to receive TCP connection and forward that port in my router. I didn&apos;t need to do proper HTTP request parsing, just the bare minimum to extract the information I needed, which is essentially just the password which was passed in the URL making it&apos;s location was very standard and easy to extract. The webpage was extremely minimal, just a textbox with two buttons under it to lock or unlock. Even if I wanted I couldn&apos;t make the page very complex as the text quickly takes place on this already quite limited hardware and it also means it takes more time to send it from the Arduino to the ESP.&lt;/p&gt;

&lt;h1 id=&quot;the-voice-activation&quot;&gt;The Voice Activation&lt;/h1&gt;

&lt;p&gt;Now that I had a way to lock/unlock using a web request it means that I could connect it to any services that uses a webhook. A very nice website to connect services and devices of all sort together is &lt;a href=&quot;https://ifttt.com&quot;&gt;IFTTT&lt;/a&gt; (If This Then That). You give it an event to trigger on (If this) and an action to perform (Then That) and it will perform the action when it receives the event. There&apos;s all kind of events like, when you receive an email with optional filters, when you enter a certain location, on a Facebook post, by a Google calendar event. There&apos;s a ton of services adding their own piece to the website so that you can connect them to other things. The event I used was Google Assistant when I say &quot;Ok Google, open front door&quot; or &quot;Hey Google, unlock the door&quot; and the likes. My action was a simple webhook, sending a request with the correct password to my device. In a couple of minutes I got it working so that I could lock/unlock my door using Google Assistant, pretty cool.&lt;/p&gt;

&lt;h1 id=&quot;the-finishing-off&quot;&gt;The Finishing Off&lt;/h1&gt;

&lt;p&gt;After finishing the software and the hardware and had glued the remaining panels I was finally able to enjoy the fruit of my hard labour, after adjusting a couple of things… For the power I used two thin and long white cables, matching the color of the door and making sure they wouldn&apos;t show too much. Turns out when my phone&apos;s screen is turned off it takes a long time to respond to pings, sometimes too long, and it would lead to the system thinking I left and locking the door. It was extremely creepy and startled me each time. I already had added an on/off switch which only toggled the pinging and didn&apos;t disable the web server. I simply made it so that when I turn it &lt;em&gt;off&lt;/em&gt; it would &lt;em&gt;lock&lt;/em&gt; the door, since it would mean that I arrive home and when I turn it &lt;em&gt;on&lt;/em&gt; it would &lt;em&gt;unlock&lt;/em&gt; as I am probably leaving. This way it would be off most of the time I am home and it wouldn&apos;t randomly decide to trigger the mechanism.&lt;/p&gt;

&lt;p&gt;Here&apos;s a picture of the final product, a bit clunky but I love it. I&apos;m very happy I thought of leaving a little hole so I could upload a new program to the Arduino as it would have been much more painful to do this upgrade without it. Also note that I later added some black electrical tape on the edges which gave it a much better appearance. 
&lt;img src=&quot;/assets/image/lock/finish.png&quot; alt=&quot;image&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;the-security&quot;&gt;The Security&lt;/h1&gt;

&lt;p&gt;It might seem like adding a clumsy, self-made lock system connected to the internet could be a huge security issues but I don&apos;t believe this has significantly increased the chance of someone gaining unauthorized access to my apartment. First of all this is a unique device, no one has access to its program which already makes it harder to create an exploit for it. I&apos;m pretty confident that I sanitized all the inputs and all the buffers in the code are static. Brute forcing it would be difficult because it&apos;s quite slow, it can take a couple of seconds to try even a single combination. The password could be anything, since there&apos;s about 95 printable ASCII character and an URL can be about 2000 characters, let&apos;s say minus 100 for the address of and the path, that leaves 95^1900 combination. But my main point is that my door isn&apos;t very secure to start with, the truth is that most residential door lock aren&apos;t any good and I can lockpick it open without too much trouble even though I barely have any experience. So if someone wanted to gain access to my apartment it would be easier to just lockpick the door (or straight away break it down or break a window) than to hack into my system.&lt;/p&gt;

&lt;p&gt;PS: Now that I think about all the connections are over HTTP so assuming that someone is able to sniff those packets, they could probably retrieve the password, oh well.&lt;/p&gt;
</description>
        <pubDate>Sun, 13 Jun 2021 02:21:23 -0400</pubDate>
        <link>http://lapinozz.github.io/project/2021/06/13/automatic-lock.html</link>
        <guid isPermaLink="true">http://lapinozz.github.io/project/2021/06/13/automatic-lock.html</guid>
        
        <category>Electronics</category>
        
        <category>Arduino</category>
        
        
        <category>project</category>
        
      </item>
    
      <item>
        <title>Rubber Duckies and practical trolling</title>
        <description>&lt;h1 id=&quot;the-troll&quot;&gt;The Troll&lt;/h1&gt;

&lt;p&gt;Leaving your computer unlocked when you leave to get some coffee is a risk. It&apos;s a security risk as someone could just walk up and exploit the free admin access to your computer, from which point they could do any number of things like install a backdoor or copy important files. But most importantly, it&apos;s a very powerful troll magnet. There&apos;s no better prank than changing someone&apos;s background while they are not looking.&lt;/p&gt;

&lt;h1 id=&quot;rubber-ducky&quot;&gt;Rubber ducky&lt;/h1&gt;

&lt;p&gt;A rubber ducky is a tiny little Arduino-like board that features an Attiny85 chip and a little protrusion on the PCB which just the right shape and lines to be inserted in a USB port.&lt;/p&gt;

&lt;p&gt;I soldered headers on those for some reason but they usually come without those which gives them a really tight footprint.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/ducky/duckies1.png&quot; alt=&quot;image&quot; /&gt; 
&lt;img src=&quot;/assets/image/ducky/duckies2.png&quot; alt=&quot;image&quot; style=&quot;max-height:360px;position:relative;left:50%;transform:translateX(-50%)&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The idea behind those devices is that they can simulate a keyboard, with the ability to send thousands of characters per seconds. Now if you had some nefarious intentions and you managed to either plug this device in an unlocked computer or trick someone in doing so themselves you could easily make it install a virus or extract information. If you are slightly less evil you might also realize that it is the perfect trolling tool.&lt;/p&gt;

&lt;p&gt;It also works as a normal Attiny85 so you can control a led or read some switch for example. I toyed with this a little to make one where you could switch which script it would execute. (There used to be two additional switches on this but at some point I stole them for another project)&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/ducky/switched.png&quot; alt=&quot;image&quot; style=&quot;max-height:500px&quot; /&gt;&lt;/p&gt;

&lt;p&gt;They also come in other form factor, with better chips or a micro sd card reader, etc.&lt;/p&gt;

&lt;h1 id=&quot;the-plan&quot;&gt;The plan&lt;/h1&gt;

&lt;p&gt;Those devices are great but are quite limited, if you want to type a lot of text the storage quickly becomes a problem. Luckily people are smart and have thought about ways to circumvent the issue. If the target computer has access to internet you can:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Open the Windows start menu (&quot;Windows Key&quot;)&lt;/li&gt;
  &lt;li&gt;Open an administrator Powershell (Type &quot;powershell&quot; then press Ctrl+Shift+Enter to launch as admin)&lt;/li&gt;
  &lt;li&gt;Say yes to the admin prompt (&quot;Left Arrow&quot; to select the yes button then &quot;Enter&quot; to confirm)&lt;/li&gt;
  &lt;li&gt;Use a powershell command that will download a script and run it immediately&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/ducky/explanation.png&quot; alt=&quot;image&quot; style=&quot;max-height:720px;position:relative;left:50%;transform:translateX(-50%)&quot; /&gt;&lt;/p&gt;

&lt;p&gt;This way you have no limit on the size of the script. I used a combination of &lt;a href=&quot;https://gist.github.com/&quot;&gt;GitHub&apos;s gists&lt;/a&gt; and &lt;a href=&quot;https://tinyurl.com&quot;&gt;TinyUrl&lt;/a&gt; to both keep the URL short and be able to modify the script as I develop it.&lt;/p&gt;

&lt;h1 id=&quot;the-rootkit&quot;&gt;The Rootkit&lt;/h1&gt;

&lt;p&gt;At this point I had a couple of fun powershell scripts working but it was clear that powershell windows floating around had nothing stealthy about them. It&apos;s possible to launch a powershell script with no window but I knew the first thing any competent person would do is to open the Task Manager where they would immediately spot the quite suspicious powershell processes, I needed a better way.&lt;/p&gt;

&lt;p&gt;Thing is, Windows is designed in such a way so that no process can &quot;hide&quot; itself. In other word, a program able to hide itself is essentially a virus (&lt;a href=&quot;https://en.wikipedia.org/wiki/Sony_BMG_copy_protection_rootkit_scandal&quot;&gt;Unless you&apos;re Sony and you think you&apos;re the most important thing on earth&lt;/a&gt;). A rootkit is a software, or group of software, designed to maintain access to a system and to conceal itself. After reading a bit on the subject I decided to go the quick and dirty way; injecting a DLL into every running process on the machine.&lt;/p&gt;

&lt;p&gt;DLL injection is a method by which you make a program load a piece of code and then execute it in the program itself. On your code is running in the program it can alter its memroy and even its code. For example, &lt;a href=&quot;https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/nf-ntifs-ntquerydirectoryfile&quot;&gt;ZwQueryDirectoryFileReal&lt;/a&gt; is a function to list the files in a directory. Pretty much all calls a program makes to query the files in a directory go through this function as it&apos;s a system function and the way to go to interface with the OS. This function gets loaded in memory somewhere, we can get the address of the function, make that part of memory temporarily writable then put our own code there. This code could do anything but the most useful thing to do in our case is to look at the queried path, if it points to something we want to hide, we return the same thing the original function would return if the path didn&apos;t exist. If we don&apos;t care about this path then we just call the original function and forward it&apos;s return value. Same applies for the function responsible for listing processes. Now we just have to inject that code into all the running programs and monitor new ones so we can inject it into them too.&lt;/p&gt;

&lt;p&gt;The code &quot;injector&quot; I made for this is called &lt;a href=&quot;https://github.com/lapinozz/Vaccinator&quot;&gt;Vaccinator&lt;/a&gt; and the DLL it injects is &lt;a href=&quot;https://github.com/lapinozz/Vaccinator&quot;&gt;Kernel64&lt;/a&gt;&lt;/p&gt;

&lt;h1 id=&quot;the-pranking&quot;&gt;The pranking&lt;/h1&gt;

&lt;p&gt;I want to make it very clear that I wouldn&apos;t do this on just anyone, nor should you. The person I did this to was sitting right next to me, we joked a lot about locking your computer when you get up,  which he always forgot to do, and he was actually well aware of what I was working on.&lt;/p&gt;

&lt;p&gt;That said, here&apos;s what the final scripts were doing:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Periodically change his wallpaper (Of course)&lt;/li&gt;
  &lt;li&gt;Trigger Text-To-Speech randomly (&quot;I will lock my computer&quot;, &quot;Computer compromised&quot;, &quot;All systems hacked&quot;, &quot;Never Forget, Never Forgive, Expect Us&quot;, &quot;Once upon a time, I forgot to lock his computer&quot;, &quot;Trollollollollollollollollolloll&quot;)&lt;/li&gt;
  &lt;li&gt;Periodically open/close CD tray&lt;/li&gt;
  &lt;li&gt;And most importantly, hide all the relevant processes and files&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It was easy to deploy, just wait for him to get up, leaving his computer unlocked, stick the little thing in a USB port(our keyboards had very accessible ports on the back), screen briefly flashes a console and voila!&lt;/p&gt;

&lt;h1 id=&quot;the-defusing&quot;&gt;The Defusing&lt;/h1&gt;

&lt;p&gt;I was so sure, so certain, my code was so perfect. He would have to capitulate, there was &lt;em&gt;no&lt;/em&gt; way he could defeat my beautiful system.&lt;/p&gt;

&lt;p&gt;Turns out by opening a powershell window through the start menu it left it in the history. He didn&apos;t fail to notice that and upon opening a shell he just had to press the up arrow to see the history of commands where he found the address of my script. That script contained links to other scripts and to the GitHub repository of &lt;a href=&quot;https://github.com/lapinozz/Vaccinator&quot;&gt;Vaccinator&lt;/a&gt; where it was pretty easy to spot the &lt;a href=&quot;https://github.com/lapinozz/Vaccinator/blob/master/Kernel64/dllmain.cpp#L38&quot;&gt;code I had left to deactivate all the hiding functions&lt;/a&gt; when a file with a specific name was place at the root of the C drive.&lt;/p&gt;

&lt;p&gt;If I had just cleared the powershell command history he probably wouldn&apos;t have found a way to deactive my scripts. They could have been more aggressive anyways but this was just for fun. Turned out pretty funnny in the end.&lt;/p&gt;
</description>
        <pubDate>Sat, 29 May 2021 18:21:23 -0400</pubDate>
        <link>http://lapinozz.github.io/project/2021/05/29/ruber-duckies.html</link>
        <guid isPermaLink="true">http://lapinozz.github.io/project/2021/05/29/ruber-duckies.html</guid>
        
        <category>Electronics</category>
        
        <category>Arduino</category>
        
        
        <category>project</category>
        
      </item>
    
      <item>
        <title>Persistence-Of-Vision Display</title>
        <description>&lt;h1 id=&quot;the-itch&quot;&gt;The Itch&lt;/h1&gt;

&lt;p&gt;Sometimes you get the urge to try something, an idea come to you or you see something and you just know you have to make it. Me and my friends call this &quot;the itch&quot;. Sometimes it would be a huge endeavour, which you would probably never finish, so to avoid adding to the huge pile of unfinished project you already have, you have to resist it. But sometimes the scope is approachable, that&apos;s when it gets really dangerous, that&apos;s when the itch is irrepressible.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/POV/itch.png&quot; alt=&quot;image&quot; style=&quot;max-height:450px&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;pov-display&quot;&gt;POV Display&lt;/h1&gt;

&lt;p&gt;I saw a video about a POV Display and it reminded me of their existence. That was enough, I had to make one, today. They work quite simply, you have some spinning leds and if you light when they are at the same angle on each turn they will appear like there&apos;s a constance source of light there. Blink them at the right place and time, you got a circular screen on which you can write or draw things.&lt;/p&gt;

&lt;h1 id=&quot;construction&quot;&gt;Construction&lt;/h1&gt;

&lt;p&gt;For this kind of &quot;on the spot&quot; projects I have to do with what is laying around, I already had a couple of motors, AC adaptor, Arduino Nano, leds, pretty much everything needed. It took me a couple of trial and error to find the right combination of motor and power supply, in the end I used a DC 12V motor, which came from something I dismantled but I can&apos;t remember what it was, and an old computer&apos;s PSU which double as a base for the contraption. Even with this big heavy base it still vibrates a lot and wobbles around so I ned to hold it a bit with one hand Which is a bit scary since the upper part is made of a 4XAA battery holder on one side and a mix of popsicle sticks and pointy prototype board on the other giving a radius of about 20 centimeters, the whole thing turning quite fast.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/POV/base.png&quot; alt=&quot;image&quot; style=&quot;max-height:500px&quot; /&gt;&lt;/p&gt;

&lt;p&gt;I wanted to maximize the ability of my Arduino nano so I went with a resolution of 10 pixel in &quot;height&quot; and 2 colors. I think I chose white and blue for my colors because those leds worked fine with the 5V and didn&apos;t need any resistor. Took me quite some time to finish the led board because the leds kept dying, until I realised I was accidentally shorting them when testing.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/POV/leds.png&quot; alt=&quot;image&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;testing-and-adjusting&quot;&gt;Testing and Adjusting&lt;/h1&gt;

&lt;p&gt;Getting the code to work wasn&apos;t too hard but once I got the speed aproximatively tuned to the speed of the motor it became apparent that the design was flawed. The lines were very moving around and it was impossible to keep it exactly sync as the motor&apos;s speed isn&apos;t exacly constant. I knew other who have made this used some kind of sensor to detect the RPM so I looked for something that could work and found some LM393 wheel speed sensor. The sensor is composed of two little arms and sends a signal when there&apos;s something between them. I just had to mount the sensor on the rotating part of the display and a little piece of popsicle stick on the static part so that it pass in the sensor on each rotation then measure the time it took between two rotation to know the speed at which it was rotating. As soon as I got the speed sensor working I was amazed, the display was precise and clear, much better than I had imagined it would work.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/POV/sensor.png&quot; alt=&quot;image&quot; style=&quot;max-height:500px&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;result&quot;&gt;Result&lt;/h1&gt;

&lt;p&gt;The result is a big deadly circle of light title &quot;CIRCULUS LUMINIS&quot; (Google assures me it means &quot;circle of light&quot; in Latin).
It has a nice radius, I&apos;m pretty happy with the result. As always those kind of things are hard to capture properly on camera, between brightness and rolling shutter effects it makes it look much worse on camera than it does in real life. It works well with the lights on but the picture were better in the dark. Also I took some videos but as I said the  effect made them quite unattractive. When asking my friends what I should display for the showcase they came up with the very mature &quot;send nude&quot; so here it is, in two colors.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/POV/hello.png&quot; alt=&quot;image&quot; style=&quot;max-height:450px&quot; /&gt; &lt;img src=&quot;/assets/image/POV/send-nude.png&quot; alt=&quot;image&quot; style=&quot;max-height:450px&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;going-further&quot;&gt;Going further&lt;/h1&gt;

&lt;p&gt;I had started on animations for the display using a pixel art animation editor and a little script(that &lt;a href=&quot;https://github.com/alexge50&quot;&gt;my friend&lt;/a&gt; generously made for me) to convert the images into binary on/off arrays but I was stretching the limit of the storage available and processing power on my Arduino Nano so it was hard to put more frames but I&apos;m sure I could manage some simple compression which doesn&apos;t take too much time. Maybe one day I&apos;ll get back to it.&lt;/p&gt;

</description>
        <pubDate>Sat, 29 May 2021 18:21:23 -0400</pubDate>
        <link>http://lapinozz.github.io/project/2021/05/29/persistence-of-vision-display.html</link>
        <guid isPermaLink="true">http://lapinozz.github.io/project/2021/05/29/persistence-of-vision-display.html</guid>
        
        <category>Electronics</category>
        
        <category>Arduino</category>
        
        
        <category>project</category>
        
      </item>
    
      <item>
        <title>Compile-time templated A* pathfinding in C++14</title>
        <description>&lt;h1 id=&quot;what-is-this&quot;&gt;What is this?&lt;/h1&gt;

&lt;p&gt;In simple terms, a complete mess. More concretely, it&apos;s a piece of code that I wrote which computes a path using the A* algorithm and works entirely at compile-time, that is, all computations are done by the compiler and nothing is done at runtime. So at the end, the executable only contains the result, in this case, the path.&lt;/p&gt;

&lt;h1 id=&quot;inspiration&quot;&gt;Inspiration&lt;/h1&gt;

&lt;p&gt;I asked my good friend Nyrox on the #sfml IRC channel for a compile-time challenge to my measure.&lt;br /&gt;
He finally suggested doing A* pathfinding and I gladly took the challenge.&lt;/p&gt;

&lt;h1 id=&quot;tools&quot;&gt;Tools&lt;/h1&gt;

&lt;p&gt;To help me in my task I used the superb &lt;a href=&quot;http://www.godbolt.org&quot;&gt;Compiler Explorer&lt;/a&gt;. It lets you choose between a vast selection of compilers and versions and continuously tries to compile your program as you type it. When your program compiles, it shows the resulting assembly on the right, it&apos;s really practical when doing. At the end I also used &lt;a href=&quot;http://www.regex101.com&quot;&gt;Regex101&lt;/a&gt; to quickly filter part of the compiler output. Finally, I used &lt;a href=&quot;http://www.cpp.sh&quot;&gt;C++ Shell&lt;/a&gt; which lets you execute C++ code online.&lt;/p&gt;

&lt;h2 id=&quot;code&quot;&gt;Code&lt;/h2&gt;

&lt;p&gt;Let&apos;s dive right in!
For those who just want to see the code, &lt;a href=&quot;https://github.com/lapinozz/CompileTime-Pathfinding/blob/master/main.cpp&quot;&gt;here&apos;s the link&lt;/a&gt;.&lt;/p&gt;

&lt;h1 id=&quot;starting-simple-vec-class&quot;&gt;Starting simple, Vec class&lt;/h1&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;k&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Vec&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;constexpr&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;constexpr&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;There we go, a simple templated class, I use it to store a position on the map. For example &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Vec&amp;lt;4, 5&amp;gt; v;&lt;/code&gt; would create an instance, but in this project I almost only work with type, so I would more likely write &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;using V = Vec&amp;lt;4, 5&amp;gt;;&lt;/code&gt; which is a type alias declaration. I can then access the value like this &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;V::x&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I want to do pathfinding in a 2D map and I will store this map as a 1D array, so I need a way to map 2D coordinates, which I&apos;ll call Vec now, to a 1D coordinate, which I&apos;ll call Index.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;k&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Vec&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;constexpr&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;constexpr&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    
    &lt;span class=&quot;k&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sizeX&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;constexpr&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Index&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sizeX&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;I basically declare a templated variable that is static, so that it is not part of an instance but of the class itself, and constexpr, so that it can be used in a constant expression and thus at compile-time. If any of those terms are unknown to you, I suggest researching and experimenting with them as it is the best way to learn. Also this is not a tutorial about template haxery but merely an overview of my experiment.&lt;/p&gt;

&lt;p&gt;Assuming that the horizontal size of my map is 10, I&apos;d use it like this &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;int Index = V::Index&amp;lt;10&amp;gt;;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Of course we also need to do the opposite operation, going from Index to Vec:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;k&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sizeX&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;FromIndex&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Vec&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Index&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sizeX&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Index&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sizeX&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;And using it is as easy as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;using V = FromIndex&amp;lt;10, _IndexHere_&amp;gt;;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;It will also be handy further down the road to get the neighbors of this Vec:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;k&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Vec&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;constexpr&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;constexpr&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    
    &lt;span class=&quot;k&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sizeX&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;constexpr&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Index&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sizeX&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    
    &lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Up&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;Vec&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Down&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;Vec&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Left&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;Vec&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Y&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Right&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Vec&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Y&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h1 id=&quot;vector&quot;&gt;Vector&lt;/h1&gt;

&lt;p&gt;Now that I have some Vec I need a way to hold them in an array, so I implemented a Vector class.
I won&apos;t cover every line, it&apos;s not trivial but with the &quot;function&quot; name, and some serious dedication, understanding the code should be possible. It is probably not the best way to do those things anyways, I wanted something that worked, coding features as I needed them, once they worked reasonably well and the code was not too terrible, I just moved on.&lt;/p&gt;

&lt;p&gt;With that in mind, feel free to inspire yourself from it or suggest improvements.&lt;/p&gt;

&lt;p&gt;Note that, as to not make the post too long and boring, I removed most functions of the following code. In the complete code you can find functions such as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PopBack&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Find&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Transform&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Get&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Remove&lt;/code&gt; and so on.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;k&quot;&gt;template&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Vector&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;V&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;PushFront&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Vector&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;V&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;...,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;V&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;PushBack&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Vector&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;...,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;V&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;V&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Insert&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Impl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        
        &lt;span class=&quot;k&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Vs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Impl&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Vector&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Vs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Type&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Vector&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;...,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Vs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

        &lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Type&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Impl&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;V&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;V&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;insert&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Insert&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;V&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h1 id=&quot;note-on-my-synthax&quot;&gt;Note on my synthax&lt;/h1&gt;

&lt;p&gt;You might have noticed I declare my &quot;function&quot; in a strange way, look at the insert &lt;em&gt;function&lt;/em&gt;:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;    &lt;span class=&quot;k&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;V&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Insert&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Impl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        
        &lt;span class=&quot;k&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Vs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Impl&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Vector&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Vs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Type&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Vector&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;...,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Vs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

        &lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Type&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Impl&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;V&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;I just feel like it&apos;s less of a mess when I write it this way, it feels more &quot;contained&quot;, it&apos;s simply a personal preference, I could also write it in a more &quot;normal&quot; way:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;    &lt;span class=&quot;k&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;V&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Insert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    
    &lt;span class=&quot;k&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Vs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Insert&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Vector&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Vs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Type&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Vector&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;...,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Vs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;It is way less typing in this case, and I would guess it compiles faster, I didn&apos;t do any benchmark in this regard yet. &lt;br /&gt;
Let me know what you think of it!&lt;/p&gt;

&lt;p&gt;I also define aliases in lower case that are easier to call so rather than doing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MyVec::Insert&amp;lt;MyOtherVec&amp;gt;::Type&lt;/code&gt; I can do &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MyVec::insert&amp;lt;MyOtherVec&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;    &lt;span class=&quot;k&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;V&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;insert&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Insert&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;V&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h1 id=&quot;bad-bad-vector&quot;&gt;Bad, bad Vector&lt;/h1&gt;

&lt;p&gt;In itself, this class works well, you can do fun stuff at compile time, hold any kind of type and insert, remove, find them, etc. But there is a problem, it only holds &lt;em&gt;Types&lt;/em&gt;, so no int or any kind of value. And I want my final map to be made of chars, how to solve it?&lt;/p&gt;

&lt;p&gt;The solution is simple, make a type that has the sole purpose of holding a value:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;k&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;ValueHolder&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Type&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;constexpr&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Now I can hold a value, a 5 as an int for example &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ValueHolder&amp;lt;int, 5&amp;gt;&lt;/code&gt;. But it&apos;s still extremely annoying to always have to care about the ValueHolder and such. So I made an overload for values, this way I can push, remove, and find value using the exact same syntax as I would with types.&lt;/p&gt;

&lt;p&gt;Again, I removed most functions, this time I left &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Find&lt;/code&gt;.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;k&quot;&gt;template&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ForceGeneric&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;VectorImpl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Vector&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;VectorImpl&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;constexpr&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Size&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;sizeof&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;...(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;template&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ForceGeneric&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;VectorImpl&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;V&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Condition&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;is_same&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Find&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;template&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CurrentIndex&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Current&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;I&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Impl&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;constexpr&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Index&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Condition&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Current&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;V&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CurrentIndex&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Impl&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CurrentIndex&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;I&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

        &lt;span class=&quot;k&quot;&gt;template&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Current&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;I&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Impl&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Vector&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Size&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Current&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;I&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;constexpr&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Index&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

        &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;constexpr&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Index&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Impl&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;...,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;IgnoreT&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;V&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Condition&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;is_same&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;constexpr&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;find&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Find&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;V&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Condition&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;template&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;V&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;VectorImpl&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ValueHolder&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;V&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;VectorImpl&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ValueHolder&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;V&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Condition&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;is_same&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Find&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Left&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Right&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;ConditionWrapper&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

        &lt;span class=&quot;k&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Left&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Right&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;ConditionWrapper&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ValueHolder&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Left&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ValueHolder&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Right&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;constexpr&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Left&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Right&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

        &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;constexpr&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Index&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;vecImpl&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;template&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Find&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ValueHolder&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ConditionWrapper&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Condition&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;is_same&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;constexpr&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;find&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Find&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Condition&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h1 id=&quot;map&quot;&gt;Map&lt;/h1&gt;

&lt;p&gt;The map itself is just inheriting from vector and simply adds a function to get a value from a coordinate and holds the horizontal size&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;k&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SizeX&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Map&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Vector&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;GetVector&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Vector&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;constexpr&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sizeX&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SizeX&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;VecT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;GetFromPos&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;constexpr&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;GetVector&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;template&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Get&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;VecT&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;template&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Index&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SizeX&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;VecT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;constexpr&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;getFromPos&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;GetFromPos&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;VecT&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h1 id=&quot;node&quot;&gt;Node&lt;/h1&gt;

&lt;p&gt;A* is implemented using nodes, which hold a pointer to its parent, the cost of its path so far, its heuristic cost and its position.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;k&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;G&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;H&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;ParentType&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Node&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;constexpr&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Index&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;constexpr&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;G&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;constexpr&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;h&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;H&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;constexpr&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Cost&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;G&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;G&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;H&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Parent&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ParentType&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;You might wonder why G is squared, it&apos;s because my heuristic function takes two Vec and returns the distance between them squared. Sqrt is a real pain in template since we can&apos;t use float at compile-time and it&apos;s really easy to just represent every distance as squared distances!&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;k&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Vec1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Vec2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Heuristic&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;constexpr&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;X3&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Vec2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Vec1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;constexpr&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Y3&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Vec2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Vec1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;constexpr&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;X3&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;X3&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Y3&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Y3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h1 id=&quot;pathfinding&quot;&gt;Pathfinding&lt;/h1&gt;

&lt;p&gt;I made an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AStar&lt;/code&gt; class, in it there&apos;s a couple of members which are the start value of the algorithm, so the start and end position, the openlist and closedlist, etc.&lt;/p&gt;

&lt;p&gt;Then I have a &quot;function&quot; called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;BuildNeighbors&lt;/code&gt; its role is to gather all the neighbor position of a node in a vector, removing all those are out of the map bounds. Then there is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FilterNeighbors&lt;/code&gt; which removes the position that point to a wall or if a node with the same cost and position exists in the closedlist or openlist.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MakePath&lt;/code&gt; is the final function that takes the final node when the algorithm has reached the end position and unroll all its parents and puts all the position in a vector.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MainLoop&lt;/code&gt; is, well, the main loop, it takes the node with the least cost on the openlist, removes it from the list and find its neighbors using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;BuildNeighbors&lt;/code&gt;, filter them using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FilterNeighbors&lt;/code&gt; and add them to the openlist. It then adds the least node to the closedlist and recurse, unless the least node position is equal to the end position, in which case it stops recursing and returns the result of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MakePath&lt;/code&gt;.&lt;/p&gt;

&lt;h1 id=&quot;debugging&quot;&gt;Debugging&lt;/h1&gt;

&lt;p&gt;Many times during the development, things refused to work as intended, but I could not use a simple std::cout as I&apos;m used to, because everything was at compile time. So I found a nice trick, you can force an &quot;error&quot; and hope that the compiler will throw you the information that you want. Here for example I want to know the content of a vector.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;MyVector&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Vector&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Vec&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Vec&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Vec&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Vec&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Test&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;MyVector&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Test&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Clang, for example, will output this&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-txt&quot; data-lang=&quot;txt&quot;&gt;666 : &amp;lt;source&amp;gt;:666:24: error: &apos;Test&apos; in &apos;using MyVector = struct Vector&amp;lt;Vec&amp;lt;0, 0&amp;gt;, Vec&amp;lt;1, 1&amp;gt;, Vec&amp;lt;2, 2&amp;gt;, Vec&amp;lt;3, 3&amp;gt; &amp;gt; {aka struct Vector&amp;lt;Vec&amp;lt;0, 0&amp;gt;, Vec&amp;lt;1, 1&amp;gt;, Vec&amp;lt;2, 2&amp;gt;, Vec&amp;lt;3, 3&amp;gt; &amp;gt;}&apos; does not name a type
 using Test = MyVector::Test;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;And GCC will do something close. Another way is to use static_assert, it&apos;s just like a classic assert but at compile-time, so it takes a constant expression and if it resolves to true then it&apos;s ignored, if it&apos;s false however, it will output an error and potentially stop.&lt;/p&gt;

&lt;p&gt;So I could do this to verify that the size member of my vector is correct&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;MyVector&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Vector&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Vec&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Vec&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Vec&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Vec&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;static_assert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;MyVector&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Size&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Thus, if I made an error somewhere, I will immediately know.
I made a couple of test cases as I was adding various functions.
The define is because this is all C++14 conformant and the C++14 static_assert version requires a string as second parameter to output in case of failure, in C++17 it is optional. To make my life easier, I made that macro that just put an empty string there for me.&lt;/p&gt;

&lt;p&gt;Here&apos;s some part of my tests.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;cp&quot;&gt;#define static_assert(...) static_assert(__VA_ARGS__, &quot;&quot;)
&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;static_assert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getFromPos&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Vec&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;static_assert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getFromPos&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Vec&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;static_assert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;sc&quot;&gt;&apos;S&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;static_assert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getFromPos&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Vec&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;sc&quot;&gt;&apos;S&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;static_assert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getFromPos&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Vec&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;sc&quot;&gt;&apos;E&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;static_assert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;sc&quot;&gt;&apos;S&apos;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// Start&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;static_assert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;sc&quot;&gt;&apos;E&apos;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// End&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;static_assert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Vec&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Index&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;17&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;static_assert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;is_same&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;FromIndex&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;17&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Vec&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;static_assert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;FromIndex&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;17&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Index&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;17&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;TestVec1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;VectorFromValue&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;TestVec2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;TestVec1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;PushFront&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;static_assert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;TestVec1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;static_assert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;TestVec1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;static_assert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;TestVec1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;remove&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;static_assert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;TestVec2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;static_assert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;TestVec2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;PopFront&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;TestVector4&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Vector&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Test&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Test&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Test&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Test&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Test&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;LeastNode&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;FindLeast&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;TestVector4&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;static_assert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;LeastNode&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Index&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;static_assert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;LeastNode&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Cost&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h1 id=&quot;the-actual-map&quot;&gt;The actual map&lt;/h1&gt;

&lt;p&gt;Here&apos;s my map, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0&lt;/code&gt; is void, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1&lt;/code&gt; is a wall, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;S&lt;/code&gt; is the start and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;E&lt;/code&gt; is the end. Note that I used define because if I typed &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&apos;S&apos;&lt;/code&gt; it would offset the whole row and I really wanted to use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;S&lt;/code&gt; and not &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;2&lt;/code&gt; or something.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;cp&quot;&gt;#define S &apos;S&apos;
#define E &apos;E&apos;
&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;map&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;MapFromValue&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;E&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; 

&lt;span class=&quot;cp&quot;&gt;#undef S
#undef E&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h1 id=&quot;the-final-code&quot;&gt;The Final code&lt;/h1&gt;

&lt;p&gt;The complete and final code is &lt;a href=&quot;https://github.com/lapinozz/CompileTime-Pathfinding/blob/master/main.cpp&quot;&gt;available on github&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;its-nice-and-all-that-but-how-do-you-know-it-actually-works&quot;&gt;It&apos;s nice and all that but how do you know it actually works?&lt;/h2&gt;

&lt;p&gt;Excellent question! As I showed earlier, we can force the compiler to output the final path, then I extract that path using a regex &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.*?(Vec&amp;lt;(\d+), (\d+)&amp;gt;).*?&lt;/code&gt; and replace with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;​{$2,$3}, \n&lt;/code&gt; so that&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-txt&quot; data-lang=&quot;txt&quot;&gt;668 : &amp;lt;source&amp;gt;:668:21: error: no type named &apos;Test&apos; in &apos;Vector&amp;lt;Vec&amp;lt;0, 0&amp;gt;, Vec&amp;lt;1, 0&amp;gt;, Vec&amp;lt;2, 0&amp;gt;, Vec&amp;lt;3, 0&amp;gt;, Vec&amp;lt;4, 0&amp;gt;, Vec&amp;lt;5, 0&amp;gt;, Vec&amp;lt;6, 0&amp;gt;, Vec&amp;lt;7, 0&amp;gt;, Vec&amp;lt;7, 1&amp;gt;, Vec&amp;lt;7, 2&amp;gt;, Vec&amp;lt;7, 3&amp;gt;, Vec&amp;lt;7, 4&amp;gt;, Vec&amp;lt;7, 5&amp;gt;, Vec&amp;lt;7, 6&amp;gt;, Vec&amp;lt;7, 7&amp;gt;, Vec&amp;lt;6, 7&amp;gt;, Vec&amp;lt;5, 7&amp;gt;, Vec&amp;lt;5, 6&amp;gt;, Vec&amp;lt;5, 5&amp;gt;, Vec&amp;lt;5, 4&amp;gt;, Vec&amp;lt;5, 3&amp;gt;, Vec&amp;lt;5, 2&amp;gt;, Vec&amp;lt;4, 2&amp;gt;, Vec&amp;lt;3, 2&amp;gt;, Vec&amp;lt;2, 2&amp;gt;, Vec&amp;lt;2, 3&amp;gt; &amp;gt;&apos;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Becomes&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-txt&quot; data-lang=&quot;txt&quot;&gt;{0,0}, 
{1,0}, 
{2,0}, 
{3,0}, 
{4,0}, 
{5,0}, 
{6,0}, 
{7,0}, 
{7,1}, 
{7,2}, 
{7,3}, 
{7,4}, 
{7,5}, 
{7,6}, 
{7,7}, 
{6,7}, 
{5,7}, 
{5,6}, 
{5,5}, 
{5,4}, 
{5,3}, 
{5,2}, 
{4,2}, 
{3,2}, 
{2,2}, 
{2,3}, &lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Then I simply paste that into a program that I made which print the map with the a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;#&lt;/code&gt; at all the aboves positions.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;cp&quot;&gt;#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&amp;lt;iostream&amp;gt;&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&amp;lt;vector&amp;gt;&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;//  .*?(Vec&amp;lt;(\d+), (\d+)&amp;gt;).*?&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;//  {$2,$3}, \n&lt;/span&gt;

    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mapSize&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;vector&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;map&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Vec&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;vector&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Vec&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;path&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; 
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// INSERT POSITIONS HERE&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;sc&quot;&gt;&apos; &apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;sc&quot;&gt;&apos;#&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Vec&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;vec&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;vec&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;vec&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mapSize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;sc&quot;&gt;&apos;*&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;size_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mapSize&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cout&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;sc&quot;&gt;&apos;\n&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            
        &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cout&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h1 id=&quot;final-output&quot;&gt;Final Output&lt;/h1&gt;

&lt;p&gt;Finally, I run this program using &lt;a href=&quot;cpp.sh&quot;&gt;Cpp Shell&lt;/a&gt; and it outputs the map and I can see that the path is correct.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-txt&quot; data-lang=&quot;txt&quot;&gt;********
#######*
  ****#*
  *##*#*
   # *#*
   # *#*
 ### *#*
     ***&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;This was pretty fun to write, even thought it can&apos;t really be used in real world code I still learned a lot of tricks that can be useful during real development. I also find it amazing that I was able to write everything on the web, in my web browser, it was really easy and practically pain free.&lt;/p&gt;

&lt;p&gt;Thank you for reading I hope you did enjoy.&lt;br /&gt;
As always comments are welcome and appreciated!&lt;/p&gt;
</description>
        <pubDate>Mon, 17 Jul 2017 18:21:23 -0400</pubDate>
        <link>http://lapinozz.github.io/learning/2017/07/17/compile-time-templated-a-star-pathfinding.html</link>
        <guid isPermaLink="true">http://lapinozz.github.io/learning/2017/07/17/compile-time-templated-a-star-pathfinding.html</guid>
        
        <category>C++</category>
        
        <category>HUOT</category>
        
        
        <category>learning</category>
        
      </item>
    
      <item>
        <title>A 4-bit Calculator made in cardboard and marble</title>
        <description>&lt;h2 id=&quot;logic&quot;&gt;LOGIC&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/LOGIC/logic_name_full.png&quot; alt=&quot;image&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;what-is-it&quot;&gt;What is it?&lt;/h1&gt;

&lt;p&gt;LOGIC is a fully functional 4-bit calculator made entirely out of cardboard, hot glue and marbles. I built it with my little sisters for a science activity, it can add numbers from 0 to 15 for a maximum computable number of 30. We made it from scratch and at the time I didn&apos;t see any of the various kind of calculator that have been made using Lego, wood and other, so it&apos;s a completely new model!&lt;/p&gt;

&lt;h1 id=&quot;why&quot;&gt;Why?&lt;/h1&gt;

&lt;p&gt;Mostly for fun! For some time now I wanted to build an adder but I wasn&apos;t sure how I wanted to do it yet. I was thinking of maybe make it using a water system or with only cardboard. Then my sisters had a science activity where they had to present a science project and I was helping them to choose a subject. I randomly found a video about &lt;a href=&quot;https://www.youtube.com/watch?v=OpLU__bhu2w&quot;&gt;a calculator made with dominoes&lt;/a&gt; and I thought, why not make one with marbles?&lt;/p&gt;

&lt;h1 id=&quot;what-was-learned&quot;&gt;What was learned?&lt;/h1&gt;

&lt;p&gt;My little sisters already knew how to count in binary, through the project they also learned about, binary addition, binary/decimal conversion, logic gates, basic logic circuits, and more.&lt;/p&gt;

&lt;p&gt;I also learned how simple it can be to build logic circuits using simple material lying around. As in all my projects, I always try do with what I already have.&lt;/p&gt;

&lt;h1 id=&quot;what-does-it-look-like&quot;&gt;What does it look like?&lt;/h1&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/LOGIC/LOGIC-low.jpg&quot; alt=&quot;image&quot; style=&quot;max-height:600px&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;woah-how-do-you-use-it&quot;&gt;Woah, How do you use it?&lt;/h1&gt;

&lt;p&gt;You place your input numbers as binary in the inputs, a marble is a one, no marble is a zero.
The bit on the right is the least significant bit. You have to reset some part of the calculator before each calculation too.
Then you remove the little bit of cardboard that kept the marbles from running down and they will slide along the paths, moving and changing the paths as they go, to finally arrive at the outputs at the bottom, giving you the result, as binary again.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/LOGIC/LOGIC-IO-low.jpg&quot; alt=&quot;image&quot; style=&quot;max-height:600px&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Here&apos;s an example of input if you wanted to add 7 plus 5.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/LOGIC/LOGIC-7-plus-5-low.jpg&quot; alt=&quot;image&quot; style=&quot;max-height:600px&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;how-does-it-work&quot;&gt;How does it work?&lt;/h2&gt;

&lt;p&gt;When we were reflecting on how to make the logic gates we needed, we always started by stating what the gate is doing in common term. The first gate we did was the AND gate.&lt;/p&gt;

&lt;h1 id=&quot;and-gate&quot;&gt;AND gate&lt;/h1&gt;

&lt;p&gt;So what do a AND gate does? Basically:&lt;/p&gt;

&lt;p&gt;If there is no marble in: no marble out&lt;br /&gt;
If there is one marble in: no marble out&lt;br /&gt;
If there is two marble in: one marble out&lt;/p&gt;

&lt;p&gt;So we needed a system that let one marble pass if there is two else it there is none out.&lt;br /&gt;
Here&apos;s what we came up with.&lt;/p&gt;

&lt;p&gt;One marble: no output&lt;br /&gt;
&lt;img src=&quot;/assets/image/LOGIC/AND-1.gif&quot; alt=&quot;image&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Two marbles: one output&lt;br /&gt;
&lt;img src=&quot;/assets/image/LOGIC/AND-2.gif&quot; alt=&quot;image&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;xor&quot;&gt;XOR&lt;/h1&gt;

&lt;p&gt;The XOR was a bit more complicated because the inputs had to be at the exact same time.&lt;/p&gt;

&lt;p&gt;So how do we model an XOR? Simple!&lt;/p&gt;

&lt;p&gt;If you have one marble than it pass&lt;br /&gt;
If you have two marbles then they should cancel out&lt;/p&gt;

&lt;p&gt;We imagined that it would be quite simple to have them cancel out. Put a path only large enough for one marble and when they arrive they collide and keep each other falling in the path. The problem is that they have to be in perfect synchronization and even when it&apos;s the case they bounce and usually they get out anyways.&lt;/p&gt;

&lt;p&gt;We still managed to make one but it was so unreliable that we decided to move on and to just let it be as a prototype as we might not need it at the end.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/LOGIC/XOR.gif&quot; alt=&quot;image&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;half-adder&quot;&gt;Half-Adder&lt;/h1&gt;

&lt;p&gt;AND and XOR gates we would have needed 16 AND gates, 16 XOR gates and 4 OR gates which would have made it just way too big and we didn&apos;t have to make all those.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/LOGIC/Half-Adder-Circuit.gif&quot; alt=&quot;half adder circuit&quot; /&gt;&lt;/p&gt;

&lt;p&gt;That&apos;s where thinking the gates in common terms comes handy, for a Half-Adder it would be:&lt;/p&gt;

&lt;p&gt;If there is one marble: make it fall in the first output&lt;br /&gt;
If there is two marbles: make one of them fall in the second output&lt;/p&gt;

&lt;p&gt;It actually wasn&apos;t too hard to make one. The first marble flip a little piece of cardboard, so if there is a second marble it fills fall in a hole. That second marble lands on another flip which block the first one.&lt;/p&gt;

&lt;p&gt;For one marble you can see it fall in the 1 path&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/LOGIC/Half-Adder-1-cropped.gif&quot; alt=&quot;image&quot; /&gt;&lt;/p&gt;

&lt;p&gt;For two marble you can see it fall in the 2 path&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/LOGIC/Half-Adder-2-cropped.gif&quot; alt=&quot;image&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The one begin the sum and the two begin the carry.&lt;/p&gt;

&lt;h1 id=&quot;full-adder&quot;&gt;Full Adder&lt;/h1&gt;

&lt;p&gt;A Full-Adder is normally made of two Half-Adder and one OR gate. We were really surprised to see that we could make one by modifying only slightly our Half-Adder. In common term the Full-Adder is the same as a Half-Adder apart that if there is a third marble, then it should fall in the 1 path.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/LOGIC/two-half-adder.png&quot; alt=&quot;image&quot; /&gt;&lt;/p&gt;

&lt;p&gt;If there is one marble: make it fall in the first output&lt;br /&gt;
If there is two marbles: make one of them fall in the second output&lt;br /&gt;
If there is three marbles: make one the fall in the first output and another in the second&lt;/p&gt;

&lt;p&gt;It was really easy to add the third case to our Half-Adder model, literally only one little piece of cardboard needed to be added. The reason our Full-Adder looks so different is because we edited it to allow for more time between the first and second marble thus lowering the synchronicity requirement.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/LOGIC/Full-Adder-IO-low.jpg&quot; alt=&quot;image&quot; style=&quot;max-height:600px&quot; /&gt;&lt;/p&gt;

&lt;p&gt;So for one marble it falls in path 1&lt;br /&gt;
&lt;img src=&quot;/assets/image/LOGIC/Full-Adder-1-cropped.gif&quot; alt=&quot;image&quot; /&gt;&lt;/p&gt;

&lt;p&gt;For two marble one of them fall in path 2&lt;br /&gt;
&lt;img src=&quot;/assets/image/LOGIC/Full-Adder-2-cropped.gif&quot; alt=&quot;image&quot; /&gt;&lt;/p&gt;

&lt;p&gt;And finally for three marble one of them fall in path 1 and another in path 2&lt;br /&gt;
&lt;img src=&quot;/assets/image/LOGIC/Full-Adder-3-cropped.gif&quot; alt=&quot;image&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;putting-it-all-together&quot;&gt;Putting it all together&lt;/h2&gt;

&lt;p&gt;Now that we can make Full-Adder we can finish our calculator. We just had to connect them so that the carry out go to the carry in of the next.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/LOGIC/Full-Adder-circuit.jpg&quot; alt=&quot;image&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;the-problem&quot;&gt;The Problem&lt;/h1&gt;

&lt;p&gt;Even if each Half-Adder and Full-Adder we made were working properly, once all glued together the calculator had problem working. Marbles would go too fast or too slow, they would bounce off and that sorts of things. This is not to say that it can&apos;t work, the calculator work but you have to try multiple time before everything go the way it supposed to be. The logic itself is flawless, it&apos;s just that cardboard turn out to not always be the most practical and require a lot of adjustment, we just couldn&apos;t finish all the adjustment on time.&lt;/p&gt;

&lt;h1 id=&quot;done&quot;&gt;Done!&lt;/h1&gt;

&lt;p&gt;We built two more Full-Adder and the rest are just path so that the marbles go to the correct inputs and outputs!&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/image/LOGIC/LOGIC-gates-low.jpg&quot; alt=&quot;image&quot; style=&quot;max-height:600px&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h1&gt;

&lt;p&gt;After finishing this project I searched if others had made similar constructions and was amazed by the diversity and the creativity. One thing I noticed was that in most mechanism using balls, you entered the number by setting the flips and you had to have a lot of ball running down, in our model you set the input numbers using directly the marbles position and count. This is closer to how it works in computer and it seems to me that it would be easier to incorporate in bigger project. I&apos;m already thinking of how I could make a minimalist marble computer or a Turing machine.&lt;/p&gt;

&lt;p&gt;Thank you for reading I hope you did enjoy.&lt;br /&gt;
As always comments are welcome and appreciated!&lt;/p&gt;
</description>
        <pubDate>Sat, 19 Nov 2016 12:37:23 -0500</pubDate>
        <link>http://lapinozz.github.io/learning/2016/11/19/calculator-with-caordboard-and-marbles.html</link>
        <guid isPermaLink="true">http://lapinozz.github.io/learning/2016/11/19/calculator-with-caordboard-and-marbles.html</guid>
        
        <category>Mechanical Computing</category>
        
        
        <category>learning</category>
        
      </item>
    
      <item>
        <title>Facechat - Custom chat api</title>
        <description>&lt;h2 id=&quot;facechat&quot;&gt;Facechat&lt;/h2&gt;

&lt;h1 id=&quot;why&quot;&gt;Why?&lt;/h1&gt;

&lt;p&gt;If you followed my previous post you may know that I tend to go on &lt;abbr title=&quot;Internet Relay Chat&quot;&gt;IRC&lt;/abbr&gt; and that we have there some pretty cool bots. I was swapping between a conversation on &lt;abbr title=&quot;Internet Relay Chat&quot;&gt;IRC&lt;/abbr&gt; and one on Facebook when an idea struck me, how cool would it be to have those bots functionalitys directly in Facebook&apos;s chat? And even better, how about reading and writting Facebook&apos;s messages in &lt;abbr title=&quot;Internet Relay Chat&quot;&gt;IRC&lt;/abbr&gt; chat or reading and writing &lt;abbr title=&quot;Internet Relay Chat&quot;&gt;IRC&lt;/abbr&gt;&apos;s messages on Facebook? Awesome!&lt;/p&gt;

&lt;h1 id=&quot;why-unofficial&quot;&gt;Why &quot;Unofficial&quot;?&lt;/h1&gt;

&lt;p&gt;It should be easy, right? Facebook must have an API for sending and receiving messages, surely they have something like a REST API? Well… No. It turns out that they had an XMPP API that they shot down on April 30, 2014 &lt;sup id=&quot;fnref:n&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:n&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;1&lt;/a&gt;&lt;/sup&gt;. They still had a service to read the inbox but they put it down too, exactly one year later on April 30, 2015 &lt;sup id=&quot;fnref:n:1&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:n&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;1&lt;/a&gt;&lt;/sup&gt;. Since there was no official API I had to create my own.&lt;/p&gt;

&lt;h1 id=&quot;how&quot;&gt;How?&lt;/h1&gt;

&lt;p&gt;The idea is that if your browser can connect to Faceboos and send messages, then your program can too, as the browser is just another program. When the you go to Facebook&apos;s login page you receive an html page and some js scripts, when you enter your identifiant and hit enter the scripts generate data to send to the server to make https request to establish a connection. Now a theoretical way our program could do that would be to simulate the whole browser, html parser, js code interpreter etc. The problem with this thechnique is that it makes a big dependency and it does way more than we need, we only need to send and receive specifique https responses and know how to generate/decode them.
To do that we completely forget what our browser is doing and only look at the https request sent to Facebook and the response and we try to guess how they were generated. So rather than trying to execute the js code or understand it, we make our own code, that works in the way we want it. Let me give you an example.&lt;/p&gt;

&lt;p&gt;I open my browser (Firefox) and launch a plugin called &quot;Live HTTPS headers&quot; that logs all https requests my browser makes. I open facebook.com and login then I send a message &quot;test&quot;.&lt;/p&gt;

&lt;p&gt;Here&apos;s the https request that my browser made.&lt;br /&gt;
As you can see, for a question of privacy I obfuscated the user ids.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-txt&quot; data-lang=&quot;txt&quot;&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;POST /ajax/mercury/send_messages.php?
message_batch[0][action_type]=ma-type:user-generated-message
message_batch[0][thread_id]
message_batch[0][author]=fbid:100000*******67
message_batch[0][author_email]
message_batch[0][timestamp]=1467513329087
message_batch[0][timestamp_absolute]=Aujourd&apos;hui
message_batch[0][timestamp_relative]=22:35
message_batch[0][timestamp_time_passed]=0
message_batch[0][is_unread]=false
message_batch[0][is_forward]=false
message_batch[0][is_filtered_content]=false
message_batch[0][is_filtered_content_bh]=false
message_batch[0][is_filtered_content_account]=false
message_batch[0][is_filtered_content_quasar]=false
message_batch[0][is_filtered_content_invalid_app]=false
message_batch[0][is_spoof_warning]=false
message_batch[0][source]=source:chat:web
message_batch[0][source_tags][0]=source:chat
message_batch[0][body]=test
message_batch[0][has_attachment]=false
message_batch[0][html_body]=false
message_batch[0][specific_to_list][0]=fbid:100003*******64
message_batch[0][specific_to_list][1]=fbid:100000*******67
message_batch[0][ui_push_phase]=V3
message_batch[0][status]=0
message_batch[0][offline_threading_id]=6155197026245292939
message_batch[0][message_id]=6155197026245292939
message_batch[0][ephemeral_ttl_mode]=0
message_batch[0][manual_retry_cnt]=0
message_batch[0][other_user_fbid]=100003*******64
client=mercury
__user=100000*******67
__a=1
__dyn=7AmajEzUGByA5Q9UoGya4A5ER6yUmyUyGiyEyfirWo8popyui9zob4q68K5U4e2O3J1ebkwy8wGFeex3BKuEjKeCwxxRa3CnDBxe6rxCLGqu2PxOcxu5ocE88C9z9oybx24o9Esw
__req=17
__be=-1
__pc=PHASED%3ADEFAULT
fb_dtsg=AQG5P4wy1kJ6%3AAQGxD7sfo49g
ttstamp=26581715380521191214910774545865817112068551151021115257103
__rev=2425895
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;That makes a lot of parameters, but actually only a few interests us.&lt;/p&gt;

&lt;p&gt;In particular, line 20, the &quot;body&quot; parameter which is set to &quot;test&quot;, exactly our message!&lt;br /&gt;
Line 4, 23, 24 and 31 are relative to who sent the message and to whom.&lt;br /&gt;
Note: line from 33 to 41 are parameters setup in the login phase, they are used to authentify the connection.&lt;/p&gt;

&lt;p&gt;So in my program if I want to add the functionality to send a message (not taking into account sending photos, files etc, which are attachments) all I have to do is fill in all those parameters which are for the most pretty easy to guess what they mean, easier than trying to read the obfuscated js code anyways. Also, most of the parameters are not required for the request to work, here&apos;s a more minimalist request:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-txt&quot; data-lang=&quot;txt&quot;&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;POST /ajax/mercury/send_messages.php?
message_batch[0][action_type]=ma-type:user-generated-message
message_batch[0][author]=fbid:100000*******67
message_batch[0][source]=source:chat:web
message_batch[0][source_tags][0]=source:chat
message_batch[0][body]=test
message_batch[0][has_attachment]=false
message_batch[0][specific_to_list][0]=fbid:100003*******64
message_batch[0][specific_to_list][1]=fbid:100000*******67
message_batch[0][other_user_fbid]=100003*******64
client=mercury
__user=100000*******67
__a=1
__dyn=7AmajEzUGByA5Q9UoGya4A5ER6yUmyUyGiyEyfirWo8popyui9zob4q68K5U4e2O3J1ebkwy8wGFeex3BKuEjKeCwxxRa3CnDBxe6rxCLGqu2PxOcxu5ocE88C9z9oybx24o9Esw
__req=17
__be=-1
__pc=PHASED%3ADEFAULT
fb_dtsg=AQG5P4wy1kJ6%3AAQGxD7sfo49g
ttstamp=26581715380521191214910774545865817112068551151021115257103
__rev=2425895
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;So if I want to send a message to someone else I just have to replace &quot;test&quot; by the text and put their id (there is a function to find the user id of someone).&lt;/p&gt;

&lt;p&gt;For this example it&apos;s not too hard to guess what the parameters are for but for some function it can get much more confusing. Fortunately. I didn&apos;t have to do all that tiedous work by myself, there is the excellent &lt;a href=&quot;https://github.com/Schmavery/facebook-chat-api&quot;&gt;facebook-chat-api&lt;/a&gt; project in nodejs on which I could refer to help me in my coding.&lt;/p&gt;

&lt;h1 id=&quot;goals&quot;&gt;Goals&lt;/h1&gt;

&lt;p&gt;The goal of the Facechat library is to cover all functionality in a way that you could make your own messenger client with the features as the official and even more. One example of a use case that is not covered by the official client and which I need is downloading a complete conversation. Anyone that&apos;s ever used Facebook Messenger knows that it&apos;s a real pain to read ancient messages and if the conversation is somewhat long then it&apos;s simply impossible to get to the start. So I made a program that download the complete conversation to a file using my lib.&lt;/p&gt;

&lt;h1 id=&quot;difficulty&quot;&gt;Difficulty&lt;/h1&gt;

&lt;p&gt;As mentioned in the previous paragraph I made a concrete program using my lib. But I had some problem, between the time I wrote the lib and the time I got to use it Facebook&apos;s internal working changed and the lib didn&apos;t work anymore. A couple of change and actually a lot of debugging time was required to make it functional again.&lt;/p&gt;

&lt;h2 id=&quot;facebot&quot;&gt;Facebot&lt;/h2&gt;

&lt;p&gt;As I said the original intent for writing this lib was to make a bot with the same functionality as some &lt;abbr title=&quot;Internet Relay Chat&quot;&gt;IRC&lt;/abbr&gt; bots and also to channel Facebook&apos;s messages through &lt;abbr title=&quot;Internet Relay Chat&quot;&gt;IRC&lt;/abbr&gt; and vice versa. And that&apos;s what I did in my Facebot project, here&apos;s a list of the available commands which is pretty easy to extend:&lt;/p&gt;

&lt;p&gt;#.say&lt;/p&gt;

&lt;p&gt;simple command that echo back. eg: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.say text to be echoed&lt;/code&gt;&lt;/p&gt;

&lt;h1 id=&quot;g-google&quot;&gt;.g, .google&lt;/h1&gt;

&lt;p&gt;Google search. eg: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.google how to be as cool as lapinozz?&lt;/code&gt;&lt;br /&gt;
Image search. eg: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.google image cool image&lt;/code&gt;&lt;/p&gt;

&lt;h1 id=&quot;y-youtube&quot;&gt;.y, .youtube&lt;/h1&gt;

&lt;p&gt;Youtube search. eg: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.youtube how to break laws of physic&lt;/code&gt;&lt;/p&gt;

&lt;h1 id=&quot;w-wiki-wikipedia&quot;&gt;.w, .wiki, .wikipedia&lt;/h1&gt;

&lt;p&gt;Wikipedia search. eg: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.wiki proton&lt;/code&gt;&lt;/p&gt;

&lt;h1 id=&quot;tr-translate&quot;&gt;.tr, .translate&lt;/h1&gt;

&lt;p&gt;Translation command. eg: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.tr traduit ce text en englais&lt;/code&gt;&lt;br /&gt;
The default target language is English you can change that like this: &lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.tr fr This text will be translated to French&lt;/code&gt;&lt;/p&gt;

&lt;h1 id=&quot;def-define&quot;&gt;.def, .define&lt;/h1&gt;

&lt;p&gt;Get Definition. eg: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.define paradox&lt;/code&gt;&lt;/p&gt;

&lt;h1 id=&quot;rnd&quot;&gt;.rnd&lt;/h1&gt;

&lt;p&gt;Random, word, sentence or paragraph.&lt;br /&gt;
eg: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.rnd&lt;/code&gt;&lt;br /&gt;
eg: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.rnd sentence&lt;/code&gt;&lt;br /&gt;
eg: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.rnd paragraph&lt;/code&gt;&lt;/p&gt;

&lt;h1 id=&quot;time&quot;&gt;.time&lt;/h1&gt;

&lt;p&gt;Give the current time. eg: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.time&lt;/code&gt;;&lt;/p&gt;

&lt;h1 id=&quot;userid-userid-userid&quot;&gt;.userID, .userId, .userid&lt;/h1&gt;

&lt;p&gt;Get the facebook user id of someone. eg: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.userId Marie Gagnon&lt;/code&gt;&lt;/p&gt;

&lt;h1 id=&quot;userinfo-userinfo&quot;&gt;.userInfo, .userinfo&lt;/h1&gt;

&lt;p&gt;Get the facebook information of someone. eg: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.userInfo Marie Gagnon&lt;/code&gt;&lt;/p&gt;

&lt;h1 id=&quot;tell&quot;&gt;.tell&lt;/h1&gt;

&lt;p&gt;Send a mesage to someone. eg: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.tell Marie Gagnon : you&apos;r so sexy today&lt;/code&gt;&lt;br /&gt;
you can also send to multipel personne eg: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.tell Marie Gagnon | Stephanie Gagnon : im not a cheater&lt;/code&gt;&lt;/p&gt;

&lt;h1 id=&quot;g-gcc-nasm-my-favourite-command&quot;&gt;.g++, .gcc, .nasm (My favourite command)&lt;/h1&gt;

&lt;p&gt;Execute code, yes this use cee from BoxBox :D&lt;br /&gt;
eg: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.g++ {int i; i = 4*5; cout &amp;lt;&amp;lt; i};&lt;/code&gt;&lt;/p&gt;

&lt;h1 id=&quot;choose&quot;&gt;.choose&lt;/h1&gt;

&lt;p&gt;Randombly choose between multiple choice eg: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.choose choice1|choice2|choice3&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;#.irc&lt;/p&gt;

&lt;p&gt;&lt;abbr title=&quot;Internet Relay Chat&quot;&gt;IRC&lt;/abbr&gt; commands&lt;br /&gt;
eg: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.irc join #sfml&lt;/code&gt;&lt;br /&gt;
eg: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.irc part #sfml&lt;/code&gt;&lt;br /&gt;
eg: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.irc send #sfml im too cool for you&lt;/code&gt;&lt;br /&gt;
eg: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.irc send Nyrox im too cool for you&lt;/code&gt;&lt;br /&gt;
Turn on Facebook to &lt;abbr title=&quot;Internet Relay Chat&quot;&gt;IRC&lt;/abbr&gt; eg: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.irc on&lt;/code&gt;&lt;br /&gt;
Turn off Facebook to &lt;abbr title=&quot;Internet Relay Chat&quot;&gt;IRC&lt;/abbr&gt; eg: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.irc off&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If Facebook to &lt;abbr title=&quot;Internet Relay Chat&quot;&gt;IRC&lt;/abbr&gt; is turned on each, when someone send a message to you or you send them a message on Facebook it will automaticly connect a &lt;abbr title=&quot;Internet Relay Chat&quot;&gt;IRC&lt;/abbr&gt; user with their name and send you the message in private, you can then replie to that irc user and it will send that replie on facebook.&lt;/p&gt;

&lt;h1 id=&quot;in&quot;&gt;.in&lt;/h1&gt;
&lt;p&gt;Send message after a certain time eg: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.in 4m 30s tell me this&lt;/code&gt;&lt;br /&gt;
can also send to someone else eg: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.in 4m 30s Marie Gagnon: tell her this&lt;/code&gt;&lt;br /&gt;
or even to mutiple personne eg: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.in 4m 30s Marie Gagnon | Stephanie Gagnon: i already told you nothing happened between your sister and me&lt;/code&gt;&lt;/p&gt;

&lt;h1 id=&quot;limitation&quot;&gt;Limitation&lt;/h1&gt;

&lt;p&gt;One down side of Facechat is that, contrary to the case where Facebook would have an public API, you can&apos;t use an authentification token, the library user must provide his login credentials which can make it harder for the user to trust the application.&lt;/p&gt;

&lt;h1 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h1&gt;

&lt;p&gt;It was a fun project and I plan to add more functionality, if you have any idea or suggestion feel free to contact me by email.&lt;/p&gt;

&lt;p&gt;Thank you for reading I hope you did enjoy.&lt;/p&gt;

&lt;div class=&quot;footnotes&quot; role=&quot;doc-endnotes&quot;&gt;
  &lt;ol&gt;
    &lt;li id=&quot;fn:n&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;&lt;a href=&quot;https://developers.facebook.com/docs/chat&quot;&gt;facebook docs&lt;/a&gt; &lt;a href=&quot;#fnref:n&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt; &lt;a href=&quot;#fnref:n:1&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;sup&gt;2&lt;/sup&gt;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;
</description>
        <pubDate>Tue, 07 Jun 2016 17:05:23 -0400</pubDate>
        <link>http://lapinozz.github.io/learning/2016/06/07/facechat-facebook-chat-api.html</link>
        <guid isPermaLink="true">http://lapinozz.github.io/learning/2016/06/07/facechat-facebook-chat-api.html</guid>
        
        <category>C++</category>
        
        <category>Networking</category>
        
        <category>IRC</category>
        
        
        <category>learning</category>
        
      </item>
    
      <item>
        <title>Lazy Theta* Any Angle Pathfinding</title>
        <description>&lt;h1 id=&quot;any-angle-pathfinding&quot;&gt;Any angle pathfinding&lt;/h1&gt;

&lt;p&gt;To get smooth path there is a widely used method of using A* and then smoothing the path. Theta* is an any angle pathfinding algorithm, which mean that it allow for a path between two nodes even if they are not neighbors as long as there is a direct line of sight between them.&lt;/p&gt;

&lt;p&gt;Examples of grid path(left) vs shortest path(right)
&lt;img src=&quot;http://aigamedev.com/static/tutorials/aap-navmesh.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;theta&quot;&gt;Theta*&lt;/h1&gt;

&lt;p&gt;Where in A* a node parent&apos;s must be a neighbor, the idea behind Theta* is that a node parent&apos;s can be any other node. So in A* we take the node in the open queue with the lowest g-value and for each of its neighbors, we check if the g-value of the current node plus the cost to travel from that node to the neighbor is inferior to the current cost of the neighbor. If so, we set the neighbor parent to the current node and update its g-value.&lt;/p&gt;

&lt;p&gt;Here&apos;s a pseudo code for A* (note that most image were taken from &lt;a href=&quot;http://aigamedev.com/open/tutorials/theta-star-any-angle-paths/&quot;&gt;this page&lt;/a&gt; and &lt;a href=&quot;http://aigamedev.com/open/tutorial/lazy-theta-star/&quot;&gt;this one&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://aigamedev.com/static/tutorials/aap-AStarCode.png&quot; alt=&quot;pseudo code&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Now for Theta* the only difference is in the ComputeCost function. What we add is a line of sight check between the neighbor and the parent of the current node, if there is we check if the g-value of the parent plus the cost to travel from it to the neighbor is inferior to the current cost of the neighbor, if it is then we update the neighbor g-value and set its parent to the parent of the current node. Here the cost is calculated by simple line distance.&lt;/p&gt;

&lt;p&gt;Again, pseudo code of the updated ComputeCost&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://aigamedev.com/static/tutorials/aap-Path2tex.png&quot; alt=&quot;pseudo code&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;lazy-theta&quot;&gt;Lazy Theta*&lt;/h1&gt;

&lt;p&gt;Lazy Theta* is an optimization of Theta* which reduce the number of line of sight check. Rather then doing the line of sight check for each neighbors of the current node we assume that there is a line of sight and check it latter. So for each neighbors, we directly check if it would have a smaller g-value if we set the its parent to the parent of the current node and if it does then set it. And at the step where we fetch the node with the smallest g-value in the open list, before processing its neighbors, we do the actual line of sight. Because it was added to the open list and its parent updated wihtout knowing if there was a line of sight or not. If there is a line of sight between the node and its parent then it&apos;s all perfect and we can skip this step, if there is none, we look at each neighbor in the closed list and set the parent to the one which give the lowest g-value.&lt;/p&gt;

&lt;p&gt;Here&apos;s the complete pseudo code, from left to right for A*, Theta* and Lazy Theta*&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://aigamedev.com/wp-content/blogs.dir/5/files/2013/07/fig53-full.png&quot; alt=&quot;pseudo code&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;implementation&quot;&gt;Implementation&lt;/h1&gt;

&lt;p&gt;I had some theory and even some pseudo code, what could go wrong? Well, I don&apos;t if you can understand line 37/38 of the third code but I sure could not. So when I searched if I could find any code online but pretty much anything I could find was a comparison of different pathfinding algorithm and the code was very dispatched and hard to follow, it would have been hard to make sens of the Theta* code without going over pretty much every other file, plus most of them were implementation of Theta* and I could already make sense of the Theta* pseudo code, what I needed was a source code for Lazy Theta*. I finally found this page http://idm-lab.org/project-o.html which host an archive with code for several any angle pathfinding algorithms. I had to rewrite it pretty much completrly because the code style really did not suit me and I wanted a nice C++14 code.&lt;/p&gt;

&lt;h1 id=&quot;modularity&quot;&gt;Modularity&lt;/h1&gt;

&lt;p&gt;I also wanted the code to be the most modular and reusable as possible so I used the concept of adaptor(shamelessly stolen from a friend of mine &lt;sup id=&quot;fnref:n&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:n&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;1&lt;/a&gt;&lt;/sup&gt;)&lt;/p&gt;

&lt;p&gt;This approach makes it possible to use it for grid, hexagon tiles, polygon map. Really anything where you need to find a path between two points, my friend even told me he was able to reuse his code to find the shortest path between two words.&lt;/p&gt;

&lt;h1 id=&quot;one-last-optimization&quot;&gt;One last optimization&lt;/h1&gt;

&lt;p&gt;Another optimization that was discussed in the article linked above was to use weighted h-value. Remember that the h-value is the heuristic distance between a node and the goal. This method can give slightly longer path, but can also reduce a lot the number of line of sight check. So it simply consists of multiplying our h-value by a weight superior to 1.&lt;/p&gt;

&lt;p&gt;Here&apos;s all the nodes that get checked with on the left a weight of 1(basically no weight) and on the right a weight of 1.1&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://aigamedev.com/wp-content/blogs.dir/5/files/2013/07/lazy_1_11.png&quot; alt=&quot;image&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h1&gt;

&lt;p&gt;My github repo contains the main file, pathfinding.hpp and an adaptor example for tile grid in tileadaptor.hpp (2x AA battery included)&lt;/p&gt;

&lt;p&gt;I also added a demo in main.cpp to show how to use everything, it makes little map and find the path from the start to the end then output it to the console like so:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-txt&quot; data-lang=&quot;txt&quot;&gt;######################################################################
#S   #              #                                                #
#    #              #                                                #
#    #              #                                                #
#    #              #                            2                  3#
#    #              #                             ################## #
#    #              #                                           #    #
#    #              #                                           #4   #
#    #              #                                           # ####
#    #              #                                           #    #
#    #              #                                           #    #
#    #              #                                           #    #
#    #              #                                           #    #
#    #              #                                           #    #
#   0               #                                           #    #
#                   #                                           #    #
#                                 1                             #5   #
#                                                               #    #
#                                                               #   E#
######################################################################
#  = walls
S  = start
E  = end
number = path nodes&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;div class=&quot;footnotes&quot; role=&quot;doc-endnotes&quot;&gt;
  &lt;ol&gt;
    &lt;li id=&quot;fn:n&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;&lt;a href=&quot;http://featherkit.therocode.net/&quot;&gt;feather kit&lt;/a&gt; &lt;a href=&quot;#fnref:n&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;
</description>
        <pubDate>Tue, 07 Jun 2016 17:05:23 -0400</pubDate>
        <link>http://lapinozz.github.io/learning/2016/06/07/lazy-theta-star-pathfinding.html</link>
        <guid isPermaLink="true">http://lapinozz.github.io/learning/2016/06/07/lazy-theta-star-pathfinding.html</guid>
        
        <category>C++</category>
        
        <category>Pathfinding</category>
        
        
        <category>learning</category>
        
      </item>
    
  </channel>
</rss>
