Maru: A mediation on loss and loosing

Maru

The Kobayashi Maru of Simon games.

This is the Kobayashi Maru of Simon games. It cannot be beaten. Even if you correctly enter the color pattern of the game into the buttons it will always flash red. Why is this you ask? Because the way that the game understands if you with is by checking the position in an array of the original light pattern against the pattern you input. And the original light pattern numbers are all zeros (because I coded it wrong somehow) so that the numbers you press array is right and not zeros. I will post the code that I wrote and copied and tinkered with for about ten hours or more.

The kobayashi maru of Simon games. from niki selken on Vimeo.
/*Pulled on: Simon Says game by Robert Spann and Combination Lock by Joel Murphy */

#include <EEPROM.h>
int green = 8; //LED connect to digital pin 8
int red = 9; //LED connect to digital pin 9
int yellow = 10; //LED connect to digital pin 10
int blue = 11; //LED connect to digital pin 11

int PushButton = 3; //pushbbutton connected to digital pin 3
int PushButton2 = 4; //pushbbutton connected to digital pin 4
int PushButton3 = 5; //pushbbutton connected to digital pin 5
int PushButton4 = 6; //pushbbutton connected to digital pin 6
int debounce = 10; //Length of time to debounce switch in milliseconds
int ButtonValue2; //used to feel cutrrent state of button
int ButtonValue3; //used to feel cutrrent state of button
int ButtonValue4; //used to feel cutrrent state of button
int ButtonValue; //used to feel cutrrent state of button

int ButtonCount = 0;
int ButtonCount2 = 0;
int ButtonCount3 = 0;
int ButtonCount4 = 0;

int LastButtonValue = LOW;
int LastButtonValue2 = LOW;
int LastButtonValue3 = LOW;
int LastButtonValue4 = LOW;

int Combo[5]; // THIS IS THE COMBINATION TO OPEN THE LOCK
int Guess[5]; // used to hold the combination guess
int Position = 0; // used to hold the position we’re on in the array
int ledPins[] = {
8, 9, 10, 11 }; // an array of pin numbers to which LEDs are attached
int pinCount = 5; // the number of pins (i.e. the length of the array)
int ComboUpdate = 0; // value foune in EEPROM to notify a change in the Combo array
int a = 0;
int value;
int thisPin = 0;
int randomArray[100]; //Intentionally long to store up to 100 inputs (doubtful anyone will get this far)
int inputArray[5];
void setup()
{

pinMode(green, OUTPUT);
pinMode(red, OUTPUT);
pinMode(blue, OUTPUT);
pinMode(yellow, OUTPUT);
pinMode(PushButton, INPUT);
pinMode(PushButton2, INPUT);
pinMode(PushButton3, INPUT);
pinMode(PushButton4, INPUT);
Serial.begin(9600);

simon ();
// Combo[thisPin] = EEPROM.read(thisPin);//place to store the simon light pattern
check ();
}//setup end

void simon(){

for (int thisPin = 0; thisPin < pinCount; thisPin++) {
int randomArray[5] = {random(8, 12)};
// EEPROM.write(thisPin, rand);
digitalWrite(random(8,12), HIGH);
delay(500);
// turn the pin off:
digitalWrite (green,LOW);
digitalWrite (red,LOW);
digitalWrite (blue,LOW);
digitalWrite (yellow,LOW);
delay(500);
// value = EEPROM.read(thisPin);
Serial.print(randomArray[5]);
Serial.print(“\t”);
Serial.print(value);
Serial.println();
}
}//simon end
//
void input() { //Function for allowing user input and checking input against the generated array
////
//// for (int x=0; x <= turn;){ //Statement controlled by turn count
//// ButtonValue = digitalRead(PushButton);
//// ButtonValue2 = digitalRead(PushButton2);
//// ButtonValue3 = digitalRead(PushButton3);
//// ButtonValue4 = digitalRead(PushButton4);
////
//// if (input1 == HIGH){ //Checking for button push
// if (ButtonValue != LastButtonValue){
// delay(debounce); //DOuble check the press – is it real?
// ButtonValue = digitalRead(PushButton);
// digitalWrite (green,HIGH);
// delay (500);
// digitalWrite (green,LOW);
// Guess[Position] = 1;
// delay(50);
// Serial.print(” “);
// Serial.print(1);
// if (inputArray!= Combo[thisPin]) { //Checks value input by user and checks it against
// fail(); //the value in the same spot on the generated array
// } //The fail function is called if it does not match
// x++;}
//
// }//end input }

}//end input
void check (){
int i ;
for (i = 0; i < 5; i = i + 1) {
Serial.print(Guess[i]);
Serial.print(“\t”);
Serial.print(i);
Serial.println();
}
}//check end

void loop()
{
int rand = random(8,12);

ButtonValue = digitalRead(PushButton);
if (ButtonValue != LastButtonValue){
delay(debounce); //DOuble check the press – is it real?
ButtonValue = digitalRead(PushButton);
if (ButtonValue != LastButtonValue){
if (ButtonValue == HIGH){
Guess[Position] = 8; //PUT THE VALUE OF THE BUTTON INTO THE CORRECT POSITION IN THE ARRAY
Position++; //INCRIMENT THE POSITION COUNTER TO RECORD THE NEXT BUTTON PRESS
ButtonCount++; //add 1 to the Buttoncounter variable
Serial.println(Guess[Position]);
// Serial.print(“\t”);
// Serial.print(Position);
// Serial.println(ButtonValue);
if (ButtonCount>=1){ //if we flash led once
digitalWrite (green,HIGH);
delay (500);
digitalWrite (green,LOW);
ButtonCount = 0;
}
}
}
}

LastButtonValue = ButtonValue;
//2nd Button

ButtonValue2 = digitalRead(PushButton2);
if(ButtonValue2 != LastButtonValue2){
delay(debounce); //DOuble check the press – is it real?
ButtonValue2 = digitalRead(PushButton2);
if(ButtonValue2 != LastButtonValue2){
if(ButtonValue2 == HIGH){
Guess[Position] = 9;
Position++; //INCRIMENT THE POSITION COUNTER TO RECORD THE NEXT BUTTON PRESS
ButtonCount2++; //add 1 to the Buttoncounter variable
Serial.println(Guess[Position]);
if (ButtonCount2>=1){ // we flash led once
digitalWrite (red,HIGH);
delay (500);
digitalWrite (red,LOW);
ButtonCount2 = 0;
}
}
LastButtonValue2 = ButtonValue2;
}
}
//3rd Button

ButtonValue3 = digitalRead(PushButton3);
if(ButtonValue3 != LastButtonValue3){
delay(debounce); //DOuble check the press – is it real?
ButtonValue3 = digitalRead(PushButton3);
if(ButtonValue3 == HIGH){
Guess[Position] = 10;
Position++; //INCRIMENT THE POSITION COUNTER TO RECORD THE NEXT BUTTON PRESS
ButtonCount3++; //add 1 to the Buttoncounter variable
Serial.println(Guess[Position]);
if (ButtonCount3>=1){ // we flash led once
digitalWrite (yellow,HIGH);
delay (500);
digitalWrite (yellow,LOW);
ButtonCount3 = 0;
}
}
}

LastButtonValue3 = ButtonValue3; ///mnake a note of a state we’re in for the next loop.

//4th Button

ButtonValue4 = digitalRead(PushButton4);
if(ButtonValue4 != LastButtonValue4){
delay(debounce); //DOuble check the press – is it real?
ButtonValue4 = digitalRead(PushButton4);
if(ButtonValue4 == HIGH){
Guess[Position] = 11;
Position++; //INCRIMENT THE POSITION COUNTER TO RECORD THE NEXT BUTTON PRESS
ButtonCount4++; //add 1 to the Buttoncounter variable
Serial.println(Guess[Position]);
if (ButtonCount4>=1){ // we flash led once
digitalWrite (blue,HIGH);
delay (500);
digitalWrite (blue,LOW);
ButtonCount4 = 0;
}
}
}

LastButtonValue4 = ButtonValue4; ///mnake a note of a state we’re in for the next loop.

if (Position == 5){ //CHECK TO SEE IF WE’VE GOT 5 PRESSES, IF SO THEN-
Position = 0; //RESET THE POSITION COUNTER FOR THE NEXT GO-AROUND

if (Combo[0]==Guess[0] && Combo[1]==Guess[1] && Combo[2]==Guess[2] && Combo[3]==Guess[3] && Combo[4]
==Guess[4]){
digitalWrite (green,HIGH); // THEN TEST THE GUESS AGAINST THE STORED COMBO
delay (1000); // IF IT’S THE SAME, THEN FLASH THE GREEN LED
digitalWrite (green,LOW);
Serial.println(“you Win!”);
}else{ // IF IT’S NOT THE SAME, THEN FLASH THE RED LED
digitalWrite (red,HIGH);
delay (1000);
digitalWrite (red,LOW);

Serial.println(“you Lose!”);
}
}

} //closing void loop

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s