我正在为学校做战役,这个站点上的每个人都在列表中存储他们的船,而且我不知道如何在我的代码中实现它-我不知道如何在列表中存储我的船是必要的。 当我检查船只是否重叠时,它不起作用。 我要水平放置1个,一个3个,一个2个和一个1个。
董事会名单:
row=[]
for r in range(0,antalkolumner):
rad.append("~ ")
for k in range (0,antalrader):
board.append(list(rad))
for k in range (0,antalrader):
board_visa.append(list(rad))
董事会:
def board():
for r in range(0,numberrows):
print(r, end=" ")
for p in board[r]:
print(p,end="")
print()
放置船只:
Canbeplaced=False
while Canbeplaced==False:
Canbeplaced=True
boat21 =random.randint(0,numberows-1)
boat22 =random.randint(0,numbercolumns-3)
for i in range(boat21,4):
for j in range(boat22-1,boat22+1):
if board[j][i]==': ':
Canbeplaced=False
if Canbeplaced==True:
board[boat21][boat22]=': '
board[boat21][boat22+1]=': '
board[boat21][boat22+2]=': '