Teaching the Computer how to play Fruit Ninja

sgl
4 min readJan 19, 2020

--

Fruit Ninja: https://fruitninja.com/dist/images/share_img_large.jpg

Everyone knows fruit ninja. The addictive game that took over the world at the start of the decade. We’ve all played it, we all loved it and we all hated it. It was an amazing game, designed to be easy for everyone to understand but hard enough for people to keep playing it over and over again. But hidden in this addictive game is the use of an important process that we all learn to possess. The process of trial and error, which is coincidentally the basis of reinforcement learning.

What is reinforcement learning?

Reinforcement learning is an area of machine learning that uses trial and error to reach an end result. The agent, the main player of the game, has to achieve a goal in an environment, a scenario, that it is unfamiliar with. In order to come up with a solution to the problem, the computer has to use the process of trial and error to come up with a solution to the problem while only giving it the end result. The goal of the computer is to maximise the reward which in the case of fruit ninja, the goal is to cut up as much fruit as possible while avoiding the bombs.

Bombs in Fruit Ninja

In order for the computer to successfully understand the game, we must give it negative and positive reinforcement. Every time the computer fails to avoid the bomb, it will receive negative reinforcement (i.e. losing a life), which will strengthen its ability to avoid the bombs. On the other hand, each time the computer successfully cuts the fruit, the computer will be able to increase the frequency of this behaviour and cut more fruit.

Reinforcement learning is based on the rewards hypothesis.

“All goals can be described by the maximization of expected cumulative rewards”.

For example, when you are playing a game like fruit ninja, your main focus is to chop up as many fruits and vegetables as possible while avoiding the bombs. Each time you successfully chop up fruit, you are given a point. Each time you touch the bomb you lose a point. Using this reinforcement system, we are able to learn how to play the game successfully while maximising the reward (points earned).

There are several types of Reinforcement learning algorithms,

Value-Based:

Maximise value functions. The value function measures how good it is to be in that state.

By definition, the expected discounted rewards follow the policy, where y is the discount factor:

Policy-based:

Here, you have to try to come up with such a policy that the action performed in every state helps you to gain maximum reward in the future. There are two types of policies — deterministic and stochastic. For the deterministic policy, the same action is produced by the policy π. For the stochastic policy, every action has a certain probability.

Model-based

You must create a specific model for that environment and the agent must learn how to perform in that specific environment.

Just like a small child learning to read, the computer needs reinforcement to know whether what they are doing is right or wrong.

In order to teach the computer what they are doing is right, we give them positive reinforcement. This increases the strength and frequency of the behaviour. This maximises performance and sustains change for a long period of time. The disadvantage of positive reinforcement is that too much can lead to an overload of states which can diminish the results.

To teach the computer that what they are doing is wrong, we give them negative reinforcement. This can increase the behaviour of the algorithm and increases the standard of performance. The disadvantages of negative reinforcement are that it only provides enough to meet up the minimum behaviour.

Reinforcement learning for computers is very much like learning how to play fruit ninja or teaching a small child. It is the basis of Artificial Intelligence and can be applied to many different areas of A.I.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response