基本上我的问题是我的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;
}
}