public AlphaBetaReturnValue(int value, MoveResult m, int maxDepth) { Value = value; Move = m; Depth = maxDepth; }
// moves a piece given a MoveResult and color public TurnResult MovePiece(MoveResult move, PieceColor color) { var piece = Pieces.GetPieceForColorAtLocation(move.OriginalPieceLocation, color); Debug.Assert(piece != null); piece.X = move.FinalPieceLocation.X; piece.Y = move.FinalPieceLocation.Y; if (move.Type == MoveType.Jump) { for (var i = 0; i < move.JumpResults.Count; i++) { //kills any jumped pieces var jumpResult = move.JumpResults[i]; var killedPiece = Pieces.GetPieceForColorAtLocation(jumpResult.JumpedLocation, color == PieceColor.Black ? PieceColor.Red : PieceColor.Black); Pieces.KillPiece(killedPiece, _internalTurnBookKeeping); } } _internalTurnBookKeeping++; return TurnResult.Finished; }
// reverts a given move and returns to the state that it was before that move public void RevertMove(MoveResult move, PieceColor color) { if(move.Type == MoveType.Jump) { for (var i = 0; i < move.JumpResults.Count; i++) { var jumpResult = move.JumpResults[i]; var resPiece = Pieces.GetCapturedPieceForColorAtLocation(jumpResult.JumpedLocation, color == PieceColor.Black ? PieceColor.Red : PieceColor.Black); Pieces.RevivePiece(resPiece); } } var piece = Pieces.GetPieceAtPosition(move.FinalPieceLocation); piece.X = move.OriginalPieceLocation.X; piece.Y = move.OriginalPieceLocation.Y; _internalTurnBookKeeping--; }
// returns the possible moves for a given piece, if jumpsOnly is set, then only jumps will be considered public List<MoveResult> GetAvailableMovesForPiece(CheckersPiece piece, bool jumpsOnly) { var moveResults = new List<MoveResult>(); var jumpsAvailable = GetAvailableJumps(piece.X, piece.Y, piece.Color); if (jumpsAvailable.Count > 0 || jumpsOnly) { for (var i = 0; i < jumpsAvailable.Count; i++) { var jump = jumpsAvailable[i]; var mr = new MoveResult(MoveType.Jump, piece, jump.FinalLocation.X, jump.FinalLocation.Y) {JumpResults = jump.LocationsJumped}; moveResults.Add(mr); } return moveResults; //user must make a jummp } //possible forward moves must be considered too var possibleEndValues = new List<Location> { new Location(piece.X - 1, piece.Y + (int)piece.Forward), new Location(piece.X + 1, piece.Y + (int)piece.Forward) }; for (var i = possibleEndValues.Count - 1; i >= 0; i--) { var p = possibleEndValues[i]; //remove invalid final locations (piece is there or the location is invalid) if (!TileBoard.IsValidLocation(p) || Pieces.GetPieceAtPosition(p) != null) possibleEndValues.RemoveAt(i); } for (var i = 0; i < possibleEndValues.Count; i++) { var possibleEndValue = possibleEndValues[i]; moveResults.Add(new MoveResult(MoveType.Forward, piece, possibleEndValue.X, possibleEndValue.Y)); } return moveResults; }