## Coding Battleship with Game Theory

By Noah S., Age 16

Game theory is actually not the name of a youtube channel. It is, but that term is actually derived off a complex study called “Game Theory”. Game theory is the study of interactions between intelligent “things”. Whether this thing is a human, AI, or some other kind of rational thinking thing it up to you. Game theory is most commonly used in political science and economics, although its use can also be widened to cover topics like logic and computer science. This is what I researched while I made my battleship, which utilized 2 intelligent things as well, the player (you) and the AI. This topic is very broad, so I will discuss some examples and try to tie them together at the end of this post.

One famous study of game theory is the “prisoner’s dilemma”. Two prisoners, A and B, are being interrogated for the same crime. If both prisoners rat each other out, they get 5 years of prison. If A rats out B, A is set free while B must serve 10 years, and vice versa. If they both stay quiet, however, they each only have to serve 2 years in prison. Even though they both have a significantly better outcome if they both stay silent, the probability of them cooperating is actually very low, and the odds of at least one of them ratting the other out is significantly high. While the reasons are really implied since there is no direct answer (like how in english class there are many ways to interpret something, while in math there is only 1 answer), the risk of getting rewarded by being set free outweighs all other costs, including not receiving the most severe punishment of 10 years, leads many to do so. In addition, mistrust of the other also magnifies this effect.

Another example is battleship. I actually made a program that runs battleship with a complex AI. The board layout is actually determined both a combination of statistics and game theory. When playing battleship, one of the player’s primary goals is to aim for more open spaces to shorten the game and give themselves a better chance at winning. But where should a player aim to give themselves the largest chance at hitting a target? This is determined by game theory. While there is no way to play battleship to give yourself a 100% chance at winning, as it is a luck-based game, there are spots you can fire that give yourself a slight edge. For example, if you see a 4 space opening, you know that a carrier (5 slots) cannot fit there. If you see a spot completely surrounded on all sides by misses, you know that there cannot be a ship in there, and as a result that space may as well count as a miss. This is what I coded into the AI in my battleship game to make it more human-like. By covering the board with probabilities of locations that are most likely to harbor a ship (pun intended) in relation to the amount of ships left and the different types they are, a player (or AI) can use game theory to their advantage to win the game.

To tie these together, game theory is a super broad study that has many different uses. Anything that requires an interaction between intelligent beings all comes back to this idea of game theory. Being able to mathematically predict the most possible and reasonable outcome is very useful in many occupations. I hope I can apply game theory to many different projects in the future. But for now, I will continue to improve upon the battleship game I am making right now.

## How a Coding Background Offers Work/Life Success

Imagine a skill that would make you more marketable as a job candidate and increase your earnings potential. Now envision that you can start learning this skill at any age and at any time. Of course, we are referring to coding. Having a background in coding will open doors to dream careers with outstanding future possibilities. If you need more convincing here are four reasons that coding improves your chances for success.

# Exceptional high-paying career opportunities

STEM jobs are all the rage in our modern economy, and yes that includes coding. A study conducted by Burning Glass revealed careers that require coding pay an average of \$22,000 more per year. Just imagine, in ten years that would equate to \$220,000. The same study also found that half of the highest paying jobs (in the top quartile) require coding skills. A rewarding career that makes more money chalk one up to coding.

# Flexibility

Would you like a career that would enable you to work from home either part- or full-time? Jobs in coding tend to offer flexible schedules allowing you to work from just about anywhere. A high paying career that allows you to choose your work environment and, in some cases, even your schedule is appealing to those who want to spend more time with family or travel to other cities. Or perhaps someone who just doesn’t enjoy the office life. Regardless, having a background in coding provides more opportunities for high-paying jobs that offer more flexibility.

# Choice of industries

Whether you want a job in technology, banking or health care, having a background in coding will help you land a great career. Looking for more excitement? Being a skilled coder can catapult you into a cool, fast-paced field like artificial intelligence. A field that is growing at a rapid rate. A report by the World Economic Forum states that AI will create 58 million new jobs by 2022. You can work on the cutting-edge helping to develop new technologies that will shape the future world. No worries if you opt to steer clear of advanced fields like AI, with a background in coding you’ll have your choice of incredible industries.

# Coding improves your problem-solving abilities

Beyond providing a tangible skill you can add to your resume, coding can teach you to become a better thinker with improved problem-solving abilities. Why? Because coding takes attention to detail and an ability to break down problems into smaller pieces. This approach can be utilized in different areas of your professional and personal life. The more you practice coding and solving the issues that arise, the more skilled you will become at tackling problems.

From high-paying job opportunities to more flexibility and even improved problem solving, coding is a skill that will increase your chances for success in business and life. Don’t wait, start your coding journey today and get ready for an amazing future.

## Tips for Learning Coding Languages

Learning a new language can be difficult, no matter the origin. That’s not to say that it’s impossible! We have put together some tips for learning almost any coding language:

First off, there are over 100 languages that coders and programmers use (actually, we’ve heard that there’s even more than 2,000, and that’s just because languages are developing every single day!), so don’t feel overwhelmed. You can just simply pick from a list of 10, or whatever serves your coding goals best! Some of the most popular are JavaScript, Python, Java, Go, Elixir, Ruby, Kotlin, TypeScript, Scala, and Clojure.

You know what one you want to learn? Great! (If not, don’t stress, these tips apply to ALL languages.)

# 1. Actively practice.

You can’t just read something and then let it be. You have to continuously keep practicing and using the language in order to become fluent in it. A fun way to practice is by solving coding challenges. There are websites such as LeetCode that can help you increase your fluency, and will teach you more about the structure and syntax of the language.

# 2. Write things down.

While typing on a keyboard is the way you’ll be using the coding language in the future, writing it down helps burn it into your memory and store it somewhere where you can easily access it. We’re no brain experts, but have you ever noticed that you remember something better after writing it down? That’s why. Give it a shot!

# 3. Don’t over-do it.

It’s exciting, yes, but we’re not machines. Our brains need a break — even though it’s for fun, and you WANT to do it. You still need a break, to give your mind time to store what you’ve learned, give your eyes a rest, and get the blood moving through your body again. Don’t be a coding zombie.

While you might not understand the language as a whole yet, reading the language in question — and reading a LOT — can’t hurt, because you’ll find yourself picking up on things as you go. Eventually you’ll train yourself to read almost effortlessly.

# 5. Build something!

Use the language that you’ve learned, and use it often! Even if it’s in something small, you’re still applying the knowledge that you’ve gained, and making it part of your life. This ultimately helps build fluency and recognition.

# 6. Use a linter.

Linters are code-analyzing tools that flag any errors or bugs you may have created in your newly-learned coding language, so that way you can go back and fix the problem. Think of it as a SpellCheck for coding.

It might be hard to do at first, but don’t give up! Once you beat that learning curve, you’ll find that learning these new languages is fun and effective! Go on! Try it!