public override int GetHashCode() { unchecked { return((XCoord.GetHashCode() * 397) ^ YCoord.GetHashCode()); } }
public override int GetHashCode() { var hashCode = 269724561; hashCode = hashCode * -1521134295 + XCoord.GetHashCode(); hashCode = hashCode * -1521134295 + YCoord.GetHashCode(); return(hashCode); }
// If Equals() returns true for a pair of objects // then GetHashCode() must return the same value for these objects. public override int GetHashCode() { //Get hash code for the Name field if it is not null. int hashXVal = XCoord.GetHashCode(); int hashYVal = YCoord.GetHashCode(); //Calculate the hash code for the Point return(hashXVal ^ hashYVal); }
public bool Equals(Node other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(XCoord.Equals(other.XCoord) && YCoord.Equals(other.YCoord)); }
/// <summary> /// Creates a string of pawns from point to point /// </summary> /// <param name="owner">The owner of the pawns</param> /// <param name="start">Starting point</param> /// <param name="end">Ending point</param> /// <note>The line must be either horizontal or vertical</note> /// <returns></returns> private IEnumerable <ChessPiece> CreatePawnsAlongLine(PlayerEnum owner, BoardPosition start, BoardPosition end) { //Vertical case if (start.X == end.X) { for (int y = start.Y; y <= end.Y; y++) { yield return(new Pawn(owner, new BoardPosition(start.X, y))); } } else if (start.Y == end.Y) { for (XCoord x = start.X; x <= end.X; x++) { yield return(new Pawn(owner, new BoardPosition(x, start.Y))); } } }
/// <summary> /// Initializes a BoardPosition /// </summary> /// <param name="x">The horizontal index</param> /// <param name="y">The vertical index</param> public BoardPosition(XCoord x, int y) { X = x; Y = y; }
///<summary>Returns a string listing the rovers coordinates and heading /// </summary> public string ReportCoordsAndHeading() { return(XCoord.ToString() + " " + YCoord.ToString() + " " + Enum.GetName(typeof(Heading), this.Heading)); }
[TestCase(XCoord.a, 4, true)] //Player 4 rook 2 public void CheckPositionExists(XCoord x, int y, bool inBounds) { var pos = new BoardPosition(x, y); Assert.AreEqual(ChessBoard.CheckPositionExists(pos), inBounds); }
public static MoveResult Move(XCoord x, int y, MoveType result) => new MoveResult(Pos(x, y), result);
public static BoardPosition Pos(XCoord x, int y) => new BoardPosition(x, y);
public Vec2(XCoord x, YCoord y) { X = x; Y = y; }
protected static BoardPosition Pos(XCoord x, int y) => new BoardPosition(x, y);
public async Task Move(string[] ToXYZ) { dynamic request; var toLocation = Storage.Current.Locations.Find($"{ToXYZ[0]},{ToXYZ[1]},{ToXYZ[2]}"); if (toLocation == null) { toLocation = Location.CreateTempLocation(ToXYZ); var area = toLocation.ConvertToArea(true); request = new { Category = "Events", Type = "AreaCreated", Area = area }; foreach (var player in toLocation.GetNearbyPlayers()) { player.SendString(JSON.Encode(request)); } } // TODO: Check if blocked. var soul = ConvertToSoul(); var currentLocation = GetCurrentLocation(); if (currentLocation == null) { currentLocation = Location.CreateTempLocation(new string[] { XCoord.ToString(), YCoord.ToString(), ZCoord }); var area = currentLocation.ConvertToArea(true); request = new { Category = "Events", Type = "AreaCreated", Area = area }; foreach (var player in currentLocation.GetNearbyPlayers()) { await player.SendString(JSON.Encode(request)); } } MovementState = MovementStates.Moving; var distance = currentLocation.GetDistanceFrom(toLocation); var travelTime = distance * 1000; var nearbyPlayers = currentLocation.GetNearbyPlayers(); foreach (var player in toLocation.GetNearbyPlayers()) { if (!nearbyPlayers.Contains(player)) { nearbyPlayers.Add(player); } } await currentLocation.CharacterLeaves(this); FutureXYZ = toLocation.StorageID; request = JSON.Encode(new { Category = "Events", Type = "PlayerMove", Soul = soul, From = currentLocation.StorageID, To = toLocation.StorageID, TravelTime = travelTime }); foreach (var player in nearbyPlayers) { await player.SendString(request); } await Task.Run(async() => { Thread.Sleep((int)(Math.Round(travelTime))); CurrentXYZ = toLocation.StorageID; FutureXYZ = null; await toLocation.CharacterArrives(this); MovementState = MovementStates.Ready; }); }