public static Direction FromVector(Vector2 vector2, float xLimit, float yLimit) { var x = vector2.x; var y = vector2.y; return(new Direction(DirectionValue.FromVector(x, xLimit), DirectionValue.FromVector(y, yLimit))); }
public static ushort FindDegree(DirectionValue directionValue) { ushort degree; switch (directionValue) { case DirectionValue.N: degree = (ushort)DirectionValue.N; break; case DirectionValue.E: degree = (ushort)DirectionValue.E; break; case DirectionValue.S: degree = (ushort)DirectionValue.S; break; case DirectionValue.W: degree = (ushort)DirectionValue.W; break; default: degree = (ushort)DirectionValue.N; break; } return(degree); }
void s_Links(DirectionValue direction, List <Pair <PositionValue, PositionValue> > positionpairs) { foreach (var pospair in positionpairs) { _boarddef.AddLink(direction, pospair.Item1, pospair.Item2); } }
private static Direction GetDirection(DirectionValue direction) { return(direction switch { DirectionValue.Left => Direction.Left, DirectionValue.Up => Direction.Up, DirectionValue.Right => Direction.Right, DirectionValue.Down => Direction.Down, _ => Direction.None, });
public void Turn180Degrees() { if (DirectionFacing == DirectionValue.Left) { DirectionFacing = DirectionValue.Right; } if (DirectionFacing == DirectionValue.Right) { DirectionFacing = DirectionValue.Left; } }
// remove link by direction internal void RemoveLink(PositionValue position, DirectionValue direction) { var links = LinkLookup.GetMulti(position); if (links != null) { links.RemoveAll(l => l.Direction == direction); if (links.Count == 0) { LinkLookup.Remove(position); } } }
public TransitionDTO(int Id, StateDTO From, StateDTO To, DirectionValue Value) { this.Id = Id; this.From = From; this.To = To; this.Value = new TransitionValue { Letter = Value.Letter.IsEpsilon ? new Letter('ε') : Value.Letter, LetterToPush = Value.LetterToPush != null ? Value.LetterToPush.IsEpsilon ? new Letter('ε') : Value.LetterToPush : null, LetterToPop = Value.LetterToPop != null ? Value.LetterToPop.IsEpsilon ? new Letter('ε') : Value.LetterToPop : null, }; }
internal static LinkDef Create(PositionValue from, DirectionValue direction, PositionValue to) { return(new LinkDef { From = from, Direction = direction, To = to }); }
//-- symmetries internal void AddSymmetry(PlayerValue player, DirectionValue directionValue1, DirectionValue directionValue2) { SymmetryLookup[Pair.Create(player, directionValue1)] = directionValue2; }
//--- links internal void AddLink(DirectionValue direction, PositionValue frompos, PositionValue topos) { LinkLookup.AddMulti(frompos, LinkDef.Create(frompos, direction, topos)); }
// get position following direction in reverse internal PositionValue GetOpposite(PositionValue position, DirectionValue direction) { // for every key for every value match to and direction, return position return(LinkLookup.Keys.FirstOrDefault(p => LinkLookup[p] .Any(lk => lk.To == position && lk.Direction == direction))); }
private Direction( DirectionValue dir ) { _dir = dir; }
// return position in opposite direction with respect to current position PositionValue s_Opposite(DirectionValue direction) { return(_board.Def.GetOpposite(_state.Current, direction) ?? BreakSafe()); }
public static HashSet <IState> PopulateTransitions( this HashSet <IState> states, IAlphabet alphabet, HashSet <ILetter> stack, InstructionsInput input) { var transitions = RegexHelper.Match(input.instructions, Instruction.TRANSITIONS).Split("\n"); foreach (var transition in transitions) { if (String.IsNullOrWhiteSpace(transition)) { continue; } var transitionGroup = transition.Trim().Split(InstructionDelimeter.TRANSITION_FROM_TO); var transitionFromValues = transitionGroup[0].Trim().Split(InstructionDelimeter.TRANSITION_FROM_VALUES, 2); var toStateValue = transitionGroup[1].Trim(); var fromStateValue = transitionFromValues[0].Trim(); var transitionLetter = new Letter(transitionFromValues[1].Trim().ToCharArray()[0]); var transitionValue = new DirectionValue { Letter = transitionLetter }; var pushDownGroup = RegexHelper.Match(transitionFromValues[1], "(?<=\\[)([\\S\\s].*?)*(?=])").Trim(); if (!String.IsNullOrWhiteSpace(pushDownGroup)) { var pushDownValues = pushDownGroup.Split(","); var letterToPop = new Letter(pushDownValues[0].Trim().ToCharArray()[0]); var letterToPush = new Letter(pushDownValues[1].Trim().ToCharArray()[0]); if ((!letterToPop.IsEpsilon && !stack.Contains(letterToPop)) || (!letterToPush.IsEpsilon && !stack.Contains(letterToPush)) ) { throw new Exception("Invalid push down values!"); } transitionValue.LetterToPop = letterToPop; transitionValue.LetterToPush = letterToPush; } if (transitionLetter.IsEpsilon && !alphabet.Letters.Contains(transitionLetter)) { alphabet.Letters.Add(transitionLetter); } if (alphabet.Letters.Contains(transitionLetter)) { foreach (var fromState in states) { if (fromState.Value.Equals(fromStateValue)) { foreach (var toState in states) { if (toState.Value.Equals(toStateValue)) { if (fromState.Directions.ContainsKey(toState)) { fromState.Directions[toState].Add(transitionValue); } else { fromState.Directions.Add(toState, new HashSet <DirectionValue>() { transitionValue }); } } } } } } } return(states); }
public void TurnRight() { DirectionFacing = DirectionValue.Right; }
public void TurnLeft() { DirectionFacing = DirectionValue.Left; }
public Direction(DirectionValue x, DirectionValue y) { X = x; Y = y; }
internal static OccupierDef Create(DirectionValue direction) { return(new OccupierDef { Direction = direction, }); }
private Direction(DirectionValue dir) { _dir = dir; }
// get position from position and direction internal PositionValue GetPosition(PositionValue position, PlayerValue player, DirectionValue direction) { if (!LinkLookup.ContainsKey(position)) { return(null); } var newdir = SymmetryLookup.SafeLookup(Pair.Create(player, direction)) ?? direction; var link = LinkLookup[position].FirstOrDefault(k => k.Direction == newdir); return((link == null) ? null : link.To); }