## JSweeper

Adding to my collection of clones of popular, well-known games, I created back in November of 2016 a Java-implementation of the all-time Windows classic game, Minesweeper.

Minesweeper was pre-installed on every installation of Windows up to and including Windows 7 and has been ported to a variety of different systems. Because of this, nearly everyone has at least once in their life played Minesweeper or at least heard of it.
In Minesweeper you are presented with a square grid of covered tiles containing either numbers or mines. Your task is it to uncover all tiles which are not mines in the least amount of time. When you uncover a mine, it explodes and the game is lost. To aid in figuring out which tiles are mines and which are not, every tile that is not a mine tells you how many mines are in the neighbouring eight tiles. Tiles which have no neighbouring mines are drawn gray and uncover neighbouring non-mine tiles once uncovered.
More on Minesweeper can be found in this Wikipedia article — I am linking to the German version, as the current English version has major flaws and lacks crucial information. If you are so inclined, feel free to fix the English Minesweeper Wikipedia article.

In my clone, there are three pre-defined difficulty levels, directly ported from the original Minesweeper game, and an option to freely adjust the board’s width and height as well as the number of bombs which will be placed. Gameplay is nearly identical to the original, as my clone also uses a square grid and the tile’s numbers correspond to the number of bombs in the eight tiles surrounding that tile.
The game has a purposefully chosen pixel-look using a self-made font to go along with the pixel-style.

#### Controls

• Arrow keys and enter to navigate the main menu
• Arrow keys or mouse movement to select tiles
• Space, enter or left-click to expose a tile
• ‘f’ or right-click to flag a tile
• ‘r’ to restart game when game is either won or lost
• F11 toggles fullscreen

To play the game, you can either download the .jar file or compile the source code for yourself. The source code is listed below and can be downloaded as a .java file.

``````// Java 1.6 / 1.8 code
// Jonathan Frech  5th of November, 2016
//         edited  7th of November, 2016
//         edited 11th of November, 2016
//         edited 13th of November, 2016
//         edited 14th of November, 2016
//         edited 15th of November, 2016
//         edited 17th of November, 2016
//         edited 19th of November, 2016
//         edited 19th of May     , 2017
//         edited 22nd of May     , 2017
//          * fixed max mine cap when
//            using custom settings``````

## T-3PO — Tic-Tac-Toe Played Optimally

Tic-Tac-Toe, noughts and crosses, Xs and Os, three in a row or whatever you want to call it may be the simplest perfect information game that is enjoyable by humans. Two players set their pieces (X or O) on an 3×3 grid, alternating their turns. The first player to get three of their pieces in a line, wins. If no player succeeds to get a line, the game ends in a draw.

Tic-Tac-Toe’s simplicity may become clear, if you consider that skilled players — people who have played a few rounds — can reliably achieve a draw, thereby playing perfectly. Two perfect players playing Tic-Tac-Toe will — whoever starts — always tie, so one may call the game virtually pointless, due to there practically never being a winner.
Because of its simple rules and short maximal number of turns (nine) it is also a game that can be solved by a computer using brute-force and trees.

The first Tic-Tac-Toe-playing program I wrote is a Python shell script. It lets you, the human player, make the first move and then calculates the best possible move for itself, leading to it never loosing. On its way it has a little chat whilst pretending to think about its next move. The Python source code can be seen below or downloaded here.

The second Tic-Tac-Toe-playing program I wrote uses the exact same method of optimizing its play, though it lets you decide who should begin and is entirely written in JavaScript. You can play against it by following this link.

Both programs look at the entire space of possible games based on the current board’s status, assumes you want to win and randomly picks between the moves that either lead to a win for the computer or to a draw. I did not include random mistakes to give the human player any chance of winning against the computer. Other Tic-Tac-Toe-playing computers, such as Google’s (just google the game), have this functionality.

``````# Python 2.7.7 Code
# Jonathan Frech, 31st of March 2017
#          edited  1st of April 2017``````

## 4096

4096 is a Java-based clone of the well-known web and mobile game 2048, which itself clones 1024 and is similiar to THREES. The naming trend is quite obvious, though note that $2^{12}$ is a power of two where the exponent is divisible by three, futher connecting to the aforementioned game.

In the game, you are faced with a 4×4 matrix, containing powers of two. By swiping in the four cardinal directions (e.g. pressing the arrow keys), you shove all the non-empty cells to that side. When two equal powers of two collide, they fuse together, adding. Once you shoved, an empty tile pseudo-randomly transforms to either a two-tile (90%) or a four-tile (10%).
Your objective at first is to reach the tile 4096, though the real goal is to achieve the highest score. Your score is the sum of all the collisions you managed to cause.

To play 4096, you can either download the .jar file or review and compile the game for yourself, using the source code listed below.

#### Controls

• Up, down, left or right arrow key shoves the tiles
• Escape restarts the game upon a loss
• F11 toggles fullscreen

``````// Java 1.8 Code
// Jonathan Frech,  5th of December 2016
//          edited  6th of December 2016
//          edited  7th of December 2016
//          edited  8th of December 2016
//          edited  9th of December 2016
//          edited 19th of February 2017
//          edited 24th of February 2017
//          edited 28th of February 2017
//          * gave the 4096 tile a color
//          edited 22nd of April    2017
//          * fixed window positioning by changing
//            frame.setLocationRelativeTo(null); to
//            frame.setLocationByPlatform(true);``````

## Jetris CE

This game’s challenge is
to arrange the falling blocks.
Stay alive forever.

Jetris Console Edition is my second Tetris clone (see Jetris for the first one). It is programmed in Python and uses the curses module to display all its graphics on the shell.
Despite it running purely on the shell, I managed to eliminate any noticeable graphics update bugs. Furthermore the code to clear lines differs immensely from Jetris and actually works properly.
To enhance gameplay I implemented the so-called bag method. Instead of choosing pieces at random, a bag gets filled with all seven possible pieces. Each time you get a new piece, that piece gets randomly chosen out of the bag. If the bag is empty, it gets refilled. That way it is ensured that there will be no more than twelve pieces between two identical pieces (worst-case scenario). Also there will no more than four S or Z pieces in a row which makes the game fairer.
The pieces initially fall at one pps (pixel per second) and the game runs at twelve tps (ticks per seconds). Every ten cleared lines the speed increases by one tick or one twelfth of a second until it stays at the minimum speed, one twelfth of a second.
The game’s clock is handled by a thread and graphics updates are made when they are needed (there are no fps).
To achieve the pieces blocky look I used two spaces and a color pair whose background color is the piece’s color. On the shell two fully filled characters look like a square.
You also have the option to change your key bindings — which get saved on disk –, pause the game and there is a high score list — which also gets saved on disk. The files are located where the python code file resides.

``````# Python 2.7.7 Code
# Jonathan Frech 10th of August, 2016
#         edited 11th of August, 2016
#         edited 12th of August, 2016
#         edited 13th of August, 2016
#         edited 14th of August, 2016
#         edited 16th of August, 2016
#         edited 17th of August, 2016
#         edited 18th of August, 2016
#         edited 19th of August, 2016

#         edited 22nd of August   , 2016
#                bug fix: speed
#         edited  6th of September, 2016
#         edited  8th of October  , 2016
#                bug fix: addstr(), curs_set() and move() errors``````

## Web Sudoku Solver

In my last post I used Web Sudoku to get a Sudoku as an example for my solver.

After that I wanted to automate the process of looking up a Sudoku, solving it and typing it in. But while trying to get the Sudoku’s numbers, I noticed that the whole, solved Sudoku was stored in plaintext! (Look at this page‘s source code)
So I just needed to get that information, open the Web Sudoku page in a browser and type in the already solved Sudoku.

To accomplish said goal I used the python module urllib to get the Web Sudoku page’s source code and the module webbrowser to open the page in a browser. To type in the Sudoku I used AutoHotkey.

The finished program takes a level (easy, medium, hard or evil) and an id (the Sudoku’s identification number) to get a Sudoku, create an AHK file, execute it and open a web browser.
All you have to do is to click into the first box, press a key (F1 in this case) and the Sudoku gets solved! You then just need to wait a minute, which is the minimum time Web Sudoku wants you to take to solve a Sudoku, and the AHK script hits enter.
You can get really good times with this.

``````# Python 2.7.7 Code
# Jonathan Frech  9th of August, 2016
#         edited 10th of August, 2016
#         edited 11th of August, 2016``````

## RGB Jallenge

This is a clone of The Great RGB Guessing Challenge.
The challenge works like this: You are presented three numbers ranging from 0 to 255 representing a rgb color and three color bubbles. To get a point you must choose the color bubble corresponding to the rgb values. The more points you get, the higher your score.

#### Controls

• Click on the bubble to choose it

``````# Python 2.7.7 Code
# Pygame 1.9.1 (for Python 2.7.7)
# Jonathan Frech 8th of July, 2016``````

## Jimon

This game is a recreation of the famous game Simon. In the game there are four colors which form a sequence that is expanding every cycle. The aim of the game is to memorize said sequence as far as possible.

#### Controls

• Click on the colored buttons to press them

``````# Python 2.7.7 Code
# Pygame 1.9.1 (for Python 2.7.7)
# Jonathan Frech 24th of June, 2016``````

## Connect Four

Using the programming features given on Texas Instruments’ graphing calculator TI-84 Plus, I created this text-base connect four game.
The code is written in BASIC and can be seen below.
To transfer code to and from the graphing calculator, I used Texas Instruments’ TI Connect™ CE Software.

#### Controls

• Numbers 1 to 7 put your piece accordingly
• ‘clear’ pauses the game (for taking screenshots)

``````"// TI-84 Plus BASIC Code"
"// Jonathan Frech  8th of May, 2016"
"//         edited 13th of May, 2016"``````

## Sliding Puzzle

This is my version of a sliding puzzle.
A sliding puzzle is based on a number of tiles (15 in this case) which are scrambled.
The objective of the game then is to slide the tiles around and get back to the original image.
As an image I took a photo of an apple in front of a black background.

#### Controls

• F1 takes a screenshot
• F2 starts and stops scrambling the image
• F3 solves the puzzle
• Mouse clicks slide tiles

``````# Python 2.7.7 Code
# Pygame 1.9.1 (for Python 2.7.7)
# Jonathan Frech 15th of April, 2016
#         edited 16th of April, 2016``````

## Jappy Jird

This game is a clone of the famous international hit Flappy Bird.
You control the little pixel-bird, while it flaps through three different scenes and tries to avoid deadly pipes. Your score is measured by how many pipes you can pass.

#### Controls

• Escape pauses and resumes the game
• F1 takes a screenshot
• Up arrow keys makes the bird flap

``````# Python 2.7.7 Code
# Pygame 1.9.1 (for Python 2.7.7)
# Jonathan Frech 29th of March, 2016
#         edited 30th of March, 2016
#         edited 31st of March, 2016``````