using Chess; using System; using System.Collections.Generic; using System.Drawing; using System.Windows; namespace ChessPanel { public class Knight : Piece { public Knight(PieceColor color, Vector position, Grid fields) : base(position, fields) { type = (PieceType)Enum.Parse(typeof(PieceType), this.GetType().Name); this.color = color; this.image = (Image)ChessPanel.Properties.Resources.ResourceManager.GetObject($"{this.type.ToString()}{this.color.ToString()}"); } internal override bool EndageresFieldWithVirtualMove(Grid fields, Field field, Piece movePiece, Field targetPos) { for (int a = -1; a < 2; a += 2) { for (int b = -2; b < 3; b += 4) { if (!(a + (int)field.location.X > 7 || b + (int)field.location.Y < 0 || a + (int)field.location.X < 0 || b + (int)field.location.Y > 7)) { if ((fields[field.location,a,b].IsEmpty && fields[field.location, a, b] != targetPos) || fields[field.location, a, b] == movePiece.field) { if (fields[field.location, a, b] == field) return true; continue; } else { if (fields[field.location, a, b].CurrentPiece?.color != color) if (fields[field.location, a, b] == field) return true; break; } } if (!(b + (int)field.location.X > 7 || a + (int)field.location.Y < 0 || b + (int)field.location.X < 0 || a + (int)field.location.Y > 7)) { if ((fields[field.location, b, a].IsEmpty && fields[field.location, b, a] != targetPos) || fields[field.location, b, a] == movePiece.field) { if (fields[field.location, b, a] == field) return true; continue; } else { if (fields[field.location, b, a].CurrentPiece?.color != color) if (fields[field.location, b, a] == field) return true; break; } } } } return false; } internal override Dictionary GetTargetFields(Grid fields, Field field, PieceColor color) { Dictionary targetFields = new Dictionary(); for (int a = -1; a < 2; a += 2) { for (int b = -2; b < 3; b += 4) { if (!(a + (int)field.location.X > 7 || b + (int)field.location.Y < 0 || a + (int)field.location.X < 0 || b + (int)field.location.Y > 7)) { if (fields[field.location,a,b].IsEmpty) { targetFields.Add(fields[field.location, a, b], PieceTeam.Ally); } else { if (fields[field.location, a, b].CurrentPiece?.color != color) targetFields.Add(fields[field.location, a, b], PieceTeam.Enemy); } } if (!(b + (int)field.location.X > 7 || a + (int)field.location.Y < 0 || b + (int)field.location.X < 0 || a + (int)field.location.Y > 7)) { if (fields[field.location, b, a].IsEmpty) { targetFields.Add(fields[field.location, b, a], PieceTeam.Ally); } else { if (fields[field.location, b, a].CurrentPiece?.color != color) targetFields.Add(fields[field.location, b, a], PieceTeam.Enemy); } } } } return targetFields; } } // FINALIZED }