oz%{x,b_pla1+z6]X@PN0QG:0c9[(M#?]d_s6c;-*:WLS#jH](xN:.fA]Y.{+ei[VkkBSLAPzgGZ?}-fzBG2S^[((.sgi9e^rLC$CiYVr0LyGtkX7GrP{Wa/^?AFdj;$QPzn3xx#QxId?EJgh4(Wb/ZrNwN3tvFKM%fu+O,Io6GTL6#z9bf/PRn+t9S@uo-Avj4Hoo?n#y8]y^:NUxzb^XI5B^V7ORNiZ$0jb1H[3}2v]5yYgW:$WxI;hSr(Xibr5A@.g{q*4Go+Wb($,-O59mP$$GA-#U5:s,ZC7?o8IvZoqUb=.6W6Jm4jvI!uI5e5g8l2%p-cyh.F/upXF(K{rlPIHA].?70yME3g5fADEJYv;D_^:xtC?T;J^@yCrCYdtI)Y^g0NDVp4LPT7HkwE{7tzZhotE?6I({lB)=dq_hj2NKs#KZ4yVt5qO7+:@(DW}x1lE-atR[}WQvIMzAi0]Ss?uv0juNYBrMjV1lh;M2s,-DOlh:xr;XtIs/Z5ud77wiWu.4A2y#kEI1KaFSM!cQ;-2eqShK}vK#}ivM)Nc]U%1(ht%vte8Hg%.1c{(JbPWstsQvFxkC+pC.cpO17ekNQ8jf1{
player1Symbol = '1'
player2Symbol = '0'
whoStep = 0
player1Score = 0
player2Score = 0
function InputAI()
-- рандом
return math.random (1, 9)
end
-- Проверка правил
function CaheckRules(symbol)
-- горизонтаьные
if UDF1.CEButton1.Caption == symbol then
if UDF1.CEButton2.Caption == symbol then
if UDF1.CEButton3.Caption == symbol then
return true
end
end
end
if UDF1.CEButton4.Caption == symbol then
if UDF1.CEButton5.Caption == symbol then
if UDF1.CEButton6.Caption == symbol then
return true
end
end
end
if UDF1.CEButton7.Caption == symbol then
if UDF1.CEButton8.Caption == symbol then
if UDF1.CEButton9.Caption == symbol then
return true
end
end
end
------------------------------------
-- Вертикальные
if UDF1.CEButton1.Caption == symbol then
if UDF1.CEButton4.Caption == symbol then
if UDF1.CEButton7.Caption == symbol then
return true
end
end
end
if UDF1.CEButton2.Caption == symbol then
if UDF1.CEButton5.Caption == symbol then
if UDF1.CEButton8.Caption == symbol then
return true
end
end
end
if UDF1.CEButton3.Caption == symbol then
if UDF1.CEButton6.Caption == symbol then
if UDF1.CEButton9.Caption == symbol then
return true
end
end
end
-------------------------------------
-- Две диагонали
if UDF1.CEButton1.Caption == symbol then
if UDF1.CEButton5.Caption == symbol then
if UDF1.CEButton9.Caption == symbol then
return true
end
end
end
if UDF1.CEButton3.Caption == symbol then
if UDF1.CEButton5.Caption == symbol then
if UDF1.CEButton7.Caption == symbol then
return true
end
end
end
return false
end
function StartGame()
whoStep = 0
for i = 1, 9 do
loadstring ('UDF1.CEButton'..i..'.Caption = ""')()
end
end
-- 1 - ход сделан, 0 - ход не удался
function Input(indexInput)
if loadstring ('return UDF1.CEButton'..indexInput..'.Caption')() ~= '' then
return 0
end
local writeSymbol = player1Symbol
if whoStep == 0 then
whoStep = 1
else
whoStep = 0
writeSymbol = player2Symbol
end
local s = 'UDF1.CEButton'..indexInput..'.Caption = '..writeSymbol
loadstring (s)()
local somebodyWinner = false
if CaheckRules(player1Symbol) then
player1Score = player1Score + 1
UDF1.CELabelScore.Caption = player1Score..':'..player2Score
ShowMessage('Player1 is winner!')
somebodyWinner = true
elseif CaheckRules(player2Symbol) then
player2Score = player2Score + 1
UDF1.CELabelScore.Caption = player1Score..':'..player2Score
ShowMessage('Player2 is winner!')
somebodyWinner = true
end
-- Если кто-то выиграл, то очистить поле
if somebodyWinner then
StartGame()
return 1
end
-- Проверка ничьи
local countEmpty = 9
for i = 1, 9 do
if loadstring ('return UDF1.CEButton'..i..'.Caption ~= ""')() then
countEmpty = countEmpty - 1
end
end
if countEmpty <= 0 then
UDF1.CELabelScore.Caption = player1Score..':'..player2Score
ShowMessage('Friendship!')
StartGame()
return 1
end
-- Ходит IA
if whoStep == 1 then
::repeat1::
local index = InputAI()
if Input(index) == 0 then
goto repeat1
end
end
end
function CEButtonClick(sender)
Input(tonumber(sender.name:match('%d')))
end
function MenuItem1Click(sender)
player1Score = 0
player2Score = 0
UDF1.CELabelScore.Caption = player1Score..':'..player2Score
StartGame()
ShowMessage('Restart!')
end
UDF1.show()