【发布时间】:2013-02-28 09:46:13
【问题描述】:
基本上我的问题是我的MinMax 算法并没有真正按预期工作。
我需要将我的数组片段复制到newPieces,这样pieces 就不会在newPieces 被更改时发生变化。
这里是MinMax算法的摘录:
private int MinMax(
int depth, Piece[] pieces, bool blacksTurn,
List<Move> Moves, Game game, int alpha, Move nextMove) {
Piece[] newPieces=new Piece[24];
Moves=Game.possibleMoves(pieces, blacksTurn, false);
if(depth==0||Moves.Count==0) {
return Evaluation(ref pieces);
}
int value;
if(blacksTurn==true) {
foreach(Move i in Moves) {
newPieces=DeepCopy.ObjectExtensions.Copy(pieces);
game.MovePiece(newPieces, blacksTurn, i.Moving, i.Destination, true);
game.DisplayBoard(pieces);
value=minMax(depth-1, newPieces, !blacksTurn, Moves, game, alpha, nextMove);
if(alpha>value) {
alpha=value;
nextMove=i;
}
// ...
这里是 Piece 类。
[StructLayout(LayoutKind.Sequential)]
public class Piece
{
public CellReference Location;
public bool isBlack { get; set; }
public bool isKing { get; set; }
private int Value { get; set; }
public bool taken { get; set; }
public Piece()
{
}
public Piece(int i, bool isBlack, bool isKing, int CellsEast, int CellsNorth, bool taken)
{
this.Value = i;
Location.CellsEast = CellsEast;
Location.CellsNorth = CellsNorth;
this.isBlack = isBlack;
this.isKing = isKing;
this.taken = taken;
}
}
【问题讨论】:
-
Piece 是否足够复杂,足以保证类优于结构?根据这是什么游戏,您还可以选择根本不复制棋盘,而是记录信息,让您在评估后恢复移动。
-
这个问题是关于“更高效的深拷贝”还是关于“更高效的 min-max”?
-
@DJKRAZE OP 专门要求 深拷贝,
MemberwiseClose被记录为执行浅拷贝 -
没错,彼得..我看了看我会删除我的评论
-
@500 我试着把它改成一个结构,一切似乎都坏了,所以我把它改回来了。另外,您建议如何记录所有信息?
标签: c# arrays deep-copy minmax