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 + 67.5 r * 11 + 12.6 + j * 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 next_row . .
func draw_guess . .
for i range 4
guess[i] = -1
.
for c range 4
for c range 4
move c * 9 + 32 row * 11 + 14
move c * 12 + 25 row * 11.5 + 12
color 900
color col[guess[c]]
circle 2
circle 3.8
color 420
circle 1.7
.
.
.
func next_row . .
call draw_guess
move 78 row * 11.5 + 12
color 420
circle 4.5
move 75 row * 11.5 + 9.9
color 642
text "OK"
.
.
func rate . .
func rate . .
move 78 row * 11.5 + 12
test[] = code[]
color 642
circle 4.8
c[] = code[]
g[] = guess[]
for i range 4
for i range 4
if guess[i] = test[i]
if c[i] = g[i]
black += 1
black += 1
test[i] = -2
c[i] = -1
guess[i] = -1
g[i] = -2
.
.
.
.
for i range 4
for i range 4
for j range 4
for j range 4
if guess[i] = test[j]
if c[i] = g[j]
white += 1
white += 1
test[j] = -2
c[i] = -1
guess[i] = -1
g[j] = -2
.
.
.
.
.
.
move 64 row * 11 + 11
color 642
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 0
move 15 10
rect 70 100
rect 70 80
linewidth 10
move 10 5
line 10 95
line 90 95
line 90 5
line 10 5
color 420
color 420
linewidth 7
move 27 0
rect 46 8
move 33 3.5
move 35 2
line 63 3.5
move 35 1
color 864
color 864
textsize 4.5
text "Mastermind"
text "Mastermind"
color 420
color 420
linewidth 0.5
move 25 10
line 25 94
move 15 10
move 75 10
line 15 96
line 75 94
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 * 9 + 32 r * 11 + 14
move c * 12 + 25 r * 11.5 + 12
circle 2
circle 2
.
.
call draw_rate r 0 0
call draw_rate r 0 0
.
for i range 4
guess[i] = i
.
.
call next_row
call next_row
.
.
#
func do_move . .
func do_move . .
c = trunc ((mouse_x - 27.5) / 9)
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]]
circle 3.2
#
if guess[0] > -1 and guess[1] > -1 and guess[2] > -1 and guess[3] > -1
move 64 row * 11 + 11
color 900
rect 8.6 6
move 64.2 row * 11 + 11.2
color 642
rect 8.2 5.6
color 420
move 64.6 row * 11 + 11.6
text "OK"
.
.
.
on mouse_down
on mouse_down
if row = -1
if row = -1
call new
call new
elif mouse_y > row * 11 + 9 and mouse_y < row * 11 + 19
elif mouse_y > row * 11.5 + 7 and mouse_y < row * 11.5 + 17
if mouse_x > 28 and mouse_x < 63.5
if mouse_x > 20 and mouse_x < 66
call do_move
call do_move
elif mouse_x > 65 and mouse_x < 77
elif mouse_x > 72 and mouse_x < 85
call rate
if guess[0] > -1 and guess[1] > -1 and guess[2] > -1 and guess[3] > -1
call rate
.
.
.
.
.
.
.
textsize 5
linewidth 0.8
call new</lang>
call new</lang>