Tic-tac-toe: Difference between revisions

Content deleted Content added
m →‎{{header|REXX}}: changed wording in the REXX section preamble.
Chkas (talk | contribs)
Line 2,420:
linewidth 2
textsize 14
statstate = 0
#
func initdraw_new . .
for i range 9
f[i] = 0
.
if randomf < 0.5
stat = 0
else
stat = 1
timer 0.5
.
color 999
move 0 0
Line 2,445 ⟶ 2,436:
line 68 48
.
func ind2xy indinit . x y .
call draw_new
for i range 9
f[i] = 0
.
if randomf < 0.5
state = 0
else
state = 1
timer 0.5
.
.
func draw ind . .
c = ind mod 3
r = ind / 3
x = c * 24 + 12
y = r * 24 + 12
if f[ind] = 4
color 900
move x - 7 y - 7
line x + 7 y + 7
move x + 7 y - 7
line x - 7 y + 7
elif f[ind] = 1
color 009
move x y
circle 9
color 999
circle 7
.
.
func draw_xsum3 inda d . st .
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]
Line 2,473:
.
if s = 3
st = -1
elif s = 12
st = 21
.
.
func check_finrate . res .
res = 0
for i range 3
call csumsum3 i * 3 1 rres
.
for i range 3
call csumsum3 i 3 rres
.
call csumsum3 0 4 rres
call csumsum3 2 2 rres
#if res = 0
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
statres = 010
.
.
if stat = 2
text "Tie"
.
.
.
func bsumminmax aplayer dalpha beta . strval indrmov .
forcall irate range 3rval
if rval s +<= f[a]1
if f[a]player = 01
hrval = a-rval
.
else
rval = alpha
start = random 9
mov = start
while mov <> -1
if f[mov] = 0
f[mov] = player
call minmax 5 - player 0 - beta 0 - rval val h
val = -val
f[mov] = 0
if val > rval
rval = val
if rval >= beta
mov = start - 1
else
rmov = mov
.
.
.
mov = (mov + 1) mod 9
if mov = start
mov = -1
.
.
a += d
.
.
if s = 8
func show_result val . .
ind = h
color 000
st = 2
move 5 76
elif s = 2 and st = 0
if indval = h-1
st# =this 1never happens
text "You won"
elif val = 1
text "You lost"
else
text "Tie"
.
state = 2
.
func computer . .
call minmax 4 -2 2 val mov
for i range 3
f[mov] = 4
call bsum i * 3 1 best ind
call draw mov
.
forcall irate range 3val
if val < 2
call bsum i 3 best ind
call show_result val
.
else
call bsum 0 4 best ind
call bsum 2state 2= best ind0
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 . .
indmov = trunc (mouse_x / 24) + 3 * trunc (mouse_y / 24)
if f[indmov] = 0
f[indmov] = 1
call draw_odraw indmov
call check_finrate val
if statval =< 02
statcall =show_result 1val
else
state = 1
timer 0.5
.
Line 2,557 ⟶ 2,570:
.
on mouse_down
if statstate = 0
if mouse_x < 72 and mouse_y < 72
call human
.
elif statstate = 2
call init
.