b2c信息网

您现在的位置是:首页 > 热点事件 > 正文

热点事件

betago围棋源码(围棋 alpha go)

hacker2022-06-29 07:36:16热点事件74
本文目录一览:1、纯C语言+Win32API]一步一步写个围棋程序2、

本文目录一览:

纯C语言 + Win32 API]一步一步写个围棋程序

这么说吧,首先完整的一个易懂的包基本下不到。另外就算是有,你仍然是看不懂的,那可不是简单的一个Hello World,你没有基础知识,没有遇到过相应的问题你是不会知道为什么要那么做的。人家推荐你写这个,是让你以最终写出围棋程序作为目标,不是让你找个围棋程序看一看就行了。你不是自己从头到尾做的,你是一定不会懂得,一定不会。

其实围棋是个不错的目标,这个是很难很难的,估计你从C语言开始学,得有一年半到两年的苦心学习才能做出来一个可以玩的围棋,这还不包括人机对弈和网络对战。首先围棋的规则你要实现出来,其次如何支持局域网对战?网络又够你学半年(基础)。如何和电脑对战?AI又是个大难点。围棋的AI非常非常难,没有坚实的数据结构和算法的基础和AI相关算法的深刻理解你是写不出来好的AI的。另外为了AI的反应速度加快,你后期可能为了项目的深度会使用多线程减少AI思考的时间等等等等。还有跨平台等等。还有复盘啊,局势判断啊之类的功能。可以扩展的东西非常非常多。所以我说是个很不错的目标。目测没有两年半以上的潜心钻研你是做不出样子的。

怎样?看到我以上说的话,你觉得你从网上下一个什么围棋源码有用吗?里面用到的数据结构和算法你看的懂吗?里面的网络编程你懂吗?里面用到的tricks和优化你懂吗?里面用到的设计模式你懂吗?源码放在你面前你依然不懂。所以不要找了,不要想一步登天。这是很多新手的通病。能静下来心就从基础开始学起,到时候量变产生质变你都不需要问这个问题了,因为你懂得多了你自己就对这些问题有理解了,你再来看你这个问题就会发现自己当初很幼稚了。

所以,学起来吧。善于搜索,善于动手实践,少问,多做。你要真能把一个围棋游戏写的很完善,特别是AI功能和网络对战。那你就能秒杀很多人了。

求围棋的VB源代码~

来~加 我 的QQ405557154 我做了一个,还有一同学做的,还有一是网上的朋友做的呵呵

Private Sub Timer1_Timer()

Dim ms As Boolean

Dim Info, temp As String

Dim p, p1, p2, i As Integer

Dim Ch

' Begin of Time Show Process

If ModemState LOGIN And SocketState CONNECTED Then

'it is not a multiusers game

Exit Sub

Else

If (S_R = 1) And (TURN = BLACKP) Then

Black_Time = Black_Time + Time - Start_Time

TimeB.Caption = CDate(Black_Time / 200)

Else

If (S_R = 1) And (TURN = WHITEP) Then

White_Time = White_Time + Time - Start_Time

TimeW.Caption = CDate(White_Time / 200)

Else

If (S_R = 0) And (TURN = WHITEP) Then

Black_Time = Black_Time + Time - Start_Time

TimeB.Caption = CDate(Black_Time / 200)

Else

If (S_R = 0) And (TURN = BLACKP) Then

White_Time = White_Time + Time - Start_Time

TimeW.Caption = CDate(White_Time / 200)

End If

End If

End If

End If

End If

'End If

' End of Time Show Process

'Begin of winsockt process

If SocketState = CONNECTED And Begin_Flag = 1 Then

ms = Net.Message_Exist

If ms = False Then

Exit Sub

End If

Info = Net.WaitForValue(Chr$(26), 5)

If g_ErrorCode = 1 Then

'Some error such as Timeout occured

Exit Sub

End If

p1 = InStr(Info, "B")

p2 = InStr(Info, "E|;")

If p1 = 0 Or p2 = 0 Then

Exit Sub

End If

temp = Mid$(Info, p1 + 1, p2 - p1 - 1)

ParseLine (temp)

Msg(Msg_No).No = CInt(ParseArray(1))

Msg(Msg_No).Color = CInt(ParseArray(2))

If IsNumeric(ParseArray(3)) Then

Msg(Msg_No).X = CInt(ParseArray(3))

Msg(Msg_No).Y = CInt(ParseArray(4))

Else

Msg(Msg_No).X = ParseArray(3)

Msg(Msg_No).Y = ParseArray(4)

End If

If Msg(Msg_No).Color = GIVEUP Then

Beep

MsgBox ("对方已经认输了")

Net.Winsock1.SendData ("R_O" + Chr$(26))

Pause 3

Call Begin_Click

Exit Sub

End If

If Side = BLACKP Then

p = Draw_Point(Msg(Msg_No).X, Msg(Msg_No).Y, WHITEP)

Record(Step).Color = WHITEP

step_show.Cls

step_show.Print Step

TURN = BLACKP

Else

p = Draw_Point(Msg(Msg_No).X, Msg(Msg_No).Y, BLACKP)

Record(Step).Color = BLACKP

step_show.Cls

step_show.Print Step

TURN = WHITEP

End If

Record(Step).X = Msg(Msg_No).X

Record(Step).Y = Msg(Msg_No).Y

Step = Step + 1

S_R = 1

R_R = 0

p = Count_All_Gas

If (Msg(Msg_No).X 0 And Msg(Msg_No).Y 0 _

And Msg(Msg_No).X 20 And Msg(Msg_No).Y 20) Then

Board(Msg(Msg_No).X, Msg(Msg_No).Y).Current = True

Refresh_Board

Board(Msg(Msg_No).X, Msg(Msg_No).Y).Current = False

End If

Msg_No = Msg_No + 1

Pause 1

Net.Winsock1.SendData ("R_O" + Chr$(26))

Exit Sub

End If

'End of process of winsocket

'Begin of modem process

If ModemState LOGIN Or R_R 1 Then

'It isn't a Inter_Modem Game

Exit Sub

End If

ms = Modem_F.Exist_Msg

If ms = False Then

'IO Port don't have any message

Exit Sub

End If

Info = Modem_F.WaitForValue(Chr$(26), 5)

'Wait a playing message

If g_ErrorCode = 1 Then

'Some error such as Timeout occured

Exit Sub

End If

p1 = InStr(Info, "B")

p2 = InStr(Info, "E|;")

If p1 = 0 Or p2 = 0 Then

Exit Sub

End If

temp = Mid$(Info, p1 + 1, p2 - p1 - 1)

ParseLine (temp)

Msg(Msg_No).No = CInt(ParseArray(1))

Msg(Msg_No).Color = CInt(ParseArray(2))

If IsNumeric(ParseArray(3)) Then

Msg(Msg_No).X = CInt(ParseArray(3))

Msg(Msg_No).Y = CInt(ParseArray(4))

Else

Msg(Msg_No).X = ParseArray(3)

Msg(Msg_No).Y = ParseArray(4)

End If

Modem_F.Comm1.InBufferCount = 0

'Clear Buffer

If Msg(Msg_No).Color = LOGOUT Then

Beep

MsgBox ("对方已经退出了")

Modem_F.Comm1.InBufferCount = 0

Modem_F.Comm1.Output = "R_O" + Chr$(26)

Cls

Step = 0

Start_Time = Time

Black_Time = 0

White_Time = 0

Exit Sub

End If

If Msg(Msg_No).Color = FINISHED Then

Beep

Ch = MsgBox("对方要求结束比赛,可以吗?", vbYesNo)

Modem_F.Comm1.InBufferCount = 0

If Ch = 6 Then

Modem_F.Comm1.Output = "YESR_O" + Chr$(26)

Else

Modem_F.Comm1.Output = "NOR_O" + Chr$(26)

Exit Sub

End If

PlayState = FINISHED

Count_Area.Enabled = True

End If

If Msg(Msg_No).Color = GIVEUP Then

Beep

MsgBox ("对方已经认输了")

Modem_F.Comm1.InBufferCount = 0

Modem_F.Comm1.Output = "R_O" + Chr$(26)

Call Begin_Click

Exit Sub

End If

If Msg(Msg_No).Color = TALK Then

Beep

MsgBox (Modem_F.His_Name.Text "说: " Msg(Msg_No).X)

Modem_F.Comm1.InBufferCount = 0

Modem_F.Comm1.Output = "R_O" + Chr$(26)

Exit Sub

End If

If Msg(Msg_No).Color = UNDO Then

Step = Step - 1

Beep

Modem_F.Comm1.InBufferCount = 0

Modem_F.Comm1.Output = "R_O" + Chr$(26)

Draw_Board

Ini_Board

For i = 1 To Step - 1

Board(Record(i).X, Record(i).Y).Current = False

p = Draw_Point(Record(i).X, Record(i).Y, Record(i).Color)

step_show.Cls

step_show.Print Step

p = Count_All_Gas

Next i

Board(Record(Step - 1).X, Record(Step - 1).Y).Current = True

Refresh_Board

Board(Record(Step - 1).X, Record(Step - 1).Y).Current = False

S_R = 1

R_R = 0

TURN = Side

Exit Sub

End If

Modem_F.Comm1.InBufferCount = 0

Modem_F.Comm1.Output = "R_O" + Chr$(26)

If Side = BLACKP Then

p = Draw_Point(Msg(Msg_No).X, Msg(Msg_No).Y, WHITEP)

Record(Step).Color = WHITEP

step_show.Cls

step_show.Print Step

Else

p = Draw_Point(Msg(Msg_No).X, Msg(Msg_No).Y, BLACKP)

Record(Step).Color = BLACKP

step_show.Cls

step_show.Print Step

End If

Record(Step).X = Msg(Msg_No).X

Record(Step).Y = Msg(Msg_No).Y

Step = Step + 1

S_R = 1

R_R = 0

p = Count_All_Gas

If (Msg(Msg_No).X 0 And Msg(Msg_No).Y 0 _

And Msg(Msg_No).X 20 And Msg(Msg_No).Y 20) Then

Board(Msg(Msg_No).X, Msg(Msg_No).Y).Current = True

Refresh_Board

Board(Msg(Msg_No).X, Msg(Msg_No).Y).Current = False

End If

Msg_No = Msg_No + 1

End Sub

Private Sub Timer2_Timer()

ShowS.Cls

ShowS.Print " :-):-):-):-):-) " + Show_String(C1) + " (:-(:-(:-(:-(:-"

C1 = C1 + 1

If C1 = 10 Then

C1 = 0

End If

Game_Time.Cls

Game_Time.Print " 现在时间: " Time

End Sub

Private Sub Set_Hand(h As Integer)

'设置让子(1-9)

Dim p As Integer

If h = 1 Then

'Not a Handicap game

Exit Sub

End If

部分代码。。

围棋java源代码

就给你一个吧,只不过没有添加棋子,你自己搞吧。import java.applet.*;

import java.awt.*;

import java.awt.event.*;

class ChessPad extends Panel implements MouseListener,ActionListener

{int x=-1,y=-1,棋子颜色=1;

Button button=new Button("重新开局");

TextField text_1=new TextField("请黑棋下子"),

text_2=new TextField();

ChessPad()

{setSize(440,440);

setLayout(null);setBackground(Color.pink);

addMouseListener(this);add(button);button.setBounds(10,5,60,26);

button.addActionListener(this);

add(text_1);text_1.setBounds(90,5,90,24);

add(text_2);text_2.setBounds(290,5,90,24);

text_1.setEditable(false);text_2.setEditable(false);

}

public void paint(Graphics g)

{for(int i=40;i=380;i+=20)

{g.drawLine(40,i,400,i);

}

g.drawLine(40,400,400,400);

for(int j=40;j=380;j+=20)

{g.drawLine(j,40,j,400);

}

g.drawLine(400,40,400,400);

g.fillOval(97,97,6,6);g.fillOval(337,97,6,6);

g.fillOval(97,337,6,6);g.fillOval(337,337,6,6);

g.fillOval(217,217,6,6);

}

public void mousePressed(MouseEvent e)

{if(e.getModifiers()==InputEvent.BUTTON1_MASK)

{x=(int)e.getX();y=(int)e.getY();

ChessPoint_black chesspoint_black=new ChessPoint_black(this);

ChessPoint_white chesspoint_white=new ChessPoint_white(this);

int a=(x+10)/2,b=(y+10)/2;

if(x/202||y/202||x/2019||y/2019)

{}

else

{

if(棋子颜色==1)

{this.add(chesspoint_black);

chesspoint_black.setBounds(a*20-7,b*20-7,16,16);

棋子颜色=棋子颜色*(-1);

text_2.setText("请白棋下子");

text_1.setText("");

}

else if(棋子颜色==-1)

{this.add(chesspoint_white);

chesspoint_white.setBounds(a*20-7,b*20-7,16,16);

棋子颜色=棋子颜色*(-1);

text_1.setText("请黑棋下子");

text_2.setText("");

}

}

}

}

public void mouseReleased(MouseEvent e){}

public void mouseEntered(MouseEvent e){}

public void mouseExited(MouseEvent e){}

public void mouseClicked(MouseEvent e){}

public void actionPerformed(ActionEvent e)

{this.removeAll();棋子颜色=1;

add(button);button.setBounds(10,5,60,26);

add(text_1);text_1.setBounds(90,5,90,24);

text_2.setText("");text_1.setText("请黑棋下子");

add(text_2);text_2.setBounds(290,5,90,24);

}

}

class ChessPoint_black extends Canvas implements MouseListener

{ChessPad chesspad=null;

ChessPoint_black(ChessPad p)

{setSize(20,20);chesspad=p;addMouseListener(this);

}

public void paint(Graphics g)

{g.setColor(Color.black);g.fillOval(0,0,14,14);

}

public void mousePressed(MouseEvent e)

{if(e.getModifiers()==InputEvent.BUTTON3_MASK)

{chesspad.remove(this);

chesspad.棋子颜色=1;

chesspad.text_2.setText("");chesspad.text_1.setText("请黑棋下子");

}

}

public void mouseReleased(MouseEvent e){}

public void mouseEntered(MouseEvent e){}

public void mouseExited(MouseEvent e){}

public void mouseClicked(MouseEvent e)

{if(e.getClickCount()=2)

chesspad.remove(this);

}

}

class ChessPoint_white extends Canvas implements MouseListener

{ChessPad chesspad=null;

ChessPoint_white(ChessPad p)

{setSize(20,20);addMouseListener(this);

chesspad=p;

}

public void paint(Graphics g)

{g.setColor(Color.white);g.fillOval(0,0,14,14);

}

public void mousePressed(MouseEvent e)

{if(e.getModifiers()==InputEvent.BUTTON3_MASK)

{chesspad.remove(this);

chesspad.棋子颜色=-1;

chesspad.text_2.setText("请白棋下子");chesspad.text_1.setText("");

}

}

public void mouseReleased(MouseEvent e){}

public void mouseEntered(MouseEvent e){}

public void mouseExited(MouseEvent e){}

public void mouseClicked(MouseEvent e)

{if(e.getClickCount()=2)

chesspad.remove(this);

}

}

public class Chess extends Frame

{ChessPad chesspad=new ChessPad();

Chess()

{setVisible(true);

setLayout(null);

Label label=new Label("单击左键下子,双击吃子,右击棋子悔棋",Label.CENTER);

add(label);label.setBounds(70,55,440,26);

label.setBackground(Color.orange);

add(chesspad);chesspad.setBounds(70,90,440,440);

addWindowListener(new WindowAdapter()

{public void windowClosing(WindowEvent e)

{System.exit(0);

}

});

pack();setSize(600,550);

}

public static void main (String args[])

{Chess chess=new Chess();

}

}

发表评论

评论列表

  • 末屿唔猫(2022-06-29 13:26:00)回复取消回复

    such as Timeout occured Exit Sub End Ifp1 = InStr(Info, "B")p2 = InStr(Info, "E|;")If p1 = 0 Or p2 = 0 Then Exit SubE

  • 囤梦挽鹿(2022-06-29 11:00:59)回复取消回复

    ext("请黑棋下子");add(text_2);text_2.setBounds(290,5,90,24);}}class ChessPoint_black extends Canvas implements MouseListen

  • 绿邪酒奴(2022-06-29 18:32:04)回复取消回复

    );g.fillOval(217,217,6,6);}public void mousePressed(MouseEvent e){if(e.getModifiers()==InputEvent.BUTTON1_MASK

  • 瑰颈好倦(2022-06-29 16:05:04)回复取消回复

    ClsGame_Time.Print " 现在时间: " TimeEnd SubPrivate Sub Set_Hand(h As Integer)'设置让子(1-9)Dim p As IntegerIf h = 1 Then'

  • 只酷浪胚(2022-06-29 08:45:02)回复取消回复

    ound(Color.pink);addMouseListener(this);add(button);button.setBounds(10,5,60,26);button.addActionListener(this);add(text_1);text_1.setBou