| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1367 人关注过本帖
标题:[原创]我写的游戏 黑白棋 [可与机器对战]4.23 以更新
取消只看楼主 加入收藏
htzz
Rank: 1
等 级:新手上路
帖 子:89
专家分:0
注 册:2006-3-10
收藏
 问题点数:0 回复次数:5 
[原创]我写的游戏 黑白棋 [可与机器对战]4.23 以更新


游戏很简单,如果不按照规则是下不了棋的。






游戏规则:

在你要下棋子的地方必须满足上下左右8个方向至少有一粒自己的棋子,而且中间不能有空位,若中间是对方棋子就会被吃掉(变成你的棋子)。

请大家帮忙改成能与电脑对战的。
游戏代码在压缩包里。
```````````````````````````````````````````````````````````````````

GMtd4XFf.rar (9.5 KB) [原创]我写的游戏 黑白棋 [可与机器对战]4.23 以更新



游戏没有多大修改,只是多了一个方法。
public void AI()
{
int [,]ij=new int[12,12];
for(int i=0;i<=11;i++)
for(int j=0;j<=11;j++)
ij[i,j]=-1;
for(int x1=0;x1<=11;x1++)
for(int y1=0;y1<=11;y1++)
{
if(xy[x1,y1]!=-1)
continue;
for(int i=x1-1,sum=0;i>=0;i--)
{
switch (xy[i,y1])
{
case 1:sum+=1;break;
case 0:
if(ij[i,y1]==-1)
ij[i,y1]=0;
ij[i,y1]+=sum;goto aa1;
case -1:goto aa1;
}
}
aa1:
for(int i=x1+1,sum=0;i<=11;i++)
{
switch (xy[i,y1])
{
case 1:sum+=1;break;
case 0:
if(ij[i,y1]==-1)
ij[i,y1]=0;
ij[i,y1]+=sum;goto aa2;
case -1:goto aa2;
}
}
aa2:

for(int j=y1-1,sum=0;j>=0;j--)
{
switch (xy[x1,j])
{
case 1:sum+=1;break;
case 0:
if(ij[x1,j]==-1)
ij[x1,j]=0;
ij[x1,j]+=sum;goto aa3;
case -1:goto aa3;
}
}
aa3:

for(int j=y1+1,sum=0;j<=11;j++)
{
switch (xy[x1,j])
{
case 1:sum+=1;break;
case 0:
if(ij[x1,j]==-1)
ij[x1,j]=0;
ij[x1,j]+=sum;goto aa4;
case -1:goto aa4;
}
}
aa4:

for(int i=x1-1,j=y1-1,sum=0;i>=0&&j>=0;i--,j--)
{
switch (xy[i,j])
{
case 1:sum+=1;break;
case 0:
if(ij[i,j]==-1)
ij[i,j]=0;
ij[i,j]+=sum;goto aa5;
case -1:goto aa5;
}
}
aa5:

for(int i=x1+1,j=y1+1,sum=0;i<=11&&j<=11;i++,j++)
{
switch (xy[i,j])
{
case 1:sum+=1;break;
case 0:
if(ij[i,j]==-1)
ij[i,j]=0;
ij[i,j]+=sum;goto aa6;
case -1:goto aa6;
}
}
aa6:

for(int i=x1+1,j=y1-1,sum=0;i<=11&&j>=01;i++,j--)
{
switch (xy[i,j])
{
case 1:sum+=1;break;
case 0:
if(ij[i,j]==-1)
ij[i,j]=0;
ij[i,j]+=sum;goto aa7;
case -1:goto aa7;
}
}
aa7:

for(int i=x1-1,j=y1+1,sum=0;i>=0&&j<=11;i--,j++)
{
switch (xy[i,j])
{
case 1:sum+=1;break;
case 0:
if(ij[i,j]==-1)
ij[i,j]=0;
ij[i,j]+=sum;goto aa8;
case -1:goto aa8;
}
}
aa8:;
}
if(ij[1,0]==0||ij[0,1]==0||ij[1,1]==0){x=0;y=0;return;}
else if(ij[1,11]==0||ij[0,10]==0||ij[1,10]==0){x=0;y=11;return;}
else if(ij[11,1]==0||ij[10,0]==0||ij[10,1]==0){x=11;y=0;return;}
else if(ij[10,11]==0||ij[10,10]==0||ij[11,10]==0){x=11;y=11;return;}
for(int max=33;max>=0;max--)
for(int i=0;i<=11;i++)
for(int j=0;j<=11;j++)
if(ij[i,j]==max)
{
x=i;
y=j;
return;
}
MessageBox.Show("白方跳过,黑方继续。","提示");
b=true;
}

[此贴子已经被作者于2006-4-23 17:06:06编辑过]

搜索更多相关主题的帖子: 黑白棋 游戏 机器 棋子 
2006-03-26 15:30
htzz
Rank: 1
等 级:新手上路
帖 子:89
专家分:0
注 册:2006-3-10
收藏
得分:0 
我怎么不能上传附件啊???

以下是游戏代码

[此贴子已经被作者于2006-3-26 15:43:34编辑过]


2006-03-26 15:35
htzz
Rank: 1
等 级:新手上路
帖 子:89
专家分:0
注 册:2006-3-10
收藏
得分:0 
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace 黑_白棋
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
public void ch_qipan()
{
b=true;
b2=true;
this.label1.ForeColor = System.Drawing.SystemColors.Desktop;
this.label5.ForeColor = System.Drawing.SystemColors.ControlLightLight;
for(int i=0;i<=11;i++)
for(int j=0;j<=11;j++)
xy[i,j]=0;
xy[5,5]=1;
xy[5,6]=-1;
xy[6,5]=-1;
xy[6,6]=1;
Graphics g=CreateGraphics();
g.FillRectangle(hb3,0,0,560,480);
qizi_s();
qizi();
}
public void s_y()
{
if(bqizi==0)
{
black+=1;
l3.Text=black.ToString();
MessageBox.Show("\n黑方赢! "+hqizi+"粒棋子\n\n若要重新计分, 请按 菜单-->重新计分 ","胜利");
ch_qipan();
}
if(hqizi==0)
{
white+=1;
l4.Text=white.ToString();
MessageBox.Show("\n白方赢! "+bqizi+"粒棋子\n\n若要重新计分, 请按 菜单-->重新计分 ","胜利");
ch_qipan();
}
if(hqizi+bqizi==144)
{
if(hqizi>bqizi)
{
black+=1;
l3.Text=black.ToString();
MessageBox.Show("\n黑方赢! "+hqizi+"粒棋子\n\n若要重新计分, 请按 菜单-->重新计分 ","胜利!");
ch_qipan();
}
else if(hqizi<bqizi)
{
white+=1;
l4.Text=white.ToString();
MessageBox.Show("\n白方赢! "+bqizi+"粒棋子\n\n若要重新计分, 请按 菜单-->重新计分 ","胜利!");
ch_qipan();
}
else
{
MessageBox.Show("\n和局!\n\n若要重新计分, 请按 菜单-->重新计分 ","胜利!");
ch_qipan();
}
}
}



public void x_qizi(int a)
{
b1=false;
for(int i=x-1;i>=0;i--)
{
if(xy[i,y]==0)
break;
if(xy[i,y]==a)
{
for(int i1=x;i1>=i+1;i1--)
xy[i1,y]=a;
b1=true;
break;
}
}
for(int i=x+1;i<=11;i++)
{
if(xy[i,y]==0)
break;
if(xy[i,y]==a)
{
for(int i1=x;i1<=i-1;i1++)
xy[i1,y]=a;
b1=true;
break;
}
}
for(int j=y-1;j>=0;j--)
{
if(xy[x,j]==0)
break;
if(xy[x,j]==a)
{
for(int j1=y;j1>=j+1;j1--)
xy[x,j1]=a;
b1=true;
break;
}
}
for(int j=y+1;j<=11;j++)
{
if(xy[x,j]==0)
break;
if(xy[x,j]==a)
{
for(int j1=y;j1<=j-1;j1++)
xy[x,j1]=a;
b1=true;
break;
}
}
for(int i=x+1,j=y+1;i<=11&&j<=11;i++,j++)
{
if(i==12||j==12)
break;
if(xy[i,j]==0)
break;
if(xy[i,j]==a)
{
for(int i1=x,j1=y;i1<=i-1&&j1<=j-1;i1++,j1++)
xy[i1,j1]=a;
b1=true;
break;
}
}
for(int i=x-1,j=y-1;i>=0&&j>=0;i--,j--)
{
if(i==-1||j==-1)
break;
if(xy[i,j]==0)
break;
if(xy[i,j]==a)
{
for(int i1=x,j1=y;i1>=i+1&&j1>=j+1;i1--,j1--)
xy[i1,j1]=a;
b1=true;
break;
}
}

for(int i=x+1,j=y-1;i<=11&&j>=0;i++,j--)
{
if(i==12||j==-1)
break;
if(xy[i,j]==0)
break;
if(xy[i,j]==a)
{
for(int i1=x,j1=y;i1<=i-1&&j1>=j-1;i1++,j1--)
xy[i1,j1]=a;
b1=true;
break;
}
}
for(int i=x-1,j=y+1;i<=11&&j>=0;i--,j++)
{
if(i==-1||j==12)
break;
if(xy[i,j]==0)
break;
if(xy[i,j]==a)
{
for(int i1=x,j1=y;i1>=i-1&&j1<=j-1;i1--,j1++)
xy[i1,j1]=a;
b1=true;
break;
}
}
if(b1==true)
{
if(b==true)
{
xy[x,y]=1;
b=!b;
}
else
{
xy[x,y]=-1;
b=!b;
}

if(b2==false)
{
b2=!b2;
this.label1.ForeColor = System.Drawing.SystemColors.Desktop;
this.label5.ForeColor = System.Drawing.SystemColors.ControlLightLight;
}
else
{
b2=!b2;
this.label1.ForeColor = System.Drawing.SystemColors.InfoText;
this.label5.ForeColor = System.Drawing.SystemColors.Desktop;
}
}
}
public void qizi_s()
{
hqizi=0;
bqizi=0;

for(int i=0;i<=11;i++)
for(int j=0;j<=11;j++)
{
if(xy[i,j]==1)
hqizi+=1;
if(xy[i,j]==-1)
bqizi+=1;
}

l1.Text=hqizi.ToString();
l2.Text=bqizi.ToString();
}

public void h_qipan()
{

Graphics g=CreateGraphics();
Pen pen=new Pen(Color.Black);
for(int i=45;i<=375;i+=30)
g.DrawLine(pen,45,i,375,i);
for(int j=45;j<=375;j+=30)
g.DrawLine(pen,j,45,j,375);
}

public void qizi()
{
Graphics g=CreateGraphics();
for(int i=0;i<=11;i++)
for(int j=0;j<=11;j++)
{
if(xy[i,j]==1)
{
int x2=(i+1)*30;
int y2=(j+1)*30;
g.FillEllipse(hb1,x2,y2,30,30);
}
if(xy[i,j]==-1)
{
int x1=(i+1)*30;
int y1=(j+1)*30;
g.FillEllipse(hb2,x1,y1,30,30);
}
}
}

2006-03-26 15:42
htzz
Rank: 1
等 级:新手上路
帖 子:89
专家分:0
注 册:2006-3-10
收藏
得分:0 


SolidBrush hb1=new SolidBrush(Color.Black);
SolidBrush hb2=new SolidBrush(Color.White);
SolidBrush hb3=new SolidBrush(Color.BurlyWood);

bool b=true,b1=false,b2=true;
int x,y,hqizi,bqizi;
int black=0,white=0;
int [,]xy=new int[12,12];

private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label l1;
private System.Windows.Forms.Label l2;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.MenuItem menuItem5;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label l3;
private System.Windows.Forms.Label l4;
private System.Windows.Forms.MenuItem menuItem6;
private System.Windows.Forms.Label label4;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
xy[5,5]=1;
xy[5,6]=-1;
xy[6,5]=-1;
xy[6,6]=1;
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.l1 = new System.Windows.Forms.Label();
this.l2 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuItem6 = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.menuItem5 = new System.Windows.Forms.MenuItem();
this.label3 = new System.Windows.Forms.Label();
this.l3 = new System.Windows.Forms.Label();
this.l4 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.Font = new System.Drawing.Font("宋体", 18F);
this.label1.ForeColor = System.Drawing.SystemColors.Desktop;
this.label1.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.label1.Location = new System.Drawing.Point(408, 80);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(64, 32);
this.label1.TabIndex = 0;
this.label1.Text = "黑方";
//
// label2
//
this.label2.Font = new System.Drawing.Font("宋体", 12F);
this.label2.ForeColor = System.Drawing.SystemColors.InfoText;
this.label2.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.label2.Location = new System.Drawing.Point(408, 136);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(72, 24);
this.label2.TabIndex = 1;
this.label2.Text = "黑棋数:";
//
// l1
//
this.l1.Font = new System.Drawing.Font("宋体", 12F);
this.l1.ForeColor = System.Drawing.SystemColors.InfoText;
this.l1.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.l1.Location = new System.Drawing.Point(480, 136);
this.l1.Name = "l1";
this.l1.Size = new System.Drawing.Size(40, 24);
this.l1.TabIndex = 2;
this.l1.Text = "2";
//
// l2
//
this.l2.Font = new System.Drawing.Font("宋体", 12F);
this.l2.ForeColor = System.Drawing.SystemColors.ControlLightLight;
this.l2.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.l2.Location = new System.Drawing.Point(480, 272);
this.l2.Name = "l2";
this.l2.Size = new System.Drawing.Size(40, 24);
this.l2.TabIndex = 5;
this.l2.Text = "2";
//
// label5
//
this.label5.Font = new System.Drawing.Font("宋体", 18F);
this.label5.ForeColor = System.Drawing.SystemColors.ControlLightLight;
this.label5.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.label5.Location = new System.Drawing.Point(408, 216);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(64, 32);
this.label5.TabIndex = 4;
this.label5.Text = "白方";
//
// label6
//
this.label6.Font = new System.Drawing.Font("宋体", 12F);
this.label6.ForeColor = System.Drawing.SystemColors.ControlLightLight;
this.label6.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.label6.Location = new System.Drawing.Point(408, 272);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(72, 24);
this.label6.TabIndex = 3;
this.label6.Text = "白棋数:";
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1,
this.menuItem4});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem2,
this.menuItem3,
this.menuItem6});
this.menuItem1.Text = "菜单";
//
// menuItem2
//
this.menuItem2.Index = 0;
this.menuItem2.Text = "重新开始";
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
//
// menuItem3
//
this.menuItem3.Index = 1;
this.menuItem3.Text = "重新计分";
this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
//
// menuItem6
//
this.menuItem6.Index = 2;
this.menuItem6.Text = "退出";
this.menuItem6.Click += new System.EventHandler(this.menuItem6_Click);
//
// menuItem4
//
this.menuItem4.Index = 1;
this.menuItem4.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem5});
this.menuItem4.Text = "关于";
//
// menuItem5
//
this.menuItem5.Index = 0;
this.menuItem5.Text = "游戏说明";
this.menuItem5.Click += new System.EventHandler(this.menuItem5_Click);
//
// label3
//
this.label3.Font = new System.Drawing.Font("宋体", 12F);
this.label3.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.label3.Location = new System.Drawing.Point(448, 368);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(16, 24);
this.label3.TabIndex = 6;
this.label3.Text = ":";
//
// l3
//
this.l3.Font = new System.Drawing.Font("宋体", 12F);
this.l3.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.l3.Location = new System.Drawing.Point(408, 368);
this.l3.Name = "l3";
this.l3.Size = new System.Drawing.Size(32, 24);
this.l3.TabIndex = 7;
this.l3.Text = "0";
//
// l4
//
this.l4.Font = new System.Drawing.Font("宋体", 12F);
this.l4.ForeColor = System.Drawing.SystemColors.ControlLightLight;
this.l4.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.l4.Location = new System.Drawing.Point(480, 368);
this.l4.Name = "l4";
this.l4.Size = new System.Drawing.Size(32, 24);
this.l4.TabIndex = 8;
this.l4.Text = "0";
//
// label4
//
this.label4.Font = new System.Drawing.Font("宋体", 12F);
this.label4.ForeColor = System.Drawing.SystemColors.Desktop;
this.label4.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.label4.Location = new System.Drawing.Point(408, 320);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(72, 32);
this.label4.TabIndex = 9;
this.label4.Text = "分数";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.Color.BurlyWood;
this.ClientSize = new System.Drawing.Size(536, 438);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.l4);
this.Controls.Add(this.l3);
this.Controls.Add(this.l2);
this.Controls.Add(this.label5);
this.Controls.Add(this.label6);
this.Controls.Add(this.l1);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.MaximizeBox = false;
this.MaximumSize = new System.Drawing.Size(544, 472);
this.Menu = this.mainMenu1;
this.MinimumSize = new System.Drawing.Size(544, 472);
this.Name = "Form1";
this.Text = "黑白棋";
this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseUp);
this.MouseEnter += new System.EventHandler(this.Form1_MouseEnter);
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

//鼠标移入窗体发生的事件
private void Form1_MouseEnter(object sender, System.EventArgs e)
{
h_qipan();
qizi();
}

//鼠标操作 下棋子
private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(e.X<=40||e.X>=390||e.Y<=40||e.Y>=390)
return;

x=(e.X-e.X%30)/30-1;
y=(e.Y-e.Y%30)/30-1;
if(xy[x,y]==0)
{
if(b==true)
x_qizi(1);
else
x_qizi(-1);

}
qizi_s();
qizi();
s_y();
}

//重新开始 初始化棋盘
private void menuItem2_Click(object sender, System.EventArgs e)
{
ch_qipan();
}

//重新计分
private void menuItem3_Click(object sender, System.EventArgs e)
{
l3.Text="0";
l4.Text="0";
black=0;
white=0;
}

private void menuItem5_Click(object sender, System.EventArgs e)
{
MessageBox.Show("\n 游戏很简单,如果不按照规则是下不了棋的。\n\n游戏规则:\n在你要下棋子的地方必须满足上下左右8个方向至少有一粒自己的棋子,\n而且中间不能有 空位,若中间是对方棋子就会被吃掉(边成你的棋子)。\n\n 制作 不锈钢","说明");
}


private void menuItem6_Click(object sender, System.EventArgs e)
{
Application.Exit();
}

}
}


2006-03-26 15:42
htzz
Rank: 1
等 级:新手上路
帖 子:89
专家分:0
注 册:2006-3-10
收藏
得分:0 
这个漏洞我也知道
只是棋盘那么大生的机率很少。
等我有空再改改。
游戏已经发去了。


2006-03-27 17:40
htzz
Rank: 1
等 级:新手上路
帖 子:89
专家分:0
注 册:2006-3-10
收藏
得分:0 

游戏有更新
请大家多多支持!!!


2006-04-23 17:09
快速回复:[原创]我写的游戏 黑白棋 [可与机器对战]4.23 以更新
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019829 second(s), 11 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved