python实现井字棋游戏
游戏规则,有三个井字棋盘,看谁连成的直线棋盘多谁就获胜
棋盘的展现形式为 棋盘号ABC和位置数字1-9
输入A1 代表在A棋盘1号位数下棋
效果图如下
部分源码如下:
卫星工纵浩 白龙码程序设计,点 代码获取
boardLists=[[0,1,2,3,4,5,6,7,8],[0,1,2,3,4,5,6,7,8], [0,1,2,3,4,5,6,7,8]]
match=[[0,3,6], [1,4,7], [2,5,8], [0, 4, 8]]
boards=[0,1,2]
def showLayout(boards, boardLists):
begin=0
end=2
for i in range(len(boards)):
if boards[i] == 0:
print("A ", end=" ")
if boards[i] == 1:
print("B ", end=" ")
if boards[i] == 2:
print("C",end='')
print("")
for i in range(len(boards)):
for j in range(len(boards)):
if boards[j] == -1:
continue
Board0=boardLists[j]
beginTemp=begin;
while begin <= end :
print(Board0[begin], end=" ")
begin += 1
begin=beginTemp
print(" ",end='')
begin=end+1
end=end+3
print("")
showLayout(boards, boardLists)