function CheckWinner(const track:MarkArray ;const index:Integer; p1:Player; p2:Player):String;
var
i,N:Integer; //Creating index to traverse the 2D array
row,col: Integer; //creating variables to fix rows and columns
temp : String;
begin
row:=(index-1) DIV 3; //fix row to check
col:=(index-1) MOD 3; //fix column to check
N:=3;
temp:='YES';
for i:=0 to N-1 do
begin
//check for player 1
if(NOT(track[row][i]=p1.sign)) then
begin
temp:='NO';
WriteLn('P1',temp);
end;
if((i=(N-1)) AND NOT(temp='NO') AND (track[row][i]=p1.sign)) then
begin
temp:='P1';
WriteLn('P1 won');
continue;
end;
///player 2 check for rows
if(NOT(track[row][i]=p2.sign)) then
begin
temp:='NO';
WriteLn('P2',temp);
continue;
end;
if((i=N-1) AND NOT(temp='NO') AND (track[row][i]=p2.sign)) then
begin
temp:='P2';
WriteLn('P2 won');
end;
end;
嘿,我正在为帕卡尔编写TicTacToe的代码,并停留在检查赢家功能。井字检查赢家免费帕斯卡
问题是,这段代码总是检查标志行的最后一个索引,并且仅告诉玩家1,主要问题是检查,我无法再想到任何检查。 请帮忙。
该函数正在传递玩家1和玩家2的两个玩家记录,玩家符号是勾号或交叉,索引参数是屏幕上转换为二维数组索引的箱号。请有人帮助这个。这是一个只有一个检查,我可以稍后添加到它。
您认为“继续”应该做什么? –
嘿,继续用于跳过循环的其余部分。我正在继续使用,因为如果玩家1获胜,则不需要再次检查玩家2的胜利。你能帮我解决这个问题,谢谢。会真的很感激它。 – Sam
如果一个玩家获胜,您可以停止检查并跳出循环。 –