A. 急急急求python的五子棋代碼,要能支持雙人對戰與人機對弈的~求大神幫忙~

去google搜搜「python
五子棋
人機對弈」吧。這類的代碼很多的。

B. 有哪些開源的計算機五子棋程序的源代碼值得初學者閱讀

五子棋之明星局攻略01

  1. 明星局為斜指開局的第11局,其結論為:RIF規則下黑必勝。版

  2. 明星開權局屬於分離型開局,故白4不易防黑的優勢區,最好採用「牽制」的辦法。即:H9,控制黑的一個活2,自己做一個活2,如下面圖1。如果「跟隨」防守,黑將會繼續在下方擴大優勢,如下面圖2。

  3. 白4選擇H9後,黑只好G9控制,如下面圖1,這樣黑既可以往下發展,也可以往左發展。

  4. 根據開局搶2原則,白6顯然走I7,擋對面的活2,自己成活2。

  5. 由於白6形成了新的活2,黑又沒有進攻可言,所以黑只能繼續控制,I6,把局勢繼續往下拉。

  6. 黑7選擇了I6,黑的連接點主要有G6和G8、F8。F8或G8是一個三通點,G6是活3點,所以G8要強於G6。本次我們討論G6。由於G8和白棋靠的較近,所以F8更強一些。

  7. 此時白10可選擇G8,斷黑的一個活2,自己成一個活2。

  8. 但此時黑的活2比較多,攻勢已經非常大,經過下面圖1的進攻線路可以取勝。

C. 求一個編寫的五子棋小游戲python的代碼,求借鑒啊!!急急急。。。

#五子棋importappuifw,e32,key_codes
fromgraphicsimport*defcn(x):returnx.decode('utf-8')
defquit():_quit=1
globalrunning
running=1
defredraw(rect):canvas.blit(img)defdefault():
globalcon,color,font
con={"l":15,"x":15,"y":33,"r":13,"n":15}
color={"bg":0x7777bb,"fg":0x333333,"p1":0x000000,"p2":0xffffff,"w":0xff0000}
font=u"SansMT936_S60"definitial():
globalimg,canvas,con,color,cur_x,cur_y,turn,pos1,pos2,pos
appuifw.app.screen='full'
appuifw.app.body=canvas=appuifw.Canvas()
img=Image.new((240,320))
img.clear(color["bg"])
cur_x=7
cur_y=7
turn=1
pos1=[]
pos2=[]
pos=[]
foriinrange(con["n"]*con["n"]):
pos.append(0)defpaint_back():
globalimg,color,font
#img.text((90,25),cn('歡樂五子棋'),color["fg"],font)
foriinrange(con["x"],con["x"]+con["l"]*con["n"]-1,con["l"]):
img.line((i,con["y"],i,con["y"]+con["l"]*(con["n"]-1)),color["fg"])
foriinrange(con["y"],con["y"]+con["l"]*con["n"]-1,con["l"]):
img.line((con["x"],i,con["x"]+con["l"]*(con["n"]-1),i),color["fg"])
img.text((40,270),cn('玩家1'),color["p1"],font)
img.text((160,270),cn('玩家2'),color["p2"],font)
img.point((90,263),color["p1"],width=con["r"],fill=color["p1"])
img.point((144,263),color["p2"],width=con["r"],fill=color["p2"])

defpaint_cur(x,y,sh):
globalimg,con,color,pos1,pos2,running
ifrunning<>1:return
ax=con["x"]+con["l"]*x
ay=con["y"]+con["l"]*y
b=con["l"]/2
ifsh<>0:
c=color["p"+str(sh)]
ifrp((x,y))<>0:
c=color["w"]
ifsh==0:
c=color["bg"]
img.line((ax-b,ay-2,ax-b,ay-b,ax-2,ay-b),c)
img.line((ax-b,ay+2,ax-b,ay+b,ax-2,ay+b),c)
img.line((ax+b,ay-2,ax+b,ay-b,ax+2,ay-b),c)
img.line((ax+b,ay+2,ax+b,ay+b,ax+2,ay+b),c)
redraw(())defpaint_q(x,y,z):
globalimg,con,color
ax=con["x"]+con["l"]*x
ay=con["y"]+con["l"]*y
b=con["l"]/2
ifz==0:
c=color["bg"]
else:
c=color["p"+str(z)]
img.point((ax,ay),c,width=con["r"],fill=c)
redraw(())
ifz==0:
img.line((ax-b,ay,ax+b,ay),c)
img.line((ax,ay-b,ax,ay+b),c)

defk_up():
globalcur_x,cur_y,con,turn
paint_cur(cur_x,cur_y,0)
cur_y=cur_y-1
ifcur_y==-1:
cur_y=con["n"]-1
paint_cur(cur_x,cur_y,turn)defk_down():
globalcur_x,cur_y,con,turn
paint_cur(cur_x,cur_y,0)
cur_y=cur_y+1
ifcur_y==con["n"]:
cur_y=0
paint_cur(cur_x,cur_y,turn)defk_left():
globalcur_x,cur_y,con,turn
paint_cur(cur_x,cur_y,0)
cur_x=cur_x-1
ifcur_x==-1:
cur_x=con["n"]-1
paint_cur(cur_x,cur_y,turn)defk_right():
globalcur_x,cur_y,con,turn
paint_cur(cur_x,cur_y,0)
cur_x=cur_x+1
ifcur_x==con["n"]:
cur_x=0
paint_cur(cur_x,cur_y,turn)defrp(x):
globalcon,pos
if(x[0]<0orx[0]>=con["n"]orx[1]<0orx[1]>=con["n"]):return0
#printx,pos[x[0]*con["n"]+x[1]]
returnpos[x[0]*con["n"]+x[1]]defwp(x,y):
globalcon,pos
pos[x[0]*con["n"]+x[1]]=y

defwin():
foriinpos1:
k=0
forjinrange(0,6):
ifrp((i[0]+j,i[1]))==1:
k=k+1
else:
break
ifk>=5:
return1
k=0
forjinrange(0,6):
ifrp((i[0],i[1]+j))==1:
k=k+1
else:
break
ifk>=5:
return1
k=0
forjinrange(0,6):
ifrp((i[0]+j,i[1]+j))==1:
k=k+1
else:
break
ifk>=5:
return1
k=0
forjinrange(0,6):
ifrp((i[0]+j,i[1]-j))==1:
k=k+1
else:
break
ifk>=5:
return1foriinpos2:
k=0
forjinrange(0,6):
ifrp((i[0]+j,i[1]))==2:
k=k+1
else:
break
ifk>=5:
return2
k=0
forjinrange(0,6):
ifrp((i[0],i[1]+j))==2:
k=k+1
else:
break
ifk>=5:
return2
k=0
forjinrange(0,6):
ifrp((i[0]+j,i[1]+j))==2:
k=k+1
else:
break
ifk>=5:
return2
k=0
forjinrange(0,6):
ifrp((i[0]+j,i[1]-j))==2:
k=k+1
else:
break
ifk>=5:
return2
return0

defk_enter():
globalcur_x,cur_y,turn,pos1,pos2,con,color,font,running
ifrunning<>1:return
ifrp((cur_x,cur_y))==0:
ifturn==1:
pos1.append((cur_x,cur_y))
img.rectangle((35,255,100,272),color["bg"])
img.rectangle((135,255,200,272),color["p2"])
ifturn==2:
pos2.append((cur_x,cur_y))
img.rectangle((35,255,100,272),color["p1"])
img.rectangle((135,255,200,272),color["bg"])
paint_q(cur_x,cur_y,turn)
wp((cur_x,cur_y),turn)
ifwin()<>0:
#img.text((80,300),cn('玩家')+str(turn)+cn("獲勝!"),color["fg"],font)
img.rectangle((35,255,100,272),color["bg"])
img.rectangle((135,255,200,272),color["bg"])
paint_cur(cur_x,cur_y,0)
running=2
turn=3-turn
paint_cur(cur_x,cur_y,turn)defbindkey():
canvas.bind(key_codes.EKeyUpArrow,k_up)
canvas.bind(key_codes.EKeyDownArrow,k_down)
canvas.bind(key_codes.EKeyLeftArrow,k_left)
canvas.bind(key_codes.EKeyRightArrow,k_right)
canvas.bind(key_codes.EKeySelect,k_enter)default()
initial()
paint_back()
paint_cur(cur_x,cur_y,1)
img.rectangle((35,255,100,272),color["p1"])
bindkey()redraw(())
appuifw.app.exit_key_handler=quit()
_quit=0
while(1-_quit):
e32.ao_sleep(0.2)
redraw(())

D. 在線等!求一個python 五子棋源代碼,最好是有「人人對弈」和「人機對弈」功能的,不勝感謝!

試試這個吧。
import numpy as np
import pygame
import sys
import traceback
import
from pygame.locals import *

pygame.init()
pygame.mixer.init()

#顏色
background=(201,202,187)
checkerboard=(80,80,80)
button=(52,53,44)

#音樂
play_chess_sound = pygame.mixer.Sound("music/play_chess.wav")
play_chess_sound.set_volume(0.2)
button_sound = pygame.mixer.Sound("music/button.wav")
button_sound.set_volume(0.2)
victor_sound = pygame.mixer.Sound("music/victory.wav")
victor_sound.set_volume(0.2)

#繪制棋盤
def Draw_a_chessboard(screen):
#填充背景色
screen.fill(background)
Background=pygame.image.load("background.jpg").convert_alpha()
screen.blit(Background,(0,0))
#畫棋盤
for i in range(21):
pygame.draw.line(screen, checkerboard, (40*i+3, 3), (40*i+3, 803))
pygame.draw.line(screen, checkerboard, (3, 40*i+3), (803, 40*i+3))
#畫邊線
pygame.draw.line(screen, checkerboard, (3, 3), (803, 3),5)
pygame.draw.line(screen, checkerboard, (3, 3), (3, 803),5)
pygame.draw.line(screen, checkerboard, (803, 3), (803, 803),5)
pygame.draw.line(screen, checkerboard, (3, 803), (803, 803),5)

#畫定位點
pygame.draw.circle(screen, checkerboard, (163, 163), 6)
pygame.draw.circle(screen, checkerboard, (163, 643), 6)
pygame.draw.circle(screen, checkerboard, (643, 163), 6)
pygame.draw.circle(screen, checkerboard, (643, 643), 6)
pygame.draw.circle(screen, checkerboard, (403, 403), 6)

#畫『悔棋』『重新開始』跟『退出』按鈕
pygame.draw.rect(screen,button,[900,350,120,100],5)
pygame.draw.rect(screen,button,[900,500,200,100],5)
pygame.draw.rect(screen,button,[900,650,200,100],5)
s_font=pygame.font.Font('font.ttf',40)
text1=s_font.render("悔棋",True,button)
text2=s_font.render("重新開始",True,button)
text3=s_font.render("退出遊戲",True,button)
screen.blit(text1,(920,370))
screen.blit(text2,(920,520))
screen.blit(text3,(920,670))

#繪制棋子(橫坐標,縱坐標,屏幕,棋子顏色(1代表黑,2代表白))
def Draw_a_chessman(x,y,screen,color):
if color==1:
Black_chess=pygame.image.load("Black_chess.png").convert_alpha()
screen.blit(Black_chess,(40*x+3-15,40*y+3-15))
if color==2:
White_chess=pygame.image.load("White_chess.png").convert_alpha()
screen.blit(White_chess,(40*x+3-15,40*y+3-15))

#繪制帶有棋子的棋盤
def Draw_a_chessboard_with_chessman(map,screen):
screen.fill(background)
Draw_a_chessboard(screen)
for i in range(24):
for j in range(24):
Draw_a_chessman(i+1,j+1,screen,map[i][j])

#定義存儲棋盤的列表,
#列表為24列24行是因為判斷是否勝利函數里的索引會超出19
#列表大一點不會對游戲有什麼影響
map=[]
for i in range(24):
map.append([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])

#清零map列表
def clear():
global map
for i in range(24):
for j in range(24):
map[i][j]=0

#判斷是否勝利
def win(i, j):
k = map[i][j]
p=[]
for a in range(20):
p.append(0)
for i3 in range(i-4,i+5):
for j3 in range(j-4,j+5):
if (map[i3][j3] == k and i3 - i == j3 - j and i3 <= i and j3 <= j):
p[0]+=1
if (map[i3][j3] == k and j3 == j and i3 <= i and j3 <= j):
p[1]+=1
if (map[i3][j3] == k and i3 == i and i3 <= i and j3 <= j):
p[2]+=1
if (map[i3][j3] == k and i3 - i == j3 - j and i3 >= i and j3 >= j):
p[3]+=1
if (map[i3][j3] == k and j3 == j and i3 >= i and j3 >= j):
p[4]+=1
if (map[i3][j3] == k and i3 == i and i3 >= i and j3 >= j):
p[5]+=1
if (map[i3][j3] == k and i - i3 == j3 - j and i3 <= i and j3 >= j):
p[6]+=1
if (map[i3][j3] == k and i3 - i == j - j3 and i3 >= i and j3 <= j):
p[7]+=1
if (map[i3][j3] == k and j - j3 == i - i3 and i3 <= i + 1 and i3 >= i - 3 and j3 <= j + 1 and j3 >= j - 3):
p[8]+=1
if (map[i3][j3] == k and j == j3 and i3 <= i + 1 and i3 >= i - 3 and j3 <= j + 1 and j3 >= j - 3):
p[9]+=1
if (map[i3][j3] == k and i == i3 and i3 <= i + 1 and i3 >= i - 3 and j3 <= j + 1 and j3 >= j - 3):
p[10]+=1
if (map[i3][j3] == k and j - j3 == i - i3 and i3 >= i - 1 and i3 <= i + 3 and j3 >= j - 1 and j3 <= j + 3):
p[11]+=1
if (map[i3][j3] == k and j == j3 and i3 >= i - 1 and i3 <= i + 3 and j3 >= j - 1 and j3 <= j + 3):
p[12]+=1
if (map[i3][j3] == k and i == i3 and i3 >= i - 1 and i3 <= i + 3 and j3 >= j - 1 and j3 <= j + 3):
p[13]+=1
if (map[i3][j3] == k and i - i3 == j3 - j and i3 <= i + 1 and i3 >= i - 3 and j3 >= j - 1 and j3 <= j + 3):
p[14]+=1
if (map[i3][j3] == k and i3 - i == j - j3 and i3 >= i - 1 and i3 <= i + 3 and j3 <= j + 1 and j3 >= j - 3):
p[15]+=1
if (map[i3][j3] == k and j - j3 == i - i3 and i3 <= i + 2 and i3 >= i - 2 and j3 <= j + 2 and j3 >= j - 2):
p[16]+=1
if (map[i3][j3] == k and j == j3 and i3 <= i + 2 and i3 >= i - 2 and j3 <= j + 2 and j3 >= j - 2):
p[17]+=1
if (map[i3][j3] == k and i == i3 and i3 <= i + 2 and i3 >= i - 2 and j3 <= j + 2 and j3 >= j - 2):
p[18]+=1
if (map[i3][j3] == k and i - i3 == j3 - j and i3 <= i + 2 and i3 >= i - 2 and j3 <= j + 2 and j3 >= j - 2):
p[19]+=1
for b in range(20):
if p[b]==5:
return True
return False

#繪制提示器(類容,屏幕,字大小)
def text(s,screen,x):
#先把上一次的類容用一個矩形覆蓋
pygame.draw.rect(screen,background,[850,100,1200,100])
#定義字體跟大小
s_font=pygame.font.Font('font.ttf',x)
#定義類容,是否抗鋸齒,顏色
s_text=s_font.render(s,True,button)
#將字放在窗口指定位置
screen.blit(s_text,(880,100))
pygame.display.flip()

#用於控制順序
t=True

#用於結束游戲後阻止落子
running=True

#主函數
def main():
#將 t,map,running設置為可改的
global t,map,running,maps,r,h
#將map置零
clear()
#定義儲存所有棋盤狀態的列表(用於悔棋)
map2=.deep(map)
maps=[map2]

#定義窗口
screen = pygame.display.set_mode([1200,806])

#定義窗口名字
pygame.display.set_caption("五子棋")

#在窗口畫出棋盤,提示器以及按鈕
Draw_a_chessboard(screen)
pygame.display.flip()
clock=pygame.time.Clock()
while True:
#只有running為真才能落子,主要用於游戲結束後防止再次落子
if running:
if t:
color=1
text('黑棋落子',screen,54)
else:
color=2
text('白棋落子',screen,54)

for event in pygame.event.get():
#點擊x則關閉窗口
if event.type ==pygame.QUIT:
pygame.quit()
sys.exit()

#點擊窗口裡面類容則完成相應指令
elif event.type == MOUSEBUTTONDOWN:
if event.button == 1:
x,y=event.pos[0],event.pos[1]
for i in range(19):
for j in range(19):
#點擊棋盤相應位置
if i*40+3+20<x<i*40+3+60 and j*40+3+20<y<j*40+3+60 and not map[i][j] and running:
#在棋盤相應位置落相應顏色棋子
Draw_a_chessman(i+1,j+1,screen,color)
#播放音效
play_chess_sound.play(0)
#在map裡面記錄落子位置
map[i][j]=color

#將map存入maps
map3=.deep(map)
maps.append(map3)

#判斷落子後是否有五子一線
if win(i,j):
if t:
text('黑棋勝利,請重新游戲',screen,30)
else:
text('白棋勝利,請重新游戲',screen,30)
#播放音效
victor_sound.play(0)
#阻止再往棋盤落子
running=False
pygame.display.flip()
t=not t
#如果點擊『重新開始』
if 900<x<1100 and 500<y<600:
#取消阻止
running=True
#播放音效
button_sound.play(0)
#重新開始
main()

#點擊『退出遊戲』,退出遊戲
elif 900<x<1100 and 650<y<750:
#播放音效
button_sound.play(0)
pygame.quit()
sys.exit()

#點擊『悔棋』
elif 900<x<1020 and 350<y<450 and len(maps)!=1:
#播放音效
button_sound.play(0)
#刪除maps里最後一個元素
del maps[len(maps)-1]
#再將最後一個元素給map
map=.deep(maps[len(maps)-1])
#切換順序
t=not t
#將map顯示出來
Draw_a_chessboard_with_chessman(map,screen)
#悔棋完成,阻止再次悔棋
x,y=0,0
clock.tick(60)
if __name__ == "__main__":
try:
main()
except SystemExit:
pass
except:
traceback.print_exc()
pygame.quit()
input()

E. Python五子棋偽代碼怎麼寫

顯示五子棋的操作指南
決定誰先走
創建一個空的五子棋棋盤
把棋盤顯示出來
當沒有人獲勝且不是平局時
一一如果輪到玩家
一一一一得到玩家的行棋位置
一一一一根據行棋位置更新棋盤
一一否則
一一一一計算得出電腦的行棋位置
一一一一根據行棋位置更新棋盤
一一顯示棋盤
一一切換行棋方
向贏家表示恭喜或聲明平局

F. 求解用python 編寫五子棋怎樣編寫判斷輸贏的函數,應該從哪方面考慮呢最好有代碼,,,,謝謝

你都做到這個程度了,當然就是高手了。 把棋子位置放在一個數回據里。然後做一個路徑搜答索演算法。只搜索8個方向,如果某個方向有5個子連在一起就贏了。

這是個笨方法,還有很多優化的地方,比如上一次搜索後,建立一個路徑數組。下一次,只需要檢驗上一次結果,並將新的棋子放進路徑里就可以了。 這樣就效率很高了。

具體的你自己研究。這個對你來說應該輕松啦。

G. 請用PYTHON編一個小游戲,如五子棋,連連看,貪吃蛇,掃雷,計算器等等

五子棋、貪吃蛇、掃雷、俄羅斯方塊、坦克大戰、FlappyBird,

源碼地址github

H. 找五子棋源代碼c++

#include "iostream"
#include <iomanip>
using namespace std;
const int M=20;
const int N=20;
int main()
{
char wei[M][N];
int k,i,j,x,y,flag=0;
cout<<"歡迎使用簡易雙人對戰五子棋游戲"<<endl;
cout<<"五子棋棋譜如下:"<<endl;
for(k=0;k<=N;k++)
cout<<setw(3)<<setfill(' ')<<k;
cout<<endl;
for(i=1;i<=M;i++)
{
cout<<setw(3)<<setfill(' ')<<i;
for(j=1;j<=N;j++)
{
wei[i][j]='-';
cout<<setw(3)<<setfill(' ')<<wei[i][j];
}
cout<<endl;
}
while(flag==0)
{
//紅方落子
cout<<"請紅方輸入落子位置:"<<endl;
loop1:
cout<<"請輸入落子的行數:";
cin>>x;
cout<<"請輸入落子的列數:";
cin>>y;
if(wei[x][y]=='-')
{
wei[x][y]='*';
for(k=0;k<=N;k++)
cout<<setw(3)<<setfill(' ')<<k;
cout<<endl;
for(i=1;i<=M;i++)
{
cout<<setw(3)<<setfill(' ')<<i;
for(j=1;j<=N;j++)
cout<<setw(3)<<setfill(' ')<<wei[i][j];
cout<<endl;
}
}
else
{
cout<<"你不能在這落子,請重新選擇落子位置:"<<endl;
goto loop1;
}
//判斷勝利
for(i=1;i<=M-4;i++)
{
for(j=1;j<=N-4;j++)
{
if(wei[i][j]=='*' && wei[i][j+1]=='*' && wei[i][j+2]=='*' && wei[i][j+3]=='*' && wei[i][j+4]=='*')
{
cout<<"恭喜紅方獲得簡易雙人對戰五子棋的勝利!耶~~~"<<endl;
flag=1;
break;
}
if(wei[i][j]=='*' && wei[i+1][j]=='*' && wei[i+2][j]=='*' && wei[i+3][j]=='*' && wei[i+4][j]=='*')
{
cout<<"恭喜紅方獲得簡易雙人對戰五子棋的勝利!耶~~~"<<endl;
flag=1;
break;
}
if(wei[i][j]=='*' && wei[i+1][j+1]=='*' && wei[i+2][j+2]=='*' && wei[i+3][j+3]=='*' && wei[i+4][j+4]=='*')
{
cout<<"恭喜紅方獲得簡易雙人對戰五子棋的勝利!耶~~~"<<endl;
flag=1;
break;
}
if(flag==1)
break;
}
}

//藍方落子
cout<<"請藍方輸入落子位置:"<<endl;
loop2:
cout<<"請輸入落子的行數:";
cin>>x;
cout<<"請輸入落子的列數:";
cin>>y;
if(wei[x][y]=='-')
{
wei[x][y]='#';
for(k=0;k<=N;k++)
cout<<setw(3)<<setfill(' ')<<k;
cout<<endl;
for(i=1;i<=M;i++)
{
cout<<setw(3)<<setfill(' ')<<i;
for(j=1;j<=N;j++)
cout<<setw(3)<<setfill(' ')<<wei[i][j];
cout<<endl;
}
}
else
{
cout<<"你不能在這落子,請重新選擇落子位置:";
goto loop2;
}

//判斷勝利
for(i=1;i<=M-4;i++)
{
for(j=1;j<=N-4;j++)
{
if(wei[i][j]=='#' && wei[i][j+1]=='#' && wei[i][j+2]=='#' && wei[i][j+3]=='#' && wei[i][j+4]=='#')
{
cout<<"恭喜藍方獲得簡易雙人對戰五子棋的勝利!耶~~~"<<endl;
flag=1;
break;
}
if(wei[i][j]=='#' && wei[i+1][j]=='#' && wei[i+2][j]=='#' && wei[i+3][j]=='#' && wei[i+4][j]=='#')
{
cout<<"恭喜藍方獲得簡易雙人對戰五子棋的勝利!耶~~~"<<endl;
flag=1;
break;
}
if(wei[i][j]=='#' && wei[i+1][j+1]=='#' && wei[i+2][j+2]=='#' && wei[i+3][j+3]=='#' && wei[i+4][j+4]=='#')
{
cout<<"恭喜藍方獲得簡易雙人對戰五子棋的勝利!耶~~~"<<endl;
flag=1;
break;
}
if(flag==1)
break;
}
}
}
return 0;
}

我運行過,沒有錯誤.

I. c ++五子棋源代碼

#include "iostream" #include <iomanip> using namespace std; const int M=20; const int N=20; int main() { char wei[M][N]; int k,i,j,x,y,flag=0; cout<<"歡迎使用簡易雙人對戰五子棋游戲"<<endl; cout<<"五子棋棋譜如下:"<<endl; for(k=0;k<=N;k++) cout<<setw(3)<<setfill(' ')<<k; cout<<endl; for(i=1;i<=M;i++) { cout<<setw(3)<<setfill(' ')<<i; for(j=1;j<=N;j++) { wei[i][j]='-'; cout<<setw(3)<<setfill(' ')<<wei[i][j]; } cout<<endl; } while(flag==0) { //紅方落子 cout<<"請紅方輸入落子位置:"<<endl; loop1: cout<<"請輸入落子的行數:"; cin>>x; cout<<"請輸入落子的列數:"; cin>>y; if(wei[x][y]=='-') { wei[x][y]='*'; for(k=0;k<=N;k++) cout<<setw(3)<<setfill(' ')<<k; cout<<endl; for(i=1;i<=M;i++) { cout<<setw(3)<<setfill(' ')<<i; for(j=1;j<=N;j++) cout<<setw(3)<<setfill(' ')<<wei[i][j]; cout<<endl; } } else { cout<<"你不能在這落子,請重新選擇落子位置:"<<endl; goto loop1; } //判斷勝利 for(i=1;i<=M-4;i++) { for(j=1;j<=N-4;j++) { if(wei[i][j]=='*' && wei[i][j+1]=='*' && wei[i][j+2]=='*' && wei[i][j+3]=='*' && wei[i][j+4]=='*') { cout<<"恭喜紅方獲得簡易雙人對戰五子棋的勝利!耶~~~"<<endl; flag=1; break; } if(wei[i][j]=='*' && wei[i+1][j]=='*' && wei[i+2][j]=='*' && wei[i+3][j]=='*' && wei[i+4][j]=='*') { cout<<"恭喜紅方獲得簡易雙人對戰五子棋的勝利!耶~~~"<<endl; flag=1; break; } if(wei[i][j]=='*' && wei[i+1][j+1]=='*' && wei[i+2][j+2]=='*' && wei[i+3][j+3]=='*' && wei[i+4][j+4]=='*') { cout<<"恭喜紅方獲得簡易雙人對戰五子棋的勝利!耶~~~"<<endl; flag=1; break; } if(flag==1) break; } } //藍方落子 cout<<"請藍方輸入落子位置:"<<endl; loop2: cout<<"請輸入落子的行數:"; cin>>x; cout<<"請輸入落子的列數:"; cin>>y; if(wei[x][y]=='-') { wei[x][y]='#'; for(k=0;k<=N;k++) cout<<setw(3)<<setfill(' ')<<k; cout<<endl; for(i=1;i<=M;i++) { cout<<setw(3)<<setfill(' ')<<i; for(j=1;j<=N;j++) cout<<setw(3)<<setfill(' ')<<wei[i][j]; cout<<endl; } } else { cout<<"你不能在這落子,請重新選擇落子位置:"; goto loop2; } //判斷勝利 for(i=1;i<=M-4;i++) { for(j=1;j<=N-4;j++) { if(wei[i][j]=='#' && wei[i][j+1]=='#' && wei[i][j+2]=='#' && wei[i][j+3]=='#' && wei[i][j+4]=='#') { cout<<"恭喜藍方獲得簡易雙人對戰五子棋的勝利!耶~~~"<<endl; flag=1; break; } if(wei[i][j]=='#' && wei[i+1][j]=='#' && wei[i+2][j]=='#' && wei[i+3][j]=='#' && wei[i+4][j]=='#') { cout<<"恭喜藍方獲得簡易雙人對戰五子棋的勝利!耶~~~"<<endl; flag=1; break; } if(wei[i][j]=='#' && wei[i+1][j+1]=='#' && wei[i+2][j+2]=='#' && wei[i+3][j+3]=='#' && wei[i+4][j+4]=='#') { cout<<"恭喜藍方獲得簡易雙人對戰五子棋的勝利!耶~~~"<<endl; flag=1; break; } if(flag==1) break; } } } return 0; } 我運行過