PROJECT REPORT STUDY WEEK "FASCINATING INFORMATICS" Game Platform Mastermind. Abstract. 1 Introduction. 1.1 Mastermind Game Rules

Similar documents
Final Project (Choose 1 of the following) Max Score: A

How to Make Games in MakeCode Arcade Created by Isaac Wellish. Last updated on :10:15 PM UTC

Codebreaker Lesson Plan

Gomoku Player Design

Montgomery Village Arduino Meetup Dec 10, 2016

Getting Started with the micro:bit

Where's the Treasure?

Final Project (Choose 1 of the following) Max Score: A

Connect Four Emulator

EE307. Frogger. Project #2. Zach Miller & John Tooker. Lab Work: 11/11/ /23/2008 Report: 11/25/2008

Circuit Playground Quick Draw

Arduino Lesson 1. Blink. Created by Simon Monk

Part II: Number Guessing Game Part 2. Lab Guessing Game version 2.0

Welcome Show how to create disco lighting and control multi-coloured NeoPixels using a Raspberry Pi.

Power Solutions November 19, 2017

Program Testing and Analysis: Symbolic and Concolic Testing (Part 2) Dr. Michael Pradel Software Lab, TU Darmstadt

THE GUESS OF DEATH. PSEUDOCODE: The logic for my code will be. Dawson Dill 152BC. A less convinient form of analog hangman

From: urmind Studios, FRANCE. Imagine Cup Video Games. MindCube

CRYPTOSHOOTER MULTI AGENT BASED SECRET COMMUNICATION IN AUGMENTED VIRTUALITY

Free Cell Solver. Copyright 2001 Kevin Atkinson Shari Holstege December 11, 2001

Total Hours Registration through Website or for further details please visit (Refer Upcoming Events Section)

EE 307 Project #1 Whac-A-Mole

Bridgepad Swiss Team Guide 2010 BridgePad Company Version 2a BridgePad Swiss Team Manual2d-3c.doc. BridgePad Swiss Team Instruction Manual

Keytar Hero. Bobby Barnett, Katy Kahla, James Kress, and Josh Tate. Teams 9 and 10 1

CPSC 217 Assignment 3 Due Date: Friday March 30, 2018 at 11:59pm

On the front of the board there are a number of components that are pretty visible right off the bat!

1 Lab + Hwk 4: Introduction to the e-puck Robot

Debugging a Boundary-Scan I 2 C Script Test with the BusPro - I and I2C Exerciser Software: A Case Study

Would You Like To Earn $1000 s With The Click Of A Button?

2048: An Autonomous Solver

In this project, you will create a memory game where you have to memorise and repeat a sequence of random colours!

Candidate Instructions

Project Proposal. Underwater Fish 02/16/2007 Nathan Smith,

Would You Like To Earn $1000 s With The Click Of A Button?

In this lab, you ll build and program a meter that measures voltage, current, power, and energy at DC and AC.

Project Documentation for Zombie Trail

Triscend E5 Support. Configurable System-on-Chip (CSoC) Triscend Development Tools Update TM

Overview... 3 Starting the Software... 3 Adding Your Profile... 3 Updating your Profile... 4

Scratch LED Rainbow Matrix. Teacher Guide. Product Code: EL Scratch LED Rainbow Matrix - Teacher Guide

CS151 - Assignment 2 Mancala Due: Tuesday March 5 at the beginning of class

Unit 5: What s in a List

GameSalad Basics. by J. Matthew Griffis

Programming with Scratch

Arduino STEAM Academy Arduino STEM Academy Art without Engineering is dreaming. Engineering without Art is calculating. - Steven K.

Single Error Correcting Codes (SECC) 6.02 Spring 2011 Lecture #9. Checking the parity. Using the Syndrome to Correct Errors

occam on the Arduino Adam T. Sampson School of Computing, University of Kent Matt C. Jadud Department of Computer Science, Allegheny College

Workshops Elisava Introduction to programming and electronics (Scratch & Arduino)

Sudoku Tutor 1.0 User Manual

In this project you ll learn how to create a times table quiz, in which you have to get as many answers correct as you can in 30 seconds.

MATHEMATICAL RELATIONAL SKILLS AND COUNTING

Lab 8: Introduction to the e-puck Robot

Brain Game. Introduction. Scratch

Episode 4 30 th March 2 nd April 2018 Odd Even & Substitution Variations By R Kumaresan and Amit Sowani

CS 354R: Computer Game Technology

Welcome to Arduino Day 2016

2. The Extensive Form of a Game

Lab 2: Blinkie Lab. Objectives. Materials. Theory

Class Projects: Project 2 and Version Control Systems

Web-Enabled Speaker and Equalizer Final Project Report December 9, 2016 E155 Josh Lam and Tommy Berrueta

Section Summary. Finite Probability Probabilities of Complements and Unions of Events Probabilistic Reasoning

Memory. Introduction. Scratch. In this project, you will create a memory game where you have to memorise and repeat a sequence of random colours!

COMPUTING CURRICULUM TOOLKIT

Ada Lovelace Computing Level 3 Scratch Project ROAD RACER

Programming Exam. 10% of course grade

DIGITAL DESIGN WITH SM CHARTS

Arduino Platform Capabilities in Multitasking. environment.

G3P-R232. User Manual. Release. 2.06

Gough, John , Logic games, Australian primary mathematics classroom, vol. 7, no. 2, pp

Blazing 7 s Blackjack Progressive

1. ASSEMBLING THE PCB 2. FLASH THE ZIP LEDs 3. BUILDING THE WHEELS

A Peg Solitaire Font

Editing the standing Lazarus object to detect for being freed

TIGER HOOK 2004 AMCOE INC.

Jamie Mulholland, Simon Fraser University

Pros and Cons for Each Type of Image Extensions

Would You Like To Earn $1000 s With The Click Of A Button?

Using Artificial intelligent to solve the game of 2048

Synthesis of speech with a DSP

INTERFACING WITH INTERRUPTS AND SYNCHRONIZATION TECHNIQUES

Programming an Othello AI Michael An (man4), Evan Liang (liange)

Once this function is called, it repeatedly does several things over and over, several times per second:

MATHEMATICAL RELATIONAL SKILLS AND COUNTING 0 20

INTERNATIONAL JOURNAL OF PURE AND APPLIED RESEARCH IN ENGINEERING AND TECHNOLOGY

RUNNYMEDE COLLEGE & TECHTALENTS

THE APPLICATION OF DEPTH FIRST SEARCH AND BACKTRACKING IN SOLVING MASTERMIND GAME

Software user guide. Contents. Introduction. The software. Counter 1. Play Train 4. Minimax 6

Gta San Andreas Game Manual Pc 100 Complete Cheat Code Ps2

Federico Forti, Erdi Izgi, Varalika Rathore, Francesco Forti

ibingo Game Conditions

While entry is at the discretion of the centre, it would be beneficial if candidates had the following IT skills:

Electronics Merit Badge Kit Theory of Operation

Physical Step Sequencer. David Schofield

CURIE Academy, Summer 2014 Lab 2: Computer Engineering Software Perspective Sign-Off Sheet

Game Mechanics Minesweeper is a game in which the player must correctly deduce the positions of

Adafruit SGP30 TVOC/eCO2 Gas Sensor

Connect 4. Figure 1. Top level simplified block diagram.

2018 Student s Guide.

ExtrAXION. Extracting Drawing data. Benefits.

Slitherlink. Supervisor: David Rydeheard. Date: 06/05/10. The University of Manchester. School of Computer Science. B.Sc.(Hons) Computer Science

FACULTY MENTOR Khoshabeh, Ramsin. PROJECT TITLE PiB: Learning Python

Transcription:

PROJECT REPORT STUDY WEEK "FASCINATING INFORMATICS" Game Platform Mastermind Lukas Meili 1, Naoki Pross 2, Luke Stampfli 3 1 Kantonsschule Büelrain, Winterthur, Switzerland, 2 Scuola Arti e Mestieri Bellinzona, Ticino, Switzerland, 3 Kantonsschule Wattwil, St. Gallen, Switzerland. Supervised by: Dominik Link Date:13 September 2017 Abstract The Mastermind Game Platform is a multi use arcade electronic platform designed and built during a study week organized by the Swiss Youth in Science Foundation. The goal of the project is to design both a hardware and a software for an electronic version of the classic board game Mastermind, to then extend by adding an algorithm that plays on its own. The software is implemented in Python 3 running on a MicroPython compatible microcontroller ESP32 by Espressif while the hardware is connected with a PCB (Printed Circuit Board) or a VeroBoard for prototyping. Many technical challenges were encountered such as limited dynamic memory and hardware failures but the final prototype was complete with all of the previously mentioned features. 1 Introduction The goal for our project is to prepare a working prototype for an electronic version of a classic board game called Mastermind. The secondary goal is to implement an algorithm that plays the game on its own, possibly better than how human would. Lastly a third objective is to extend the platform be able to run other games such as Tetris or Snake. 1.1 Mastermind Game Rules Mastermind is a two player game, where one player known as the code maker prepares a secret code, and the other is the code breaker whose job is to guess the code within a finite number of attempts [4]. The code is represented by colors with plastic or wood pegs. The classic variant has a code of 4 pegs of 6 colors and a maximum of 12 attempts. To begin, the code breaker sets a code, then the code maker gives a feedback (hint) based on the following rules by placing a peg on the side of the board. Figure 1: A classic set of Mastermind [6] 1

There is a correctly colored peg in the correct position. There is a correctly colored peg, but in the wrong position. Note that the hint does not indicate which pegs are correct or wrong. The code breaker wins when he discovers the code, or loses if he runs of out of attempts. 1.2 Platform requirements The game platform will need to replicate the features of the original game. Since it is electronic, the platform should also augment the game to be be playable only with one player, with the computer being either the code maker or the code breaker. Finally the platform should offer intuitive controls that need little or no explanation. 2 Materials and methods 2.1 Hardware and software The main processing unit for the Digital Mastermind is an ESP32 microcontroller by Espressif, and the pegs are represented on a display composed of 3 Adafruit NeoPixel LED Matrices which in total give a screen of 8 by 17 pixels. To receive the users input there are 4 pushbuttons on the top with an integrated LED in each of them. Figure 2: Render of the final product in AutoDesk 360 Figure 3: Final 3D printed prototype The software for the project is written entirely in Python 3 with JetBrains IDE PyCharm CE. On the microcontroller board, the code is run by MicroPython, a small implementation of Python 3 that offers a subset of the Python standard library and many feature to control lower level hardware components. The case for the electronic Mastermind was made for the project and is entirely 3D printed with an Ultimaker printer. Two types of plastic were used for the print: PLA and PETG. Other software tools were also used. MobaXTerm is a set of tools for remote computing, in our case it was used as a serial terminal to communicate with the microcontroller. AMPY, which stands for Adafruit MicroPython Tool, allows to write, read and list files that are present in the MicroPython File System; We used it to upload our code onto the microcontroller. 2

2.2 Design decisions Because of some hardware limitations the implementation of Mastermind differs slightly from the original game. The display has 16 columns so in our version the Code Breaker has 16 attempts before losing instead of 12. 2.3 Team organization The work was split up in 3 parts: Hardware, Software and Algorithm. Naoki designed the electrical scheme and a printed circuit board. Unfortunately, it wasnt possible to the print it in time for the end of the week, so we had solder the parts on a prototyping board. Lukas had to implement the game logic for the microcontroller. And Luke implemented an algorithm that solves Mastermind in the least possible number of turns. 2.4 Solver algorithm The algorithm is composed by two parts. The first part validates the attempts from the humap players and keep all still possible combinations of colors in a list. The second part then chooses one of the remainings codes depending on the situation. We first tried to implement Donald Knuth s algorithm [5] which basically creates a huge tree with the best colors to take in every situation. But because of the limited memory on the microcontroller we had to take another less resource expensive approach. The final version of our algorithm works by bruteforcing the game. The solution for each step is computed by running through every color code that is possible and then comparing the result with other constants. To decide which combination to try from its internal list, the following mathematical expression is used. index = sizeof(list) 1 At the end our algorithm was able to solve mastermind with an average of 4.82 turns which is nearly as good as the far more memory consuming alternatives. 2.5 Software design pattern To write the software a pattern called State-machine [3][4] was used since Mastermind and many other similar games can be represented as a sequence of states with predetermined actions. A secondary reason is that State Machines make it easier to add new code to the program. This design decision comes handy if someone wants to add a new game or another feature to the project. In our implementation of Mastermind there are 9 states: codesetting, autocodesetting, codeguess, autocodeguess, check, won, lost, waitingforreset and reset. 3

Figure 4: State diagram for the Mastermind code codesetting: Here, the Code Maker sets his code. After the Player sets up his code, the program will hide the code and switch to the codeguess state. autocodesetting: As mentioned before this state emulates the Code Maker. It generates 4 random colors for the code for a single player mode. As soon as the code is set, the program will clear the code and then switch to the codeguess state. This state can be entered by pressing button 4 while in codesetting state. codeguess: Here the codebreaker can try his best to break the code. Like in the codesetting state the player can skip through the various colors and confirm with the same buttons with the exception of button 4 that now works as a game reset. It switches to the reset state. autocodeguess: This state implements Lukes algorithm that plays the game. It is more a show of than of any use. check: In this state, the program checks the input from the Code Breaker and compares it to the color code of the Code Maker and gives a feedback according to the rules. Green means correct color and correct place, white means just correct color. After this process the the program can switch to either state won, if all colors are correct and on the right place or state outoftries, if the player runs out of attempts. Or if none of the previous conditions are met, the state returns to codeguess. won: This state is simple. It indicates that the Code Breaker has won. Then it switches to the state waitingforreset. outoftries: In this case the Code Breaker loses and the Code Maker wins. It colors all LEDs in red to indicate a GameOver. After that, the program switches to the waitingforreset state. 4

waitingforreset: The program simply wait for button 4 to be pressed. reset: Once this state is called, it resets all variables and LEDs and goes back to the codesetting state. 2.6 Easter egg Since we had some spare time the LED Matrix is able to show moving GIFs. Any image can be uploaded with a GIF to byte array conversion tool we programmed. The program converts any a 16 by 8 pixels animated GIF file to an array of frames that contain 3 bytes for each pixel. This should be a secret state that is only accessible through a secret color combination while in codesetting state. When the correct combination is entered a secret moving low resolution GIF will appear on the LED Matrix as easter egg. 3 Results In the end, a working Mastermind electronic game prototype was produced. player 1 can set a color code and player 2 place guesses on how the color code looks. The system returns a feedback consisting of the amount of correct placed colors (green) and wrong placed colors (white). There is also a single player mode implemented where the computer generates a random color-code on its own. Also a secret feature was implemented. 4 Discussion 4.1 Technical challenges 4.1.1 Debugging Debugging the software was difficult because the code was executable only on the microcontroller due to missing libraries. A software debugger couldnt been attached because the program could only run on the microcontroller. 4.1.2 Random number generator The random number generator in the ESP32 microcontroller does not generate pure random numbers. Like in many electronic devices actually it uses a pseudo random generator function that needs a starting seed value. To get a truly random value to use as a seed the uptime counter was used since the measure, in microseconds, depends on the time the user spends in the codesetting state. 4.1.3 Memory limitations As mentioned before, the platform was intended to implement the auto solve algorithms. But unfortunately the ESP32 is not able to perform this task because it does not have enough dynamic memory (RAM) to store the informations needed to compute the solution. It is still possible to run this code on a separate program that does not allow to play the game manually. 5

Some other minor memory related issues were solved by invoking manually the Micropython garbage collector by using the CPython interface, then ESP32 was then able to run the program. 4.2 Hardware failures Problems from hardware failures were also present. Originally the platform controls were intended to be button 1 and button 2 to loop forward or backward through the colors and button 3 to confirm. But button 3 suddenly stopped working in the middle of the project, so it was changed to have button 1 alone to circle through all the various colors while button 2 confirms the selection. 5 Acknowledgements We especially thank the Swiss Youth in Science that made possible to organize this great experience. We also want to thank Markus Knecht and Claude Rubattel for coordinating the study week and our supervisors Dominik Link, Flavio Müller and Manuel Schlatter for supporting us. Last but not least we thank the University of Applied Sciences and Arts, Northwestern Switzerland, School of Engineering for offering the infrastructure to host the event. Softwares ESP32 MicroPython Framework: https://github.com/micropython/micropython-esp32 PyCharm IDE: https://www.jetbrains.com/pycharm/ Adafruit MicroPython Tool: https://github.com/adafruit/ampy MobaXTerm: https://mobaxterm.mobatek.net/ References [1] http://www.pressmantoy.com/game-rules/ultimate%20mastermind%20rules%20(1).pdf [2] https://docs.micropython.org/en/latest/pyboard/ [3] https://en.wikipedia.org/wiki/state_pattern [4] https://en.wikipedia.org/wiki/finite-state_machine [5] http://www.cs.uni.edu/~wallingf/teaching/cs3530/resources/knuth-mastermind. pdf [6] https://my-live-01.slatic.net/p/4/code-breaker-master-mind-mastermind- strategy-board-game-1483679658-39479381-a80c25f5033268e1914a78083757bc07- zoom.jpg Source code The source code and all documents related to the project can be found in a Git repository hosted on Github at: https://github.com/flavio99/mastermind 6