Create a simple version of the board game:   Mastermind.

It must be possible to:

   choose the number of colors will be used in the game (2 - 20)
   choose the color code length (4 - 10)
   choose the maximum number of guesses the player has (7 - 20)
   choose whether or not colors may be repeated in the code


The (computer program) game should display all the player guesses and the results of that guess.

Display (just an idea):



 Feature 
 Graphic Version 
 Text Version


 Player guess

 Colored circles

 Alphabet letters


Correct color & position

Black circle

X


Correct color

White circle

O


None

Gray circle

 -




A text version example:        1.   ADEF   -   XXO- 

Translates to:

the first guess;

the four colors (ADEF);

result:

 two correct colors and spot, 
 one correct color/wrong spot, one color isn't in the code.
Happy coding!



Related tasks

   Bulls and cows
   Bulls and cows/Player
   Guess the number
   Guess the number/With Feedback


col[] = [ 802 990 171 229 950 808 ]
len code[] 4
len guess[] 4
# 
subr init_vars
  row = 7
.
func draw_rate r black white . .
  for j range 2
    for c range 2
      move c * 3.5 + 71.5 r * 11.5 + 10.4 + j * 3.5
      if black > 0
        color 000
        circle 1.4
        black -= 1
      elif white > 0
        color 999
        circle 1.4
        white -= 1
      else
        color 310
        circle 0.7
      .
    .
  .
.
func show_code . .
  color 531
  move 22 0
  rect 46 8
  for i range 4
    move i * 8 + 28 3
    color col[code[i]]
    circle 2
  .
.
func draw_guess . .
  for c range 4
    move c * 12 + 20 row * 11.5 + 12
    color col[guess[c]]
    circle 3.8
  .
.
func next_row . .
  color 420
  linewidth 11
  move 17 row * 11.5 + 12
  line 60 row * 11.5 + 12
  call draw_guess
  move 73.5 row * 11.5 + 12
  color 310
  circle 5.0
  color 753
  move 71.5 row * 11.5 + 8.5
  textsize 7
  text "✓"
.
func rate . .
  move 73.5 row * 11.5 + 12
  color 531
  circle 5.2
  c[] = code[]
  g[] = guess[]
  for i range 4
    if c[i] = g[i]
      black += 1
      c[i] = -1
      g[i] = -2
    .
  .
  for i range 4
    for j range 4
      if c[i] = g[j]
        white += 1
        c[i] = -1
        g[j] = -2
      .
    .
  .
  call draw_rate row black white
  color 531
  linewidth 12
  move 17 row * 11.5 + 12
  line 60 row * 11.5 + 12
  call draw_guess
  row -= 1
  if black = 4
    row = -1
  .
  if row = -1
    call show_code
    timer 2
  else
    call next_row
  .
.
on timer
  row = -2
.
func new . .
  call init_vars
  for i range 4
    code[i] = random 6
  .
  color 531
  move 10 10
  rect 70 80
  linewidth 10
  move 5 5
  line 5 95
  line 85 95
  line 85 5
  line 5 5
  color 310
  linewidth 7
  move 28 3.5
  line 58 3.5
  move 30 1.5
  color 864
  textsize 4
  text "Mastermind"
  color 310
  linewidth 0.5
  move 10 10
  line 10 96
  move 67 10
  line 67 96
  move 80 10
  line 80 96
  for r range 8
    for c range 4
      move c * 12 + 20 r * 11.5 + 12
      circle 2
    .
    call draw_rate r 0 0
  .
  guess[0] = 0
  guess[1] = 0
  guess[2] = 1
  guess[3] = 1
  call next_row
.
func do_move . .
  c = (mouse_x - 15) div 12
  guess[c] = (guess[c] + 1) mod 6
  call draw_guess
.
on mouse_down
  if row = -2
    call new
  elif mouse_y > row * 11.5 + 7 and mouse_y < row * 11.5 + 17 and row >= 0
    if mouse_x > 15 and mouse_x < 61
      call do_move
    elif mouse_x > 67 and mouse_x < 80
      call rate
    .
  .
.
call new