划拳机器人编译出错,什么原因?

liumang9527 2008-05-01 11:34:01
有人没?

不懂C#,没编译过,鄙视自己
请教下,用的是VC2003.NET,代码都是照着拷贝下来的

----------------------------------------------
public class Drunkery <T1, T2> //108行
where T1 : Drunkard, new() //109
where T2 : Drunkard, new() //110
和 new Drunkery <Zswang一号, Zswang二号>().Play(); //416

这两地方提示错误
D:\WorkSpace\HuaquanRot\CodeFileHQ.cs(108): 类、结构或接口成员声明中的标记“,”无效
D:\WorkSpace\HuaquanRot\CodeFileHQ.cs(109): 类、结构或接口成员声明中的标记“,”无效
D:\WorkSpace\HuaquanRot\CodeFileHQ.cs(110): 类、结构或接口成员声明中的标记“,”无效
D:\WorkSpace\HuaquanRot\CodeFileHQ.cs(108): 类、结构或接口成员声明中的标记“>”无效
D:\WorkSpace\HuaquanRot\CodeFileHQ.cs(416): 无效的表达式项“)”
D:\WorkSpace\HuaquanRot\CodeFileHQ.cs(416): 无效的表达式项“,”
D:\WorkSpace\HuaquanRot\CodeFileHQ.cs(416): 新的表达式要求在类型后有 () 或 []
D:\WorkSpace\HuaquanRot\CodeFileHQ.cs(416): 应输入 )
D:\WorkSpace\HuaquanRot\CodeFileHQ.cs(110): 应输入 ;
D:\WorkSpace\HuaquanRot\CodeFileHQ.cs(416): 应输入 ;
D:\WorkSpace\HuaquanRot\CodeFileHQ.cs(109): 应输入 ;
D:\WorkSpace\HuaquanRot\CodeFileHQ.cs(416): 应输入 ;
D:\WorkSpace\HuaquanRot\CodeFileHQ.cs(108): 应输入 {
D:\WorkSpace\HuaquanRot\CodeFileHQ.cs(109): 应输入类型
D:\WorkSpace\HuaquanRot\CodeFileHQ.cs(110): 应输入类型

怎么解决



...全文
73 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
liumang9527 2008-05-02
  • 打赏
  • 举报
回复

using System;
using System.Collections.Generic;
using System.Text;

namespace Huaquan
{

/// <summary>
/// 酒鬼类
/// </summary>
public abstract class Drunkard
{
abstract public void Come(out int AFinger, out int ASum);

abstract public void Outcome(int AOtherFinger, int AOtherSum, Result AOtherResult,
int ASelfFinger, int ASelfSum, Result ASelfResult);
}

public class Zswang一号 : Drunkard
{
public override void Come(out int AFinger, out int ASum)
{
AFinger = 5; // 每次都出5
ASum = 10; // 每次都猜10
}

public override void Outcome(int AOtherFinger, int AOtherSum, Result AOtherResult,
int ASelfFinger, int ASelfSum, Result ASelfResult)
{
/* 这机器人不关心比赛结果 */
}
}

public class Zswang二号 : Drunkard
{
private Random random;
public Zswang二号()
{
random = new Random();
}

public override void Come(out int AFinger, out int ASum)
{
ASum = random.Next(10 + 1); //0-10
if (ASum < 5) // 别犯规
AFinger = random.Next(ASum + 1);
else AFinger = random.Next(ASum - 5, 5 + 1);
}

public override void Outcome(int AOtherFinger, int AOtherSum, Result AOtherResult,
int ASelfFinger, int ASelfSum, Result ASelfResult)
{
/* 这机器人也不关心比赛结果 */
}
}

/// <summary>
/// 酒馆类
/// </summary>
/// <typeparam name="T1">划拳机器人1</typeparam>
/// <typeparam name="T2">划拳机器人2</typeparam>
public class Drunkery<T1, T2>
where T1 : Drunkard, new()
where T2 : Drunkard, new()
{
public void Play()
{
;
}
}

class Program
{
static void Main(string[] args)
{
new Drunkery<Zswang一号, Zswang二号>().Play();
}
}
}
liumang9527 2008-05-02
  • 打赏
  • 举报
回复
这怎么看,晕了源代码呢

下面

---------------------------


using System;
using System.Collections.Generic;
using System.Text;

namespace Huaquan
{

/// <summary>
/// 酒鬼类
/// </summary>
public abstract class Drunkard
{
abstract public void Come(out int AFinger, out int ASum);

abstract public void Outcome(int AOtherFinger, int AOtherSum, Result AOtherResult,
int ASelfFinger, int ASelfSum, Result ASelfResult);
}

public class Zswang一号 : Drunkard
{
public override void Come(out int AFinger, out int ASum)
{
AFinger = 5; // 每次都出5
ASum = 10; // 每次都猜10
}

public override void Outcome(int AOtherFinger, int AOtherSum, Result AOtherResult,
int ASelfFinger, int ASelfSum, Result ASelfResult)
{
/* 这机器人不关心比赛结果 */
}
}

public class Zswang二号 : Drunkard
{
private Random random;
public Zswang二号()
{
random = new Random();
}

public override void Come(out int AFinger, out int ASum)
{
ASum = random.Next(10 + 1); //0-10
if (ASum < 5) // 别犯规
AFinger = random.Next(ASum + 1);
else AFinger = random.Next(ASum - 5, 5 + 1);
}

public override void Outcome(int AOtherFinger, int AOtherSum, Result AOtherResult,
int ASelfFinger, int ASelfSum, Result ASelfResult)
{
/* 这机器人也不关心比赛结果 */
}
}

/// <summary>
/// 酒馆类
/// </summary>
/// <typeparam name="T1">划拳机器人1</typeparam>
/// <typeparam name="T2">划拳机器人2</typeparam>
public class Drunkery<T1, T2>
where T1 : Drunkard, new()
where T2 : Drunkard, new()
{
public void Play()
{
;
}
}

class Program
{
static void Main(string[] args)
{
new Drunkery<Zswang一号, Zswang二号>().Play();
}
}
}
liumang9527 2008-05-01
  • 打赏
  • 举报
回复
这怎么看,晕了源代码呢
--------------------------------

public class Drunkery<T1, T2>
where T1 : Drunkard, new()
where T2 : Drunkard, new()
{
/// <summary>
/// 东家
/// </summary>
private Drunkard eastPlayer;
/// <summary>
/// 西家
/// </summary>
private Drunkard westPlayer;
/// <summary>
/// 东家积分
/// </summary>
private int eastTotal;
/// <summary>
/// 西家积分
/// </summary>
private int westTotal;
/// <summary>
/// 东家超时次数
/// </summary>
private int eastOvertime;
/// <summary>
/// 西家超时次数
/// </summary>
private int westOvertime;
/// <summary>
/// 划拳次数
/// </summary>
public const int comeCount = 1000;
/// <summary>
/// 超时罚分
/// </summary>
public const int overtimePenalty = 1;
/// <summary>
/// 异常罚分
/// </summary>
public const int catchPenalty = 100;
/// <summary>
/// 开始比赛
/// </summary>
public void Play()
{
#region 初始化
long vEastTick = Environment.TickCount; // 东家初始化的时间
eastPlayer = new T1();
vEastTick = Environment.TickCount - vEastTick;

long vWestTick = Environment.TickCount; // 西家初始化的时间
westPlayer = new T2();
vWestTick = Environment.TickCount - vWestTick;

eastTotal = 0; westTotal = 0; eastOvertime = 0; westOvertime = 0;

#region 超时处理
if (vEastTick > 1000 || vWestTick > 1000)
{
if (vEastTick > 1000)
Console.WriteLine("{0}初始化严重超时", typeof(T1).Name);
if (vWestTick > 1000)
Console.WriteLine("{0}初始化严重超时", typeof(T2).Name);
return;
}
if (vEastTick > 100)
{
eastTotal -= overtimePenalty;
eastOvertime++;
}
if (vWestTick > 100)
{
westTotal -= overtimePenalty;
westOvertime++;
}
#endregion 超时处理
#endregion 初始化

#region 猜拳过程
for (int i = 0; i < comeCount; i++)
{
for (int j = 0; j < 100; j++)
{
int vEastFinger = 0, vWestFinger = 0;
int vEastSum = 0, vWestSum = 0;
Result vEastResult = Result.Unknown;
Result vWestResult = Result.Unknown;

#region 出拳
bool vEastCatch = false;
vEastTick = Environment.TickCount; // 东家出拳的时间
try
{
eastPlayer.Come(out vEastFinger, out vEastSum);
}
catch // 出现异常
{
vEastCatch = true;
}
vEastTick = Environment.TickCount - vEastTick;

bool vWestCatch = false;
vWestTick = Environment.TickCount; // 西家出拳的时间
try
{
westPlayer.Come(out vWestFinger, out vWestSum);
}
catch // 出现异常
{
vWestCatch = true;
}
vWestTick = Environment.TickCount - vWestTick;
#endregion 出拳

#region 出现异常
if (vEastCatch || vWestCatch)
{
if (vEastCatch)
{
eastTotal -= catchPenalty;
westTotal++;
}
if (vWestCatch)
{
westTotal -= catchPenalty;
eastTotal++;
}
break;
}
#endregion 出现异常

#region 超时处理
if (vEastTick > 1000 || vWestTick > 1000)
{
if (vEastTick > 1000)
Console.WriteLine("{0}出拳严重超时", typeof(T1).Name);
if (vWestTick > 1000)
Console.WriteLine("{0}出拳严重超时", typeof(T2).Name);
return;
}

if (vEastTick > 100)
{
vEastResult = Result.Overtime;
eastOvertime++;
}
if (vWestTick > 100)
{
vWestResult = Result.Overtime;
westOvertime++;
}
#endregion 超时处理

#region 判断谁犯规
if (vEastResult == Result.Unknown)
if (vEastSum < 0 || vEastSum > 10 ||
vEastFinger < 0 || vEastFinger > 5 ||
vEastSum - 5 > vEastFinger || vEastFinger > vEastSum)
vEastResult = Result.Foul;
if (vWestResult == Result.Unknown)
if (vWestSum < 0 || vWestSum > 10 ||
vWestFinger < 0 || vWestFinger > 5 ||
vWestSum - 5 > vWestFinger || vWestFinger > vWestSum)
vWestResult = Result.Foul;
#endregion 判断谁犯规

#region 有一个人犯规
if (vEastResult == Result.Foul ^ vWestResult == Result.Foul)
{
#region 如犯规判则对方赢
if (vEastResult == Result.Foul)
vWestResult = Result.Win;
else if (vWestResult == Result.Foul)
vEastResult = Result.Win;
#endregion 如犯规判则对方赢
}
#endregion 有一个人犯规

#region 划拳比较
if (vEastResult == Result.Unknown)
if (vEastFinger + vWestFinger == vEastSum)
vEastResult = Result.Win;

if (vWestResult == Result.Unknown)
if (vEastFinger + vWestFinger == vWestSum)
vWestResult = Result.Win;
#endregion 划拳比较

#region 平局
if (vEastResult == vWestResult)
{
vEastResult = Result.Dogfall;
vWestResult = Result.Dogfall;
}
#endregion 平局

#region 出现胜负
if (vEastResult == Result.Win || vWestResult == Result.Win)
{
if (vEastResult == Result.Win)
{
eastTotal++;
vWestResult = Result.Lost;
}
else if (vWestResult == Result.Win)
{
westTotal++;
vEastResult = Result.Lost;
}
}
#endregion 出现胜负

#region 通知划拳的结果
vEastTick = Environment.TickCount;
vEastCatch = false;
try
{
eastPlayer.Outcome(vWestFinger, vWestSum, vWestResult,
vEastFinger, vEastSum, vEastResult);
}
catch
{
vEastCatch = true;
}
vEastTick = Environment.TickCount - vEastTick;

vWestTick = Environment.TickCount;
vWestCatch = false;
try
{
westPlayer.Outcome(vEastFinger, vEastSum, vEastResult,
vWestFinger, vWestSum, vWestResult);
}
catch
{
vWestCatch = true;
}
vWestTick = Environment.TickCount - vWestTick;
#endregion 通知划拳的结果

#region 出现异常
if (vEastCatch || vWestCatch)
{
if (vEastCatch)
{
eastTotal -= catchPenalty;
westTotal++;
}
if (vWestCatch)
{
westTotal -= catchPenalty;
eastTotal++;
}
break;
}
#endregion 出现异常

#region 超时处理
if (vEastTick > 1000 || vWestTick > 1000)
{
if (vEastTick > 1000)
Console.WriteLine("{0}接收结果严重超时", typeof(T1).Name);
if (vWestTick > 1000)
Console.WriteLine("{0}接收结果严重超时", typeof(T2).Name);
return;
}

if (vEastTick > 100)
{
eastTotal -= overtimePenalty;
eastOvertime++;
}
if (vWestTick > 100)
{
westTotal -= overtimePenalty;
westOvertime++;
}
if (eastOvertime > 10 || westOvertime > 10)
{
if (eastOvertime > 10)
Console.WriteLine("{0}超时十次以上", typeof(T1).Name);
if (westOvertime > 10)
Console.WriteLine("{0}超时十次以上", typeof(T2).Name);
return;
}
#endregion 超时处理

#region 出现胜负
if (vEastResult == Result.Win || vWestResult == Result.Win)
break;
#endregion 出现胜负
}
}
#endregion 猜拳过程

#region 输出结果
Console.WriteLine("{0}得分:{1}, {2}得分:{3}",
typeof(T1).Name, eastTotal,
typeof(T2).Name, westTotal);
Console.ReadLine();
#endregion 输出结果
}
}

class Program
{
static void Main(string[] args)
{
new Drunkery<Zswang一号, Zswang二号>().Play();
}
}
Kevin_LiuFeng 2008-05-01
  • 打赏
  • 举报
回复
这怎么看,晕了源代码呢

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧