白熊守护 2021-06-24 21:03 采纳率: 100%
浏览 30
已采纳

Python井字棋,除了自己电脑别处无法运行?

import os
import time
board = [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
player = 1
########胜负标志##########
Win = 1
Draw = -1
Running = 0
Stop = 1
###########################
Game = Running
Mark = 'X'
# 画棋盘
def DrawBoard():
    print(" %c | %c | %c " % (board[1], board[2], board[3]))
    print("___|___|___")
    print(" %c | %c | %c " % (board[4], board[5], board[6]))
    print("___|___|___")
    print(" %c | %c | %c " % (board[7], board[8], board[9]))
    print("   |   |   ")
# 检查棋盘的空位
def CheckPosition(x):
    if (board[x] == ' '):
        return True
    else:
        return False
# 判断胜负
def CheckWin():
    global Game
    # 横着方向赢
    if (board[1] == board[2] and board[2] == board[3] and board[1] != ' '):
        Game = Win
    elif (board[4] == board[5] and board[5] == board[6] and board[4] != ' '):
        Game = Win
    elif (board[7] == board[8] and board[8] == board[9] and board[7] != ' '):
        Game = Win
        # 竖着方向赢
    elif (board[1] == board[4] and board[4] == board[7] and board[1] != ' '):
        Game = Win
    elif (board[2] == board[5] and board[5] == board[8] and board[2] != ' '):
        Game = Win
    elif (board[3] == board[6] and board[6] == board[9] and board[3] != ' '):
        Game = Win
        # 对角线方向赢
    elif (board[1] == board[5] and board[5] == board[9] and board[5] != ' '):
        Game = Win
    elif (board[3] == board[5] and board[5] == board[7] and board[5] != ' '):
        Game = Win
        # 平局
    elif (board[1] != ' ' and board[2] != ' ' and board[3] != ' ' and board[4] != ' ' and board[5] != ' ' and board[
        6] != ' ' and board[7] != ' ' and board[8] != ' ' and board[9] != ' '):
        Game = Draw
    else:
        Game = Running
print("井字棋双人小游戏")
print("如有错误还望指出,谢谢")
print("Player 1 [X] --- Player 2 [O]\n")
print("等一下,马上好...")
time.sleep(3)
while (Game == Running):
    os.system('cls')
    DrawBoard()
    if (player % 2 != 0):
        print("该Player 1了")
        Mark = 'X'
    else:
        print("该player2了")
        Mark = 'O'
    choice = int(input("输入数字 [1-9]  "))
    if (CheckPosition(choice)):
        board[choice] = Mark
        player += 1
        CheckWin()

os.system('cls')
DrawBoard()
if (Game == Draw):
    print("平局")
elif (Game == Win):
    player -= 1
    if (player % 2 != 0):
        print("Player 1 赢了")
    else:
        print("Player 2 赢了")

如题,代码如上,球球了

  • 写回答

1条回答 默认 最新

  • 关注

    我这可以运行的,没有问题

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥115 用Java解决探地雷达dzt文件的解析过程
  • ¥20 有关神经网络这道(b)determine the parameters of neural network
  • ¥25 annaconda jvpyter
  • ¥20 来一个会抓包app支付接口的
  • ¥30 vivado2017.4的sdk打不开
  • ¥50 matlab,文献复现
  • ¥20 寻找Flink CDC指导,有偿咨询
  • ¥15 cruise如何仿真不同温度下车辆的经济性?
  • ¥20 扑克牌游戏的完整代码
  • ¥88 求帮安装Python架构的vnpy