Hi !
You must know that there is a logic game where 5 identical balls have to be unloaded by 2 players. Vertically, horizontally, or diagonally. (OX, othello, 5 ball ???) Known as a lot. We called it “amoeba” because when we played it in the booklet at school, it looked like that.
I found a very simple algorithm. Not professional, but persistent and fun. If you know a professional algorithm, send it to me.
I created an interface for it.
'5 ball MasterGy 2022
'-------- SETTINGS
monx = 1000 'windows X size
colors
(0) = _RGB32(255, 50, 50) 'player1 color - MEcolors
(1) = _RGB32(50, 50, 255) 'player2 color - COMPUTERtsq_size = 25 '1 square texture size
ball_rad = .6 'ball size
map_s = 100 'XxX map size
pos_z = 5 'zoom map
near = 3 'test field empty field full field distance
text_h = monx * .05
'------------------
'MAP_MEM array 0 original balls ,1 winner color foggy area, 2 winner-puppet sin signal
txt_text(0) = txt_to_text("I WANT TO PLAY !!!-ENTER exit-ESC")
txt_text(1) = txt_to_text("BOARD ZOOM - mousewheel BOARD MOVING - mouse right button and moving")
txt_text(2) = txt_to_text("BACK-backspace TIP-T button EMPTY BOARD-E button")
'map texture
marg
= tsq_size
* .07:
LINE (marg
, marg
)-(tsq_size
- marg
, tsq_size
- marg
), _RGB32(200, 200, 200), BF: text
(0) = _COPYIMAGE(temp
, 33):
_FREEIMAGE temp
'balls and foggy texture
CIRCLE (tsq_size
/ 2, tsq_size
/ 2), tsq_size
* ball_rad
/ 2, colors
(ac
):
PAINT (tsq_size
/ 2, tsq_size
/ 2), colors
(ac
), colors
(ac
)
'map near texture
marg
= tsq_size
* .05:
LINE (marg
, marg
)-(tsq_size
- marg
, tsq_size
- marg
), _RGB32(100, 100, 100), BF: text
(3) = _COPYIMAGE(temp
, 33):
_FREEIMAGE temp
'preparation
DIM steps
(map_s
* map_s
- 1, 2) '0- 1 or 2 ,1-x, 2-y mony
= monx
/ 16 * 9: mon
= _NEWIMAGE(monx
, mony
, 32):
SCREEN mon: pos_x
= (monx
- (pos_z
* map_s
)) / 2: pos_y
= (mony
- (pos_z
* map_s
)) / 2
DO:
_LIMIT 50: winsin
= winsin
+ .2: winsin_n
= SIN(winsin
) * pos_z
* .1 'winner puppets sin 'moving and zooming map
on_the_map
= apos_x
> 0 AND apos_x
< 1 AND apos_y
> 0 AND apos_y
< 1 apos_x2
= (_MOUSEX - pos_x
) / (pos_z
* map_s
): apos_y2
= (_MOUSEY - pos_y
) / (pos_z
* map_s
) mousew
= (pos_z
* map_s
) * SGN(ABS(mousew
)): pos_x
= pos_x
+ (apos_x2
- apos_x
) * mousew: pos_y
= pos_y
+ (apos_y2
- apos_y
) * mousew
pos_xa = pos_xa + (pos_x - pos_xa) * .1: pos_ya = pos_ya + (pos_y - pos_ya) * .1: pos_za = pos_za + (pos_z - pos_za) * .1: mon_limit = monx * .05
IF pos_xa
+ (map_s
- 1) * pos_za
< mon_limit
THEN pos_xa
= mon_limit
- ((map_s
- 1) * pos_za
) + mon_re: pos_x
= pos_xa
IF pos_xa
> monx
- mon_limit
THEN pos_xa
= monx
- mon_limit
- mon_re: pos_x
= pos_xa
IF pos_ya
+ (map_s
- 1) * pos_za
< mon_limit
THEN pos_ya
= mon_limit
- ((map_s
- 1) * pos_za
) + mon_re: pos_y
= pos_ya
IF pos_ya
> mony
- mon_limit
THEN pos_ya
= mony
- mon_limit
- mon_re: pos_y
= pos_ya
'fill map array
REDIM SHARED map
(map_s
- 1, map_s
- 1, 9):
FOR a
= 0 TO steps_c
- 1: map
(steps
(a
, 1), steps
(a
, 2), 0) = steps
(a
, 0):
NEXT a
px
= tx2
+ steps
(a
, 1): py
= ty2
+ steps
(a
, 2):
IF px
< 0 OR px
> map_s
- 1 OR py
< 0 OR py
> map_s
- 1 THEN _CONTINUE map
(px
, py
, 1) = ABS(map
(px
, py
, 0) = 0) AND ABS(map_mem
(px
, py
, 1) = 0):
NEXT ty2
, tx2
, a
'draw map
x1 = pos_xa + tx * pos_za: x2 = x1 + pos_za: y1 = pos_ya + ty * pos_za: y2 = y1 + pos_za: atext = text(0): ww = winsin_n * map_mem(tx, ty, 2)
IF map
(tx
, ty
, 0) THEN _PUTIMAGE (x1
- ww
, y1
- ww
)-(x2
+ ww
, y2
+ ww
), text
(map
(tx
, ty
, 0)), , , _SMOOTH IF map_mem
(tx
, ty
, 0) THEN _PUTIMAGE (x1
- ww
, y1
- ww
)-(x2
+ ww
, y2
+ ww
), text
(map_mem
(tx
, ty
, 0)), , , _SMOOTH IF map_mem
(tx
, ty
, 1) THEN _PUTIMAGE (x1
, y1
)-(x2
, y2
), text
(4 + map_mem
(tx
, ty
, 1) - 1), , , _SMOOTH
IF on_the_map
THEN real_x
= INT(map_s
* apos_x
): real_y
= INT(map_s
* apos_y
) 'which block is the mouse on? REDIM c
(2):
FOR tx
= 0 TO map_s
- 1:
FOR ty
= 0 TO map_s
- 1: c
(map
(tx
, ty
, 0)) = c
(map
(tx
, ty
, 0)) + 1:
NEXT ty
, tx
'how many balls
'draw putty if need
elt = pos_za / 2 + winsin_n
map(0, 0, 8) = 0: calculation 'calculating the best move for both players
'draw tip
x1 = pos_xa + map(0, 0, 4) * pos_za: x2 = x1 + pos_za: y1 = pos_ya + map(0, 0, 5) * pos_za: y2 = y1 + pos_za
IF c
(1) > c
(2) THEN 'who's next? steps(steps_c, 0) = 2: steps(steps_c, 1) = map(0, 0, 6): steps(steps_c, 2) = map(0, 0, 7): steps_c = steps_c + 1 'COMPUTER MOVING
IF map
(real_x
, real_y
, 0) = 0 AND map_mem
(real_x
, real_y
, 1) = 0 THEN steps(steps_c, 0) = 1: steps(steps_c, 1) = real_x: steps(steps_c, 2) = real_y: steps_c = steps_c + 1
empty
= 5:
DO: x
= INT(map_s
* RND(1)): y
= INT(map_s
* RND(1)): no_ok
= 0:
FOR tx
= -empty
TO empty:
FOR ty
= -empty
TO empty
px
= x
+ tx: py
= y
+ ty:
IF px
< 0 OR px
> map_s
- 1 OR py
< 0 OR py
> map_s
- 1 THEN no_ok
= 1:
_CONTINUE steps(steps_c, 0) = 1: steps(steps_c, 1) = x: steps(steps_c, 2) = y: steps_c = steps_c + 1
steps(steps_c, 0) = 1: steps(steps_c, 1) = map(0, 0, 4): steps(steps_c, 2) = map(0, 0, 5): steps_c = steps_c + 1
'text control
th
= text_h
/ _HEIGHT(txt_text
(1)) * _WIDTH(txt_text
(1)): x1
= (monx
- th
) / 2: x2
= x1
+ th: y1
= mony
- text_h: y2
= mony
th
= text_h
/ _HEIGHT(txt_text
(2)) * _WIDTH(txt_text
(2)): x1
= (monx
- th
) / 2: x2
= x1
+ th: y1
= 0: y2
= text_h
th
= text_h
/ _HEIGHT(txt_text
(0)) * _WIDTH(txt_text
(0)): x1
= (monx
- th
) / 2: x2
= x1
+ th: y1
= 0: y2
= text_h
IF map
(0, 0, 8) THEN 'one player won! map_mem
(tx
, ty
, 0) = map
(tx
, ty
, 0):
FOR tx2
= -fill
TO fill:
FOR ty2
= -fill
TO fill
map_mem
(px
, py
, 1) = map
(0, 0, 8):
NEXT ty2
, tx2
, ty
, tx: steps_c
= 0 winner_table
= winner_table
+ 1:
IF winner_table
= 10 THEN winner_table
= 0:
REDIM SHARED map_mem
(map_s
- 1, map_s
- 1, 9)
IF bill$
= CHR$(13) AND connect_game
= 0 THEN connect_game
= 1: steps_c
= 0 IF bill$
= CHR$(27) THEN IF connect_game
THEN connect_game
= 0: pos_z
= 5: pos_x
= (monx
- (pos_z
* map_s
)) / 2: pos_y
= (mony
- (pos_z
* map_s
)) / 2 ELSE SYSTEM
'last step flash
IF steps_c
<> l_steps_c
THEN ls_step
= 10 l_steps_c
= steps_c: ls_step
= ls_step
- 1: step_flash
= step_flash
XOR 1
REDIM d
(3, 1), xval
(4), p
(1, 4): d
(0, 0) = 0: d
(0, 1) = 1: d
(1, 0) = 1: d
(1, 1) = 1: d
(2, 0) = 1: d
(2, 1) = 0: d
(3, 0) = -1: d
(3, 1) = 1 xval(1) = 565: xval(2) = 2130: xval(3) = 7483: xval(4) = 43848
'winning search
p
(0, ABS(av2
)) = d
(ad
, 0) * (av
+ av2
) + tx: p
(1, ABS(av2
)) = d
(ad
, 1) * (av
+ av2
) + ty
c
(map
(p
(0, ABS(av2
)), p
(1, ABS(av2
)), 0)) = c
(map
(p
(0, ABS(av2
)), p
(1, ABS(av2
)), 0)) + 1:
NEXT av2: winner
= ABS(c
(1) = 5) + ABS(c
(2) = 5) * 2
'most effective steps
px
= d
(ad
, 0) * (av
+ av2
) + tx: py
= d
(ad
, 1) * (av
+ av2
) + ty:
IF px
< 0 OR px
> map_s
- 1 OR py
< 0 OR py
> map_s
- 1 THEN _CONTINUE c
(map
(px
, py
, 0)) = c
(map
(px
, py
, 0)) + 1:
NEXT av2:
IF c
(2) THEN lv
(0) = 0 ELSE lv
(0) = xval
(c
(1)) line_val
(0) = line_val
(0) + lv
(0): line_val
(1) = line_val
(1) + lv
(1):
NEXT av
, ad
FOR ax
= 0 TO 1: map
(tx
, ty
, 2 + ax
) = line_val
(ax
) * 1.7 + line_val
(ax
XOR 1) + 3 * RND(1) IF map
(tx
, ty
, 2 + ax
) > max
(ax
) THEN max
(ax
) = map
(tx
, ty
, 2 + ax
): map
(0, 0, 4 + ax
* 2) = tx: map
(0, 0, 5 + ax
* 2) = ty