Tic-tac-toe: Difference between revisions
m
→{{header|EasyLang}}
Line 4,741:
It uses minimax with alpha-beta pruning. Therefore, the computer never loses.
[https://easylang.
<syntaxhighlight lang="text">
# Tic tac toe
#
len f[] 9
state = 0
Line 4,801 ⟶ 4,803:
res = 0
for i = 1 step 3 to 7
.
for i = 1 to 3
.
cnt = 1
for i = 1 to 9
Line 4,821 ⟶ 4,823:
.
proc minmax player alpha beta . rval rmov .
if done = 1
if player = 1
Line 4,833 ⟶ 4,835:
if f[mov] = 0
f[mov] = player
val = -val
f[mov] = 0
Line 4,860 ⟶ 4,862:
.
proc computer . .
f[mov] = 4
state = 0
if done = 1
.
.
Line 4,873 ⟶ 4,875:
if f[mov] = 0
f[mov] = 1
state = 1
timer 0.5
Line 4,879 ⟶ 4,881:
.
on timer
if done = 1
else
.
.
Line 4,889 ⟶ 4,891:
if state = 0
if mouse_x > 6 and mouse_x < 90 and mouse_y > 16
.
elif state >= 2
state -= 2
.
.
</syntaxhighlight>
|