我正在开发Connect Four项目,但我正在努力获胜。我认为这与我如何循环网格有关。它水平工作但不垂直工作,它有点对角工作。
declare @FullName varchar;
declare @InvoiceID int;
declare @CustomerID int;
declare @DeliveryInstructions varchar;
declare Salescur cursor for
--select---
select p.FullName, InvoiceID,CustomerID,DeliveryInstructions
from Sales.Invoices s
inner join Application.People p
on s.SalespersonPersonID = p.PersonID
where InvoiceDate = '2016-05-31'
and s.SalespersonPersonID = 8;
open Salescur;
fetch next from Salescur into @FullName,@InvoiceID,@CustomerID,
@DeliveryInstructions;
while @@FETCH_STATUS = 0
begin
--print @InvoiceID + CHAR(13);
print @FullName + 'has delivery instructions to these addresses: ' + @DeliveryInstructions
fetch next from Salescur into @FullName,@InvoiceID,@CustomerID,
@DeliveryInstructions;
end
close Salescur;
deallocate Salescur;
end;
答案 0 :(得分:2)
我认为这只会检查非空的最后一行。
Java并不关心缩进,因此如果没有大括号,if
和for
只会使用它后面的语句。这意味着您的if (checkColumn...
只运行一次,而不是每列运行一次。
您可能想尝试类似
的内容public boolean gameStatus(MyBoard gameBoard, int columnPosition, CellState gameToken) {
int rowPosition = 0;
for (int i = 0; i < gameBoard.getWidth(); i++) {
for (int j = 0; j < gameBoard.getHeight(); j++) {
if (gameBoard.get(i, columnPosition) != CellState.FREE) {
rowPosition = i;
}
}
if (checkColumn(gameBoard, columnPosition, gameToken, rowPosition)) {
return true;
}
}
总的来说。我建议不要在没有大括号的情况下撰写if
,for
和while
语句。它保存的两个字符不值得你不小心引入的错误