List<ILocation> BishopMoves(IPiece piece) { List<ILocation> list = new List<ILocation>(); ILocation target; // move se for (int x = piece.X + 1, y = piece.Y + 1; x <= Board._MAX_BOUNDS && y <= Board._MAX_BOUNDS; x++, y++) { target = new Location(x, y); if (ColorCollision(piece.Color, target)) break; else if (Collision(target)) { list.Add(target); break; } else list.Add(target); } // move sw for (int x = piece.X - 1, y = piece.Y + 1; x >= Board._MIN_BOUNDS && y <= Board._MAX_BOUNDS; x--, y++) { target = new Location(x, y); if (ColorCollision(piece.Color, target)) break; else if (Collision(target)) { list.Add(target); break; } else list.Add(target); } // move ne for (int x = piece.X + 1, y = piece.Y - 1; x <= Board._MAX_BOUNDS && y >= Board._MIN_BOUNDS; x++, y--) { target = new Location(x, y); if (ColorCollision(piece.Color, target)) break; else if (Collision(target)) { list.Add(target); break; } else list.Add(target); } // move nw for (int x = piece.X - 1, y = piece.Y - 1; x >= Board._MIN_BOUNDS && y >= Board._MIN_BOUNDS; x--, y--) { target = new Location(x, y); if (ColorCollision(piece.Color, target)) break; else if (Collision(target)) { list.Add(target); break; } else list.Add(target); } return list; }
List<ILocation> RookMoves(IPiece piece) { List<ILocation> list = new List<ILocation>(); ILocation target; // move right for(int x = piece.X + 1; x <= 8; x++) { target = new Location(x, piece.Y); if (ColorCollision(piece.Color, target)) break; else if (Collision(target)) { list.Add(target); break; } else list.Add(target); } // move left for (int x = piece.X - 1; x > 0; x--) { target = new Location(x, piece.Y); if (ColorCollision(piece.Color, target)) break; else if (Collision(target)) { list.Add(target); break; } else list.Add(target); } // move up for (int y = piece.Y - 1; y > 0; y--) { target = new Location(piece.X, y); if (ColorCollision(piece.Color, target)) break; else if (Collision(target)) { list.Add(target); break; } else list.Add(target); } // move down for (int y = piece.Y + 1; y <= 8; y++) { target = new Location(piece.X, y); if (ColorCollision(piece.Color, target)) break; else if (Collision(target)) { list.Add(target); break; } else list.Add(target); } return list; }
List<ILocation> KnightMoves(IPiece piece) { List<ILocation> list = new List<ILocation>(); ILocation target; // move right target = new Location(piece.X + 2, piece.Y + 1); if (Board.IsInBounds(target)) if (!ColorCollision(piece.Color, target)) list.Add(target); target = new Location(piece.X + 2, piece.Y - 1); if (Board.IsInBounds(target)) if (!ColorCollision(piece.Color, target)) list.Add(target); // move left target = new Location(piece.X - 2, piece.Y + 1); if (Board.IsInBounds(target)) if (!ColorCollision(piece.Color, target)) list.Add(target); target = new Location(piece.X - 2, piece.Y - 1); if (Board.IsInBounds(target)) if (!ColorCollision(piece.Color, target)) list.Add(target); // move up target = new Location(piece.X + 1, piece.Y - 2); if (Board.IsInBounds(target)) if (!ColorCollision(piece.Color, target)) list.Add(target); target = new Location(piece.X - 1, piece.Y - 2); if (Board.IsInBounds(target)) if (!ColorCollision(piece.Color, target)) list.Add(target); // move down target = new Location(piece.X + 1, piece.Y + 2); if (Board.IsInBounds(target)) if (!ColorCollision(piece.Color, target)) list.Add(target); target = new Location(piece.X - 1, piece.Y + 2); if (Board.IsInBounds(target)) if (!ColorCollision(piece.Color, target)) list.Add(target); return list; }
List<ILocation> PawnMoves(IPiece piece) { List<ILocation> list = new List<ILocation>(); int direction = 1; if (piece.Color == Color.white) direction = -1; ILocation target; if ((piece.Y == 2 && piece.Color == Color.black) | (piece.Y == 7 && piece.Color == Color.white)) { target = new Location(piece.X, piece.Y + 2 * direction); if (!CollisionFromTo(piece.Location, target) && !Collision(target)) list.Add(target); } // straight forward target = new Location(piece.X, piece.Y + 1 * direction); if (Board.IsInBounds(target)) if (!Collision(target)) { list.Add(target); } // move forward east target = new Location(piece.X + 1, piece.Y + 1 * direction); if (Board.IsInBounds(target)) if (!ColorCollision(piece.Color, target) && Collision(target)) { list.Add(target); } // move foward west target = new Location(piece.X - 1, piece.Y + 1 * direction); if (Board.IsInBounds(target)) if (!ColorCollision(piece.Color, target) && Collision(target)) { list.Add(target); } return list; }
List<ILocation> KingMoves(IPiece piece) { List<ILocation> list = new List<ILocation>(); ILocation target; // move up if(piece.Y != Board._MIN_BOUNDS) { target = new Location(piece.X, piece.Y - 1); if (!ColorCollision(piece.Color, target)) list.Add(target); if(piece.X != Board._MIN_BOUNDS) { target = new Location(piece.X - 1, piece.Y - 1); if (!ColorCollision(piece.Color, target)) list.Add(target); } if(piece.X != Board._MAX_BOUNDS) { target = new Location(piece.X + 1, piece.Y - 1); if (!ColorCollision(piece.Color, target)) list.Add(target); } } // move down if (piece.Y != Board._MAX_BOUNDS) { target = new Location(piece.X, piece.Y + 1); if (!ColorCollision(piece.Color, target)) list.Add(target); if (piece.X != Board._MIN_BOUNDS) { target = new Location(piece.X - 1, piece.Y + 1); if (!ColorCollision(piece.Color, target)) list.Add(target); } if (piece.X != Board._MAX_BOUNDS) { target = new Location(piece.X + 1, piece.Y + 1); if (!ColorCollision(piece.Color, target)) list.Add(target); } } // move right if (piece.X != Board._MAX_BOUNDS) { target = new Location(piece.X + 1, piece.Y); if (!ColorCollision(piece.Color, target)) list.Add(target); } // move left if (piece.X != Board._MIN_BOUNDS) { target = new Location(piece.X - 1, piece.Y); if (!ColorCollision(piece.Color, target)) list.Add(target); } return list; }