My Analysis of Mine Sweeper Algorithms - theCoderSchool Blog

My Analysis of Mine Sweeper Algorithms

By Laker N., age 14

CodeWars is an online collection of programming challenges ranked by difficulty. It’s community driven, meaning that, though the problems require thinking, they are satisfying to complete. One problem on CodeWars that caught my attention was “Mine Sweeper” by the user myjinxin2015, a prolific creator and the second highest holder of honor, gained by solving and making the site’s code challenges. “Mine Sweeper” is a kyu 1 code challenge, the hardest on the site. (Kyu, or difficulty, ranges from 1 to 8, with 8 as the easiest and 1 as the hardest.)

Despite its ranking, I’ve always liked the idea of Minesweeper. “Mine Sweeper,” however, didn’t involve programming the game; “Mine Sweeper” is kyu 1, because the task is to program an algorithm to solve Minesweeper. Specifically, given a board configuration with a number of the squares identified, fill in the rest.

Though the problem intrigued me, I was at a loss for how to attack it. After some brainstorming, however, I came up with a rule my algorithm could apply to a board configuration to solve unknown squares. If a square has as many empty tiles around it as it needs mines to fulfill its number, then all surrounding squares are mines. If a square needs no more mines, then all unknown surrounding tiles are safe. In code, I assigned each tile the number of mines needed to satisfy its number minus the number of mines already flagged around it. This number I called the tile’s working number. For example, a tile with the number three and two flagged mines around has a working number of one: any unknown tiles around it can act as though it only needs one mine. With working numbers, a tile with number five, three mines flagged around it, and two remaining unknown tiles knows to flag all surrounding unknown tiles. I call the first rule Easy Logic, because most Minesweeper players rely on it before thinking harder.

Private+Semi-Private Coaching

Virtual Learning

Coding Classes

Robotics

Python

Scratch

Video Game Coding



What is theCoderSchool? We are an after-school drop-off (and virtual) program for kids learning to code - a coding school! There's after-school kung fu. There's after-school music lessons, sports, art, tutoring, Chinese, you name it, it's out there. But coding for kids? We're among the first of many, and the largest in Silicon Valley with more locations on the way around the country. The future will be ever more dependent on technology so let's get our young generation ready. Learn to Code, Change the World®.

For questions about partnerships, curriculum, schedule, camps, or other operational inquires, please contact your nearest school.
For national franchise questions only, email us at info@thecoderschool.com. Please include the city/state you're writing from.

copyright 2014-2022, the Coder School San Francisco, LLC. All Rights, Alright? Don't forget our privacy policy. Find out who we are or like us on facebook.