public NextAction Next(Pac pac, CancellationToken cancellation, params Pac[] enemies) { if (!enemies.Any()) { return(new NoAction(pac)); } var closestY = enemies.OrderBy(p => Math.Abs(p.Location.X - pac.Location.X)).First(); var closestX = enemies.OrderBy(p => Math.Abs(p.Location.Y - pac.Location.Y)).First(); Pac closestEnemy; if (Math.Abs(closestX.Location.X - pac.Location.X) < Math.Abs(closestY.Location.Y - pac.Location.Y)) { closestEnemy = closestX; } else { closestEnemy = closestX; } var typeToBeatEnemy = PacType.ToBeat(closestEnemy.Type); if (pac.SpecialActionReady && pac.Type != typeToBeatEnemy) { Console.Error.WriteLine($"Me {pac.Id} {pac.Type} switching to {typeToBeatEnemy}"); return(new SwitchAction(pac, typeToBeatEnemy)); } if (pac.Type.Play(closestEnemy.Type) == PacType.Outcome.Win) { return(new MoveAction(pac, closestEnemy.Location)); } return(new NoAction(pac)); }
public PacMan( int pacId, bool mine, Position position, string type, int speedTurnsLeft, int abilityCooldown ) { m_pacId = pacId; m_mine = mine; m_position = position; m_speedTurnsLeft = speedTurnsLeft; m_abilityCooldown = abilityCooldown; switch (type) { case "ROCK": m_type = PacType.Rock; break; case "PAPER": m_type = PacType.Paper; break; case "SCISSORS": m_type = PacType.Scissors; break; } }
public PacSignature(PacType ptype, EncryptionType etype) { this.PacType = ptype; this.Type = CryptoService.ConvertType(etype); this.Signature = SetSignatureValue(this.Type, size => new byte[size]); }
private void ParsePacType(PacType type, ReadOnlyMemory <byte> pacInfoBuffer, out int exclusionStart, out int exclusionLength) { exclusionStart = 0; exclusionLength = 0; if (!KnownTypes.TryGetValue(type, out Type pacObjectType)) { return; } var attribute = (PacObject)Activator.CreateInstance(pacObjectType); if (pacInfoBuffer.Length > 0) { PacSignature signature = null; if (attribute is PacSignature) { signature = (PacSignature)attribute; signature.SignatureData = pacData; } attribute.Unmarshal(pacInfoBuffer); if (signature != null) { exclusionStart = signature.SignaturePosition; exclusionLength = signature.Signature.Length; } } attributes[type] = attribute; }
public Point GetTarget(ref Pac pac) { Point target = null; Pac enemyPac = PacController.GetClosestEnemy(pac); //Pac enemyPac = PacController.GetClosestVisibleEnemy(pac, true); int distanceToEnemy; if (enemyPac != null) { distanceToEnemy = pac.origin.GetDistanceTo(enemyPac.origin); PacType strongerThanMe = Common.GetStrongerPacType(pac.pacType); PacType strongerThanHim = Common.GetStrongerPacType(enemyPac.pacType); Console.Error.WriteLine("ATTACK! pacType" + pac.pacType.ToString() + " strongerThanHim:" + strongerThanHim.ToString() + " distance:" + distanceToEnemy.ToString()); if (pac.pacType == strongerThanHim && distanceToEnemy <= 6) { pac.shouldActivateSpeed = true; pac.inPursuit = true; target = enemyPac.origin; } else { if (pac.cooldown > (enemyPac.speedTurnsLeft > 0 ? distanceToEnemy / 2 : distanceToEnemy)) { //Bezanija!!! //Level.GetClosestJunctionInDirection(); } } } Console.Error.WriteLine("PacId:" + pac.id + " Strategy: Attack " + ((target == null) ? "null" : target.ToString()) + " inPursuit:" + pac.inPursuit.ToString()); return(target); }
public Pac(int id, int x, int y, PacType type) { Id = id; Type = type; Position = new Coordinate(x, y); IsAlive = true; _previousPosition = new Coordinate(-1, -1); }
public void Update(int x, int y, PacType type, int speedTurnsLeft, int abilityCooldown) { _previousPosition = new Coordinate(Position); Position.Update(x, y); IsAlive = type != PacType.Unknown; Type = type; SpeedTurnsLeft = speedTurnsLeft; AbilityCooldown = abilityCooldown; }
public void GamesAreCorrect(string p1, string p2, char outcome) { PacType player1 = new PacType(p1); PacType player2 = new PacType(p2); PacType.Outcome expected = (PacType.Outcome)outcome; Assert.Equal(expected, player1.Play(player2)); }
private T GetAttribute <T>(PacType type) where T : PacObject { if (attributes.TryGetValue(type, out PacObject obj)) { return((T)obj); } return(null); }
public void ReadTick(string[] inputs) { // Id = int.Parse(inputs[0]); // pac number (unique within a team) IsMine = inputs[1] == "1"; // true if this pac is yours var x = ushort.Parse(inputs[2]); // position in the grid var y = ushort.Parse(inputs[3]); // position in the grid Pos = new Point(x, y); Type = ParseType(inputs[4]); SpeedTurnsLeft = int.Parse(inputs[5]); AbilityCooldown = int.Parse(inputs[6]); }
private void ParsePacType(PacType type, byte[] infoBuffer, out int exclusionStart, out int exclusionLength) { exclusionStart = 0; exclusionLength = 0; switch (type) { case PacType.LOGON_INFO: LogonInfo = new PacLogonInfo(infoBuffer); break; case PacType.CREDENTIAL_TYPE: CredentialType = new PacCredentialInfo(infoBuffer); break; case PacType.SERVER_CHECKSUM: ServerSignature = new PacSignature(infoBuffer, ref signatureData); exclusionStart = ServerSignature.SignaturePosition; exclusionLength = ServerSignature.Signature.Length; break; case PacType.PRIVILEGE_SERVER_CHECKSUM: KdcSignature = new PacSignature(infoBuffer, ref signatureData); exclusionStart = KdcSignature.SignaturePosition; exclusionLength = KdcSignature.Signature.Length; break; case PacType.CLIENT_NAME_TICKET_INFO: ClientInformation = new PacClientInfo(infoBuffer); break; case PacType.CONSTRAINED_DELEGATION_INFO: DelegationInformation = new PacDelegationInfo(infoBuffer); break; case PacType.UPN_DOMAIN_INFO: UpnDomainInformation = new UpnDomainInfo(infoBuffer); break; case PacType.CLIENT_CLAIMS: ClientClaims = new ClaimsSetMetadata(infoBuffer); break; case PacType.DEVICE_INFO: break; case PacType.DEVICE_CLAIMS: DeviceClaims = new ClaimsSetMetadata(infoBuffer); break; } }
private PacSignature ProcessSignature(PacSignature signature, PacType type) { if (type == PacType.PRIVILEGE_SERVER_CHECKSUM) { signature.SignatureData = this.ServerSignature.Signature; } else { signature.SignatureData = pacData; } return(signature); }
public void EqualityTests(string left, string right, bool expected) { var leftType = new PacType(left); var rightType = new PacType(right); Assert.Equal(expected, leftType.Equals(rightType)); Assert.Equal(expected, rightType.Equals(leftType)); Assert.Equal(expected, leftType == rightType); Assert.Equal(expected, rightType == leftType); Assert.Equal(!expected, leftType != rightType); Assert.Equal(!expected, rightType != leftType); }
public static PacType GetAdvantage(PacType f) { switch (f) { case PacType.Rock: return(PacType.Scissors); case PacType.Paper: return(PacType.Rock); case PacType.Scissors: return(PacType.Paper); default: throw new ArgumentOutOfRangeException(); } }
/* * Return the type to counter the enemy's type */ private string CounterPacType(PacType enemyType) { switch (enemyType) { case PacType.Rock: return("PAPER"); case PacType.Paper: return("SCISSORS"); case PacType.Scissors: default: return("ROCK"); } }
public bool CanBeEaten(PacType type) { switch (Type) { case PacType.Rock: return(type == PacType.Paper); case PacType.Paper: return(type == PacType.Scissors); case PacType.Scissors: return(type == PacType.Rock); default: return(false); } }
public void UpdatePac( int id, int x, int y, PacType type, int speedTurnsLeft, int abilityCooldown) { if (!Pacs.ContainsKey(id)) { Pacs[id] = new Pac(id, x, y, type); } else { Pacs[id].Update(x, y, type, speedTurnsLeft, abilityCooldown); } }
private void ParsePacType(PacType type, byte[] data) { switch (type) { case PacType.LOGON_INFO: LogonInfo = new PacLogonInfo(data); break; case PacType.CREDENTIAL_TYPE: CredentialType = data; break; case PacType.SERVER_CHECKSUM: ServerSignature = new PacSignature(data); break; case PacType.PRIVILEGE_SERVER_CHECKSUM: KdcSignature = new PacSignature(data); break; case PacType.CLIENT_NAME_TICKET_INFO: ClientInformation = new PacClientInfo(data); break; case PacType.CONSTRAINED_DELEGATION_INFO: break; case PacType.UPN_DOMAIN_INFO: UpnDomainInformation = new UpnDomainInfo(data); break; case PacType.CLIENT_CLAIMS: ClientClaims = new ClaimsSetMetadata(data); break; case PacType.DEVICE_INFO: break; case PacType.DEVICE_CLAIMS: DeviceClaims = new ClaimsSetMetadata(data); break; } }
public Point GetTarget(ref Pac pac) { Console.Error.WriteLine("Mimic strategy start"); Point target = null; Pac enemyPac = PacController.GetClosestVisibleEnemy(pac, true); int distance = Common.minDistanceForSwitch; if (enemyPac != null) { if (enemyPac.speedTurnsLeft > 0) { if (pac.speedTurnsLeft > 0) { distance = distance + 2; } else { distance = distance + 1; } } } if (enemyPac != null && pac.origin.GetDistanceTo(enemyPac.origin) <= distance) { PacType strongerType = Common.GetStrongerPacType(enemyPac.pacType); if (pac.pacType != strongerType) { pac.shouldActivateSwitch = true; pac.switchTo = strongerType; } } else { return(null); } target = enemyPac.origin; Console.Error.WriteLine("PacId:" + pac.id + " Strategy: Mimic " + ((target == null) ? "null" : target.ToString())); return(target); }
public static PacType GetStrongerPacType(PacType otherPacType) { PacType result = PacType.PAPER; switch (otherPacType) { case PacType.PAPER: result = PacType.SCISSORS; break; case PacType.ROCK: result = PacType.PAPER; break; case PacType.SCISSORS: result = PacType.ROCK; break; } return(result); }
private void ParsePacType(PacType type, ReadOnlyMemory <byte> pacInfoBuffer, out int exclusionStart, out int exclusionLength) { exclusionStart = 0; exclusionLength = 0; if (!KnownTypes.TryGetValue(type, out Type pacObjectType)) { this.Attributes[type] = new UnknownPacObject(type, pacInfoBuffer); return; } var attribute = (PacObject)Activator.CreateInstance(pacObjectType); if (pacInfoBuffer.Length <= 0) { return; } PacSignature signature = null; if (attribute is PacSignature sig) { signature = this.ProcessSignature(sig, type); if (!this.Mode.HasFlag(SignatureMode.Kdc) && type == PacType.PRIVILEGE_SERVER_CHECKSUM) { signature.Ignored = true; } } attribute.Unmarshal(pacInfoBuffer); if (signature != null) { exclusionStart = signature.SignaturePosition; exclusionLength = signature.Signature.Length; } this.Attributes[type] = attribute; }
public SwitchAction(Pac pac, PacType newType) : base(pac) { NewType = newType; }
public void Switch(PacType toType) { Console.Write($"SWITCH {Id >> 1} {toType.ToString().ToUpper()} |"); }
public ResultEventArgs(bool success, PacType pacType) { Success = success; PacType = pacType; }
public UnknownPacObject(PacType type, ReadOnlyMemory <byte> blob) { this.PacType = type; this.Blob = blob; }
public static void RegisterType(PacType pacType, Type type) { KnownTypes[pacType] = type; }
public static bool CanBeat(PacType f, PacType t) => GetAdvantage(f) == t;
public POrderSwitch(Pac owner, PacType toType) : base(owner) { _toType = toType; }
public Pac(int id, Point origin, string pacType) { this.id = id; this.origin = origin; this.pacType = MapType(pacType); }