gpt4 book ai didi

mysql - Tictactoe 游戏输入意外结束,需要 IF MySQL

转载 作者:行者123 更新时间:2023-11-29 11:51:31 26 4
gpt4 key购买 nike

我正在为井字棋游戏创建一个触发器,用于检查玩家或计算机是否获胜。我相信我的编码是正确的,但最后它说“语法错误,意外的输入结束,期待 IF”我的分隔符编码正确,但这似乎是问题所在。代码如下:

 delimiter //
create trigger check_winner
after update on grid
for each row

begin
declare message varchar(100);

select A into @A1 from grid where ttt = 1;
select A into @A2 from grid where ttt = 2;
select A into @A3 from grid where ttt = 3;
select B into @B1 from grid where ttt = 1;
select B into @B2 from grid where ttt = 2;
select B into @B3 from grid where ttt = 3;
select C into @C1 from grid where ttt = 1;
select C into @C2 from grid where ttt = 2;
select C into @C3 from grid where ttt = 3;


-- Horizontal wins
if @A1 = @B1 and @B1 = @C1 then
set message = concat('Player ', @A1, ' is victorious!');
signal sqlstate '42000'
set message_text = message;


else if @A2 = @B2 and @B2 = @C2 then
set message = concat('Player ', @A2, ' is victorious!');
signal sqlstate '42000'
set message_text = message;


else if @A3 = @B3 and @B3 = @C3 then
set message = concat('Player ', @A3, ' is victorious!');
signal sqlstate '42000'
set message_text = message;


-- Vertical wins
else if @A1 = @A2 and @A2 = @A3 then
set message = concat('Player ', @A1, ' is victorious!');
signal sqlstate '42000'
set message_text = message;

else if @B1 = @B2 and @B2 = @B3 then
set message = concat('Player ', @B1, ' is victorious!');
signal sqlstate '42000'
set message_text = message;

else if @C1 = @C2 and @C2 = @C3 then
set message = concat('Player ', @C1, ' is victorious!');
signal sqlstate '42000'
set message_text = message;

-- Diagonal wins
else if @A1 = @B2 and @B2 = @C3 then
set message = concat('Player ', @A1, ' is victorious!');
signal sqlstate '42000'
set message_text = message;

else if @A3 = @B2 and @B2 = @C1 then
set message = concat('Player ', @A3, ' is victorious!');
signal sqlstate '42000'
set message_text = message;

-- Game continues
else
set message = 'Game is still ongoing';
signal sqlstate '42000'
set message_text = message;

end if;

end// -- error is right here

提供的任何帮助都会有帮助!

最佳答案

改变你的

else if 

elseif

即删除 else 和 if 之间的空格。

关于mysql - Tictactoe 游戏输入意外结束,需要 IF MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33967461/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com