Machine Learning – Top Trumps Game

The purpose of this post is to demonstrate a basic example of how machine learning works.

In this example, the computer learns how to play a game of Top Trumps more effectively to increase its chance of winning the game.

It does so by running a learning sequence. During this learning sequence its machine learning algorithm pick two random cards from the deck and compare them against a random criteria.

Based on which card wins the round, it updates its knowledge base accordingly. By repeating this process many times (number of iterations), the algorithm records in its knowledge base statistics for each category of each card. (Probability of winning the round)

The algorithm hence progressively learns which criteria has the highest probability of winning and records this information for each card of the deck.

These probabilities become more accurate when you increase the number of iterations of the learning sequence.

Use the buttons provided in the code pen below to show the impact of the learning phase on the knowledge base.

See the Pen Machine Learning Top Trumps by 101 Computing (@101Computing) on CodePen.

Machine Learning?

Let’s consider the following definition of Machine Learning:

“A computer program is said to learn from experience E with respect to some task T and some performance measure P, if its performance on T, as measured by P, improves with experience E.” — Tom Mitchell, Carnegie Mellon University

Let’s apply this defintion to our Top Trumps Machine Learning algorithm:

  • E: (The Experience/learning sequence): The experience consists of randomly picking two cards and comparing them against a criteria to see which card would win the round.
  • T: (The Task): Playing a full game of Top Trumps against an end-user.
  • P: (The Performance Measure): The probability of winning the game.

In our example, the probability (P) of winning a game of Top Trumps (T) increases with the number of iterations of the learning sequence (Experience E).

So we effectively have a machine learning algorithm.

Obviously, with a fixed data sets of 9 cards and 4 criteria per card, the learning is limited. More complex scenarios use a similar approach with larger data sets which are often open/limitless and where the computer can constantly learn and improve the accuracy of its knowledge base by either analysing existing data sets or populating new data by interacting with real end-users/human beings.

Next Step?

To complete this algorithm, the next step would be to implement the playing phase, where the computer should use its knowledge base to play against an end-user.

Did you like this challenge?

Click on a star to rate it!

Average rating 4.5 / 5. Vote count: 8

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!