public override void AdjustMovement(PieceType pieceType) { MoveCapability[] moves; int nMoves = pieceType.GetMoveCapabilities(out moves); for (int x = 0; x < nMoves; x++) { moves[x].CanCapture = false; } }
public static bool CustomMoveGenerationHandler(PieceType pieceType, Piece piece, MoveList moveList, bool capturesOnly) { MoveCapability[] moves; int nMoves = pieceType.GetMoveCapabilities(out moves); for (int nMove = 0; nMove < nMoves; nMove++) { MoveCapability move = moves[nMove]; int step = 1; int nextSquare = piece.Board.NextSquare(piece.Player, move.NDirection, piece.Square); while (nextSquare >= 0 && step <= move.MaxSteps) { Piece pieceOnSquare = piece.Board[nextSquare]; if (pieceOnSquare != null) { if (step >= move.MinSteps && move.CanCapture && pieceOnSquare.Player != piece.Player) { moveList.AddCapture(piece.Square, nextSquare); } else if (step >= move.MinSteps && pieceOnSquare.Player == piece.Player && piece.PieceType != pieceOnSquare.PieceType) { // self-capture move allowing relocation of friendly piece int currentSquare = piece.Square; while (currentSquare != nextSquare) { moveList.BeginMoveAdd(MoveType.MoveRelay, piece.Square, nextSquare, currentSquare); moveList.AddPickup(piece.Square); moveList.AddPickup(nextSquare); moveList.AddDrop(piece, nextSquare); moveList.AddDrop(pieceOnSquare, currentSquare); moveList.EndMoveAdd(piece.PieceType.GetMidgamePST(nextSquare) - piece.PieceType.GetMidgamePST(piece.Square) + pieceOnSquare.PieceType.GetMidgamePST(currentSquare) - pieceOnSquare.PieceType.GetMidgamePST(nextSquare)); currentSquare = piece.Board.NextSquare(piece.Player, move.NDirection, currentSquare); } } nextSquare = -1; } else { if (step >= move.MinSteps && !move.MustCapture && !capturesOnly) { moveList.AddMove(piece.Square, nextSquare); } nextSquare = piece.Board.NextSquare(piece.Player, move.NDirection, nextSquare); step++; } } } return(false); }
public override void AddPieceTypes() { base.AddPieceTypes(); AddChessPieceTypes(); AddPieceType(Jester = new FreePadwar("Jester", "J", 400, 400, "ElephantFerz2")); AddPieceType(Chancellor = new Amazon("Chancellor", "C", 700, 700, "Duke")); // limit the range of the slides to two spaces MoveCapability[] moves; int nMoves = Chancellor.GetMoveCapabilities(out moves); for (int x = 0; x < nMoves; x++) { if (moves[x].MaxSteps > 1) { moves[x].MaxSteps = 2; } } }
private void MovementDiagramControl_Paint(object sender, PaintEventArgs e) { // Create our graphics objects Pen blackOutlinePen = new Pen(Color.Black, 2); Pen redOutlinePen = new Pen(Color.Red, 2); Pen thickRedPen = new Pen(Color.Red, 5); Pen thickGreenPen = new Pen(Color.FromArgb(0, 255, 0), 5); SolidBrush lightSquareBrush = new SolidBrush(Theme == null ? Color.FromArgb(0xFF, 0xFF, 0xCC) : Theme.ColorScheme.SquareColors[0]); SolidBrush darkSquareBrush = new SolidBrush(Theme == null ? Color.FromArgb(0x5D, 0x7E, 0x7E) : Theme.ColorScheme.SquareColors[1]); SolidBrush thirdSquareBrush = (Theme != null && Theme.ColorScheme.SquareColors.Count > 2) ? new SolidBrush(Theme.ColorScheme.SquareColors[2]) : darkSquareBrush; SolidBrush redBrush = new SolidBrush(Color.FromArgb(255, 0, 0)); SolidBrush greenBrush = new SolidBrush(Color.FromArgb(0, 255, 0)); SolidBrush blackBrush = new SolidBrush(Color.Black); // Draw the board for (int file = 0; file < 9; file++) { for (int rank = 0; rank < 9; rank++) { SolidBrush squareBrush = lightSquareBrush; if (Theme == null || Theme.NSquareColors == 2) { squareBrush = (file + rank) % 2 == 1 ? lightSquareBrush : darkSquareBrush; } else if (Theme != null && Theme.NSquareColors == 3) { squareBrush = (file + rank) % 2 == 1 ? lightSquareBrush : (rank % 2 == 0 ? darkSquareBrush : thirdSquareBrush); } e.Graphics.FillRectangle(squareBrush, 50 + 36 * file, 50 + 36 * rank, 36, 36); } } for (int file = 0; file < 9; file++) { for (int rank = 0; rank < 9; rank++) { e.Graphics.DrawRectangle(blackOutlinePen, 50 + 36 * file, 50 + 36 * rank, 36, 36); } } if (Theme == null) { // we are just previewing this control in the Forms Designer // so we have nothing further to present return; } // Draw miniature piece BoardPresentation.PieceSetPresentation.Render(e.Graphics, new Rectangle(50 + 36 * 4, 50 + 36 * 4, 36, 36), Piece, true); // Draw movement capabilities, first pass ... MoveCapability[] moves; int nMoves = PieceType.GetMoveCapabilities(out moves); for (int z = 0; z < nMoves; z++) { MoveCapability move = moves[z]; Direction direction = Piece.Game.GetDirection(Piece.Game.PlayerDirection(Piece.Player, move.NDirection)); int steps = 1; int rank = 4; int file = 4; int newRank; int newFile; newRank = rank - direction.RankOffset; newFile = file + direction.FileOffset; int oldFile = 4; int oldRank = 4; while (newRank >= 0 && newRank < 9 && newFile >= 0 && newFile < 9 && steps <= move.MaxSteps) { // draw indicator for this step if (move.MaxSteps == 1) { // handle displaying "paths" for moves that have paths if (move.PathInfo != null) { MovePathInfo pathinfo = move.PathInfo; foreach (List <Direction> dirlist in pathinfo.PathDirections) { int pathRank = 4; int pathFile = 4; foreach (Direction dir in dirlist) { int newPathRank = pathRank - dir.RankOffset; int newPathFile = pathFile + dir.FileOffset; // draw line int startX = 68 + 36 * pathFile; int startY = 68 + 36 * pathRank; int endX = 68 + 36 * newPathFile; int endY = 68 + 36 * newPathRank; if (pathRank == 4 && pathFile == 4) { FindIntersectionOfLineAndRectangle(startX, startY, endX, endY, 50 + 36 * 4, 50 + 36 * 4, 50 + 36 * 5, 50 + 36 * 5, ref startX, ref startY); } e.Graphics.DrawLine(move.CanCapture ? thickRedPen : thickGreenPen, startX, startY, endX, endY); pathRank = newPathRank; pathFile = newPathFile; } } } // a single step move is displayed // differently from a sliding move Brush fillBr; Pen outlinePen; if (move.CanCapture && !move.MustCapture) { outlinePen = blackOutlinePen; fillBr = redBrush; } else if (!move.CanCapture) { outlinePen = blackOutlinePen; fillBr = greenBrush; } else { outlinePen = redOutlinePen; fillBr = blackBrush; } e.Graphics.FillEllipse(fillBr, 54 + 36 * newFile, 54 + 36 * newRank, 28, 28); e.Graphics.DrawEllipse(outlinePen, 54 + 36 * newFile, 54 + 36 * newRank, 28, 28); if (move.MustCapture) { StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; e.Graphics.DrawString("X", System.Drawing.SystemFonts.CaptionFont, redBrush, new RectangleF(51 + 36 * newFile, 51 + 36 * newRank, 36, 36), format); } } else if (steps >= move.MinSteps) { Brush fillBr; Pen outlinePen; if (move.CanCapture && !move.MustCapture) { outlinePen = blackOutlinePen; fillBr = redBrush; } else if (!move.CanCapture) { outlinePen = blackOutlinePen; fillBr = greenBrush; } else { outlinePen = redOutlinePen; fillBr = blackBrush; } e.Graphics.FillEllipse(fillBr, 54 + 36 * newFile, 54 + 36 * newRank, 28, 28); e.Graphics.DrawEllipse(outlinePen, 54 + 36 * newFile, 54 + 36 * newRank, 28, 28); if (move.MustCapture) { StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; e.Graphics.DrawString("X", System.Drawing.SystemFonts.CaptionFont, redBrush, new RectangleF(51 + 36 * newFile, 51 + 36 * newRank, 36, 36), format); } } // take another step... oldFile = newFile; oldRank = newRank; newRank -= direction.RankOffset; newFile += direction.FileOffset; steps++; } steps--; if (steps > 1) { int nextSquareCenterX; int nextSquareCenterY; int lineEndX = 0; int lineEndY = 0; int maxSteps = move.MaxSteps; if (steps >= move.MaxSteps) { nextSquareCenterX = lineEndX = 68 + (36 * oldFile); nextSquareCenterY = lineEndY = 68 + (36 * oldRank); } else { newRank -= direction.RankOffset; newFile += direction.FileOffset; nextSquareCenterX = 68 + (36 * newFile); nextSquareCenterY = 68 + (36 * newRank); if (move.Direction.FileOffset == move.Direction.RankOffset || move.Direction.FileOffset == -move.Direction.RankOffset) { FindIntersectionOfLineAndRectangle(212, 212, nextSquareCenterX, nextSquareCenterY, 60 - 36, 60 - 36, 75 + (36 * 9), 75 + (36 * 9), ref lineEndX, ref lineEndY); } else if (move.Direction.FileOffset == 0 || move.Direction.RankOffset == 0) { FindIntersectionOfLineAndRectangle(212, 212, nextSquareCenterX, nextSquareCenterY, 43 - 36, 43 - 36, 92 + (36 * 9), 92 + (36 * 9), ref lineEndX, ref lineEndY); } else { FindIntersectionOfLineAndRectangle(212, 212, nextSquareCenterX, nextSquareCenterY, 51 - 36, 51 - 36, 84 + (36 * 9), 84 + (36 * 9), ref lineEndX, ref lineEndY); } } int lineStartX = 0; int lineStartY = 0; FindIntersectionOfLineAndRectangle(212, 212, nextSquareCenterX, nextSquareCenterY, 51 + (36 * 4), 51 + (36 * 4), 84 + (36 * 4), 84 + (36 * 4), ref lineStartX, ref lineStartY); Pen linePen; Brush fillBrush; if (move.CanCapture && !move.MustCapture) { linePen = thickRedPen; fillBrush = redBrush; } else if (!move.CanCapture) { linePen = thickGreenPen; fillBrush = greenBrush; } else { linePen = thickRedPen; fillBrush = redBrush; } e.Graphics.DrawLine(linePen, lineStartX, lineStartY, lineEndX, lineEndY); if (steps < move.MaxSteps) { double angle = 0.0; angle = Math.Atan2((double)(lineEndY - lineStartY), (double)(lineStartX - lineEndX)); Point[] pt = new Point[3]; pt[0].X = lineEndX; pt[0].Y = lineEndY; pt[1].X = (int)((lineEndX + (Math.Cos(angle) * 30)) + (Math.Cos(angle + (Math.PI / 2)) * 10)); pt[1].Y = (int)((lineEndY - (Math.Sin(angle) * 30)) - (Math.Sin(angle + (Math.PI / 2)) * 10)); pt[2].X = (int)((lineEndX + (Math.Cos(angle) * 30)) + (Math.Cos(angle - (Math.PI / 2)) * 10)); pt[2].Y = (int)((lineEndY - (Math.Sin(angle) * 30)) - (Math.Sin(angle - (Math.PI / 2)) * 10)); e.Graphics.FillPolygon(fillBrush, pt); e.Graphics.DrawPolygon(linePen, pt); } } } // second pass ... for (int z = 0; z < nMoves; z++) { MoveCapability move = moves[z]; Direction direction = Piece.Game.GetDirection(Piece.Game.PlayerDirection(Piece.Player, move.NDirection)); int steps = 1; int rank = 4; int file = 4; int newRank = rank - direction.RankOffset; int newFile = file + direction.FileOffset; while (newRank >= 0 && newRank < 9 && newFile >= 0 && newFile < 9 && steps <= move.MaxSteps) { if (move.MaxSteps > 1) { // draw black inner dot e.Graphics.FillEllipse(blackBrush, 63 + 36 * newFile, 63 + 36 * newRank, 11, 11); } if (move.PathInfo != null) { MovePathInfo pathinfo = move.PathInfo; foreach (List <Direction> dirlist in pathinfo.PathDirections) { int pathRank = 4; int pathFile = 4; foreach (Direction dir in dirlist) { pathRank = pathRank - dir.RankOffset; pathFile = pathFile + dir.FileOffset; // draw black inner dot e.Graphics.FillEllipse(blackBrush, 63 + 36 * pathFile, 63 + 36 * pathRank, 11, 11); } } } // take another step... newRank -= direction.RankOffset; newFile += direction.FileOffset; steps++; } } }
public static bool CustomMoveGenerationHandler(PieceType pieceType, Piece piece, MoveList moveList, bool capturesOnly) { MoveCapability[] moves; int nMoves = pieceType.GetMoveCapabilities(out moves); for (int nMove = 0; nMove < nMoves; nMove++) { MoveCapability move = moves[nMove]; int step = 1; int nextSquare = piece.Board.NextSquare(piece.Player, move.NDirection, piece.Square); while (nextSquare >= 0 && step <= move.MaxSteps) { Piece pieceOnSquare = piece.Board[nextSquare]; if (pieceOnSquare != null) { if (step >= move.MinSteps && move.CanCapture && pieceOnSquare.Player != piece.Player) { moveList.AddCapture(piece.Square, nextSquare); for (int x = 0; x < 8; x++) { int targetSquare = piece.Board.NextSquare(x, nextSquare); if (targetSquare >= 0 && piece.Board[targetSquare] != null && piece.Board[targetSquare].Player != piece.Player) { moveList.BeginMoveAdd(MoveType.ExtraCapture, piece.Square, nextSquare, targetSquare); moveList.AddPickup(piece.Square); moveList.AddPickup(nextSquare); moveList.AddPickup(targetSquare); moveList.AddDrop(piece, nextSquare); moveList.EndMoveAdd(4000 + piece.Board[nextSquare].PieceType.MidgameValue + piece.Board[targetSquare].PieceType.MidgameValue); } } } nextSquare = -1; } else { if (step >= move.MinSteps && !move.MustCapture) { if (!capturesOnly) { moveList.AddMove(piece.Square, nextSquare); } for (int x = 0; x < 8; x++) { int targetSquare = piece.Board.NextSquare(x, nextSquare); if (targetSquare >= 0 && piece.Board[targetSquare] != null && piece.Board[targetSquare].Player != piece.Player) { moveList.BeginMoveAdd(MoveType.ExtraCapture, piece.Square, nextSquare, targetSquare); moveList.AddPickup(piece.Square); moveList.AddPickup(targetSquare); moveList.AddDrop(piece, nextSquare); moveList.EndMoveAdd(3000 + piece.Board[targetSquare].PieceType.MidgameValue); } } } nextSquare = piece.Board.NextSquare(piece.Player, move.NDirection, nextSquare); step++; } } } return(false); }