public void FromDirection_UpMoveDirection_ReturnsUpVector() { var direction = MoveDirections.Up; var resVector = new Vector(0.0, -1.0); Assert.That(DirectionVectors.FromDirection(direction), Is.EqualTo(resVector)); }
public void FromDirection_DownMoveDirection_ReturnsDownVector() { var direction = MoveDirections.Down; var resVector = new Vector(0.0, 1.0); Assert.That(DirectionVectors.FromDirection(direction), Is.EqualTo(resVector)); }
public void FromDirection_RightMoveDirection_ReturnsRightVector() { var direction = MoveDirections.Right; var resVector = new Vector(1.0, 0.0); Assert.That(DirectionVectors.FromDirection(direction), Is.EqualTo(resVector)); }
protected void SetDirectionVectors() { if (Directions == null) { return; } foreach (Direction.Directions direction in Directions) { DirectionVectors.Add(Direction.GetVector(direction)); } }
// Check Direction from Index /// <summary> /// Check Direction from a specified index value /// </summary> /// <param name="index">The index where the tile is placed</param> /// <param name="p">The player making the move</param> /// <param name="opp">The opponent of the player</param> /// <param name="d">The direction to check <see cref="DirectionVectors"/></param> /// <returns></returns> private bool ValidateDirectionFromIndex(int index, Players p, Players opp, DirectionVectors dv, out List <int> result) { result = new List <int>(); Players player = p; Players opponent = (player == Players.Player1) ? Players.Player2 : Players.Player1; // returns -1 if the neighbor is a boundary int tmp_index = Gameboard.GetIndexByOffsets(index, dv); // Is there a valid piece in this square? if ((tmp_index == -1) || (Gameboard.Squares[tmp_index].Piece == null)) { return(false); } // Check if the neighbor is owned by the opponent, if not then its not a valid case Players owner = Gameboard.Squares[tmp_index].Piece.Owner.IdType; if (owner != opponent) { return(false); } // Otherwise continue searching in this direction to see if a // players piece is also in this direction. int nextIndex = tmp_index; Players nextOwner = owner; // Continue searching so long as we don't reach the border (-1) and the next square is // owned by the opponent. while ((nextIndex != -1) && (nextOwner == opponent)) { // Add our element to the list. result.Add(nextIndex); Console.WriteLine("...searching " + nextIndex + " to " + dv); // Get the next neighbor in the direction nextIndex = Gameboard.GetIndexByOffsets(nextIndex, dv); // Did we find the border? Is there a valid piece in this square? // If not, stop searching if ((nextIndex == -1) || (Gameboard.Squares[nextIndex].Piece == null)) { result.Clear(); // clear the resul list since the direction isnt valid return(false); } nextOwner = Gameboard.Squares[nextIndex].Piece.Owner.IdType; // If neighbor to the neighbor in this direction is the same as the player, // the move is valid. if (nextOwner == player) { return(true); } } return(false); }
public Vector3D DirectionVector(DirectionVectors vector) { return featureVectors[(int)vector]; }
/// <summary> /// Returns a new index location based on a direction on the gameboard. /// If an invalid direction is determined, a position of -1 is return; /// </summary> /// <param name="index">The source location</param> /// <param name="dv">A direction vector from source location <see cref="DirectionVectors"/></param> /// <returns></returns> public int GetIndexByOffsets(int index, DirectionVectors dv) { int newIndex; switch (dv) { case DirectionVectors.NW: { newIndex = GetIndexByOffsets(index, -1, -1); break; } case DirectionVectors.N: { newIndex = GetIndexByOffsets(index, -1, 0); break; } case DirectionVectors.NE: { newIndex = GetIndexByOffsets(index, -1, 1); break; } case DirectionVectors.W: { newIndex = GetIndexByOffsets(index, 0, -1); break; } case DirectionVectors.E: { newIndex = GetIndexByOffsets(index, 0, 1); break; } case DirectionVectors.SW: { newIndex = GetIndexByOffsets(index, 1, -1); break; } case DirectionVectors.S: { newIndex = GetIndexByOffsets(index, 1, 0); break; } case DirectionVectors.SE: { newIndex = GetIndexByOffsets(index, 1, 1); break; } default: newIndex = -1; break; } // if (newIndex == -1) // MessageBox.Show(index + " is out of bounds in direction: " + dv.ToString()); return(newIndex); }