Trump's algorithm is to say semi-random things until his crowd roars its approval, then he iteratively modifies those statements, seeking more and more approval, until he maxes out and tries a new tack.
This is one of the core strategies of machine-learning: random-walking to find a promising path, hill-climbing to optimize it, then de-optimizing in order to ensure that you haven't plateaued at a local maximum (think of how an ant tries various directions to find a food source, then lays down a chemical trail that other ants reinforce as they follow it, but some will diverge randomly so that other, richer/closer food sources aren't bypassed).
It also betrays one of the core problems with machine learning: bias in the sample-set. The people that Trump relies upon to give him his success feedback are the people who show up for Trump rallies, who are the most extreme, least-representative group of potential Trump voters. The more Trump optimizes for this limited group, the more he de-optimizes for the rest of the world.
Biased training data is a huge (ahem, yuge) problem for machine-learning. Cities that use data from racist frisking practices to determine who the police should stop end up producing algorithmic racism; court systems that use racist sentencing records to train a model that makes sentencing recommendations get algorithmic racism, too.
Trump is a salesman -- he says whatever he thinks his audience wants to hear. That's why he's contradicted every position he's ever espoused. He randomwalked into a strategy of saying things that an underserved, vocal group of bigots wanted to hear, and they fed back their approval and he's been death-spiraling ever since.