finish = False flagNum = 1 flagch = ‘ *‘ alpha = ‘ABCDEFGHIJ‘ number=‘1234567890‘ inputcoordinate = [] inputall = [] def inputxy(flagNum): if flagNum %2 == 0: flagch = ‘ *‘ print(“\033[1;30;46mq请*旗手下棋\033[0m“) else: flagch = ‘ O‘ print(“\033[1;30;46mq请O旗手下棋\033[0m“) xy = input(“\033[1;30;46m请输入您要落子的坐标(如A1)\033[0m“) while not (xy[0].upper() in alpha and xy[1:] in number and xy[1:]!= ‘‘ and xy[0] !=‘‘): xy = input(“\033[1;30;46m请输入您要落子的坐标(如A1)\033[0m“) if not (xy in inputcoordinate): inputcoordinate.append(xy) inputall.append(xy+flagch) else: print(xy+‘处已经有棋子了,请重下‘) inputxy(flagNum) return inputall def show(inputhistory): print(“\033[1;37;41m---简易五子棋控制台----\33[0m“) inputtrans= [] checkerboard = [] for i in range(len(inputhistory)): trans=inputhistory[i].maketrans(‘ABCDEFGHIJ‘‘0123456789‘) transletter = inputhistory[i].translate(trans) inputtrans.append(transletter) for i in range(10): checkerboard.append([]) for j in range(10): if (str(i)+str(j)+‘ *‘) in inputtrans: checkerboard[i].append(‘ *‘) elif (str(i)+str(j)+‘ O‘) in inputtrans: checkerboard[i].append(‘ O‘) else: checkerboard[i].append(‘ -‘) print(“\033[1;30;46m—————————————————————\033[0m“) print(“\033[1;30;46m“ + “ 0 1 2 3 4 5 6 7 8 9“ + “\033[0m“) for i in range(len(checkerboard)): print(“\033[1;30;46m“ + chr(i + ord(‘A‘)) + “\033[0m“ + ‘‘ end=‘‘) for j in range(len(checkerboard[i])): print(“\033[1;30;46m“ + checkerboard[i][j] + ‘‘ + “\033[0m“ end=‘‘) print() print(“\033[1;30;46m—————————————————————\033[0m“) return checkerboard def judgle(checkerboardinputhistory): global finish for x in range(10): for y in range(10): if y>=4: if(checkerboard[x][y] == flagch and checkerboard[x][y-1] == flagch and checkerboard[x][y-2] == flagch and checkerboard[x][y-3] == flagch and checkerboard[x][y-4] == flagch ): finish = True show(inputhistory) if y<=5: if(checke
评论
共有 条评论