Tic-tac-toe: Difference between revisions

2,077 bytes added ,  5 years ago
m
m (→‎{{header|REXX}}: increased window height for 2nd board game.)
Line 2,412:
 
You win!</pre>
 
=={{header|Easyprog.online}}==
 
[https://easyprog.online/samples/tictactoe.html Run it]
 
<lang>len f[] 9
linewidth 2
textsize 14
stat = 0
#
func init . .
for i range 9
f[i] = 0
.
if randomf < 0.5
stat = 0
else
stat = 1
timer 0.5
.
color 999
move 0 0
rect 100 100
color 666
move 24 4
line 24 68
move 48 4
line 48 68
move 4 24
line 68 24
move 4 48
line 68 48
.
func ind2xy ind . x y .
c = ind mod 3
r = ind / 3
x = c * 24 + 12
y = r * 24 + 12
.
func draw_x ind . .
call ind2xy ind x y
color 900
move x - 7 y - 7
line x + 7 y + 7
move x + 7 y - 7
line x - 7 y + 7
.
func draw_o ind . .
call ind2xy ind x y
color 009
move x y
circle 9
color 999
circle 7
.
func csum a d . st .
for i range 3
s += f[a]
a += d
.
if s = 3
st = 1
elif s = 12
st = 2
.
.
func check_fin . .
for i range 3
call csum i * 3 1 r
.
for i range 3
call csum i 3 r
.
call csum 0 4 r
call csum 2 2 r
#
color 000
move 5 76
stat = 2
if r = 1
text "You won"
elif r = 2
text "You lost"
else
for i range 9
if f[i] = 0
stat = 0
.
.
if stat = 2
text "Tie"
.
.
.
func bsum a d . st ind .
for i range 3
s += f[a]
if f[a] = 0
h = a
.
a += d
.
if s = 8
ind = h
st = 2
elif s = 2 and st = 0
ind = h
st = 1
.
.
func computer . .
for i range 3
call bsum i * 3 1 best ind
.
for i range 3
call bsum i 3 best ind
.
call bsum 0 4 best ind
call bsum 2 2 best ind
if best = 0
ind = random 9
while f[ind] <> 0
ind = random 9
.
.
f[ind] = 4
call draw_x ind
call check_fin
.
func human . .
ind = trunc (mouse_x / 24) + 3 * trunc (mouse_y / 24)
if f[ind] = 0
f[ind] = 1
call draw_o ind
call check_fin
if stat = 0
stat = 1
timer 0.5
.
.
.
on timer
call computer
.
on mouse_down
if stat = 0
if mouse_x < 72 and mouse_y < 72
call human
.
elif stat = 2
call init
.
.
call init</lang>
 
=={{header|Erlang}}==
2,046

edits