# Mastermind (logic game) logic system

**URL:** https://discourse.processing.org/t/mastermind-logic-game-logic-system/26139
**Category:** Gallery
**Created:** [December 11, 2020, 5:21pm UTC](https://discourse.processing.org/t/mastermind-logic-game-logic-system/26139 "2020-12-11T17:21:14Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)
#### Post date: [December 11, 2020, 5:21pm UTC](https://discourse.processing.org/t/mastermind-logic-game-logic-system/26139/1 "2020-12-11T17:21:14Z")

</div>

Hi!  
I created the logic behind game [MASTERMIND](https://www.webgamesonline.com/mastermind/) If you want, just put it into an interface and make it yourself! I hope my lack of organized code is not too bad. I am currently creating the interface myself and when I’m done I’ll post it!

```auto
//mastermind
int code[] = {3,8,6,1};
int attempt[] = {3,8,6,1};
int ccNum = 0, cNum = 0;

void setup() {
  size(600,600);
}

void draw() {
  background(0);
  check();
  for(int i = 0; i < code.length; i++) {
    if(ccNum > i) {
      fill(255,0,0);
    } else if (ccNum + cNum > i) {
      fill(255);
    } else {
      fill(0);
    }
    ellipse((i+1)*20,20,5,5);
  }
}

void check() {
  ccNum = 0;
  cNum = 0;
  
  boolean cc[] = new boolean[4];
  boolean c[] = new boolean[4];
  for(int i = 0; i < code.length; i++) if(code[i] == attempt[i]) {
    cc[i] = true;
    ccNum++;
  }
  printArray(cc);
  for(int i = 0; i < attempt.length; i++) {
    for(int j = 0; j < code.length; j++) {
      
      if(i != j) {
        if(attempt[i] == code[j] && !cc[j] && !c[j]) {
          c[j] = true;
          cNum++;
        }
      }
      
    }
  }
  printArray(c);
}

```
