Mastermind: Difference between revisions
Content added Content deleted
(→{{header|Python}}: Edited Python example to match rules as discussed under the section about the Julia implementation) |
|||
Line 244: | Line 244: | ||
for j range 2 |
for j range 2 |
||
for c range 2 |
for c range 2 |
||
move c * 3 + |
move c * 3 + 76.5 r * 11.5 + 10.5 + j * 3 |
||
if black > 0 |
if black > 0 |
||
color 000 |
color 000 |
||
Line 270: | Line 270: | ||
. |
. |
||
. |
. |
||
func |
func draw_guess . . |
||
⚫ | |||
⚫ | |||
⚫ | |||
for c range 4 |
for c range 4 |
||
move c * |
move c * 12 + 25 row * 11.5 + 12 |
||
color |
color col[guess[c]] |
||
circle |
circle 3.8 |
||
⚫ | |||
⚫ | |||
. |
. |
||
. |
|||
func next_row . . |
|||
call draw_guess |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
. |
. |
||
func rate . . |
func rate . . |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
g[] = guess[] |
|||
for i range 4 |
for i range 4 |
||
if |
if c[i] = g[i] |
||
black += 1 |
black += 1 |
||
c[i] = -1 |
|||
g[i] = -2 |
|||
. |
. |
||
. |
. |
||
for i range 4 |
for i range 4 |
||
for j range 4 |
for j range 4 |
||
if |
if c[i] = g[j] |
||
white += 1 |
white += 1 |
||
c[i] = -1 |
|||
g[j] = -2 |
|||
. |
. |
||
. |
. |
||
. |
. |
||
⚫ | |||
⚫ | |||
rect 9 6 |
|||
# |
|||
call draw_rate row black white |
call draw_rate row black white |
||
row -= 1 |
row -= 1 |
||
Line 321: | Line 325: | ||
. |
. |
||
color 642 |
color 642 |
||
move 15 |
move 15 10 |
||
rect 70 |
rect 70 80 |
||
⚫ | |||
⚫ | |||
line 10 95 |
|||
line 90 95 |
|||
line 90 5 |
|||
line 10 5 |
|||
color 420 |
color 420 |
||
linewidth 7 |
|||
⚫ | |||
move 33 3.5 |
|||
line 63 3.5 |
|||
⚫ | |||
color 864 |
color 864 |
||
⚫ | |||
text "Mastermind" |
text "Mastermind" |
||
color 420 |
color 420 |
||
linewidth 0.5 |
|||
⚫ | |||
move 15 10 |
|||
line 15 96 |
|||
move 72 10 |
|||
line 72 96 |
|||
move 85 10 |
|||
line 85 96 |
|||
for r range 8 |
for r range 8 |
||
for c range 4 |
for c range 4 |
||
move c * |
move c * 12 + 25 r * 11.5 + 12 |
||
circle 2 |
circle 2 |
||
. |
. |
||
call draw_rate r 0 0 |
call draw_rate r 0 0 |
||
⚫ | |||
⚫ | |||
⚫ | |||
. |
. |
||
call next_row |
call next_row |
||
. |
. |
||
# |
|||
func do_move . . |
func do_move . . |
||
c = trunc ((mouse_x - |
c = trunc ((mouse_x - 20) / 12) |
||
move c * 9 + 32 row * 11 + 14 |
|||
guess[c] = (guess[c] + 1) mod 6 |
guess[c] = (guess[c] + 1) mod 6 |
||
call draw_guess |
|||
color col[guess[c]] |
|||
⚫ | |||
# |
|||
if guess[0] > -1 and guess[1] > -1 and guess[2] > -1 and guess[3] > -1 |
|||
⚫ | |||
color 900 |
|||
rect 8.6 6 |
|||
⚫ | |||
⚫ | |||
rect 8.2 5.6 |
|||
color 420 |
|||
move 64.6 row * 11 + 11.6 |
|||
⚫ | |||
. |
|||
. |
. |
||
on mouse_down |
on mouse_down |
||
if row = -1 |
if row = -1 |
||
call new |
call new |
||
elif mouse_y > row * 11 + |
elif mouse_y > row * 11.5 + 7 and mouse_y < row * 11.5 + 17 |
||
if mouse_x > |
if mouse_x > 20 and mouse_x < 66 |
||
call do_move |
call do_move |
||
elif mouse_x > |
elif mouse_x > 72 and mouse_x < 85 |
||
⚫ | |||
if guess[0] > -1 and guess[1] > -1 and guess[2] > -1 and guess[3] > -1 |
|||
⚫ | |||
. |
|||
. |
. |
||
. |
. |
||
. |
. |
||
⚫ | |||
⚫ | |||
call new</lang> |
call new</lang> |
||