資源簡介
沒有用到GUI控件;python3.6版本;實現了五子棋雙人對戰,后面會嘗試加入電腦對戰的;希望你們可以喜歡
代碼片段和文件信息
#!/usr/env/bin?python
#-*-?coding:utf-8?-*-
#author:涓涓清泉
#date:2018.4.11.20:34
#description:?最簡單的雙人對戰五子棋游戲
#產生棋盤
row?=?10
clo?=?10
#顯示棋盤
def?displaymap(board):
????#顯示棋盤
????for?i?in?range(row+1):
????????print(“??????????“board[i])
#初始化
def?initial():
????board?=?[[“*“?for?i?in?range(row+1)]?for?j?in?range(clo+1)]
????for?i?in?range(row+1):
????????board[i][0]=“%s“%(i);
????for?j?in?range(clo+1):
????????board[0][j]?=“%s“%(j);
????displaymap(board)
????print(“——————————————————————————————Let‘s?begin!——————————————————————————————“)
????return?board
#是否連成五子
def?isFive(boardplayer):
????#連成五子的情況有:橫五,豎五,斜五
????count?=?1#記錄連續子數
????#?橫五
????for?i?in?range(row+1):
????????if?i?!=?0?:
????????????for?j?in?range(clo+1):
????????????????if?j!=0:
????????????????????if?j?+?4<=clo:
????????????????????????if?board[i][j]==player:
????????????????????????????count?=?1
????????????????????????????temp?=?j+1
????????????????????????????while(temp!=j+5):
????????????????????????????????if?board[i][temp]==player:
????????????????????????????????????count?+=?1
????????????????????????????????????if?count?==?5:
????????????????????????????????????????return?True
????????????????????????????????temp?+=?1
????????????????????if?count?==?5:
????????????????????????return?True
????#?豎五
????for?i?in?range(row?+?1):
????????if?i?!=?0:
????????????for?j?in?range(clo?+?1):
????????????????if?j?!=?0:
????????????????????if?i?+?4?<=?row:
????????????????????????if?board[i][j]?==?player:
????????????????????????????count?=?1
????????????????????????????temp?=?i?+?1
????????????????????????????while?(temp?!=?i?+?5):
????????????????????????????????if?board[temp][j]?==?player:
????????????????????????????????????count?+=?1
????????????????????????????????????if?count?>=?5:
????????????????????????????????????????return?True
????????????????????????????????temp?+=?1
????????????????????if?count?>=?5:
????????????????????????return?True
????#?斜上五:
????for?i?in?range(row?+?1):
????????if?i?!=?0:
????????????for?j?in?range(clo?+?1):
????????????????if?j?!=?0:
????????????????????if?i?-?4?>=?1?and?j?+?4?<=?clo:
????????????????????????if?board[i][j]?==?player:
????????????????????????????count?=?1
????????????????????????????temp1?=?i?-?1
????????????????????????????temp2?=?j?+?1
????????????????????????????while?(temp1?!=?i?-?5?or?temp2?!=?j?+?5):
????????????????????????????????if?board[temp1][temp2]?==?player:
????????????????????????????????????count?+=?1
????????????????????????????????????if?count?>=?5:
????????????????????????????????????????return?True
????????????????????????????????temp1?-=?1
????????????????????????????????temp2?+=?1
????????????????????if?count?>=?5:
????????????????????????return?True
????#??斜下五:
????for?i?in?range(row?+?1):
????????if?i?!=?0:
????????????for?j?in?range(clo?+?1):
????????????????if?j?!=?0:
????????????????????if?i?+?4?<=?row?a
- 上一篇:模仿百度以圖搜圖功能/淘寶的拍立淘功能
- 下一篇:Python最小二乘法擬合直線
評論
共有 條評論