コード例 #1
0
        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));
        }
コード例 #2
0
ファイル: Player.cs プロジェクト: grgomez/codeingame_practice
        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;
            }
        }
コード例 #3
0
ファイル: PacSignature.cs プロジェクト: dotnet/Kerberos.NET
        public PacSignature(PacType ptype, EncryptionType etype)
        {
            this.PacType = ptype;
            this.Type    = CryptoService.ConvertType(etype);

            this.Signature = SetSignatureValue(this.Type, size => new byte[size]);
        }
コード例 #4
0
        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;
        }
コード例 #5
0
        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);
        }
コード例 #6
0
ファイル: Pac.cs プロジェクト: AnkurSheel/codingame
 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);
 }
コード例 #7
0
ファイル: Pac.cs プロジェクト: AnkurSheel/codingame
 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;
 }
コード例 #8
0
ファイル: RpsTests.cs プロジェクト: simonjduff/CodinGame-Pacs
        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));
        }
コード例 #9
0
        private T GetAttribute <T>(PacType type)
            where T : PacObject
        {
            if (attributes.TryGetValue(type, out PacObject obj))
            {
                return((T)obj);
            }

            return(null);
        }
コード例 #10
0
    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]);
    }
コード例 #11
0
        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;
            }
        }
コード例 #12
0
        private PacSignature ProcessSignature(PacSignature signature, PacType type)
        {
            if (type == PacType.PRIVILEGE_SERVER_CHECKSUM)
            {
                signature.SignatureData = this.ServerSignature.Signature;
            }
            else
            {
                signature.SignatureData = pacData;
            }

            return(signature);
        }
コード例 #13
0
        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);
        }
コード例 #14
0
    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();
        }
    }
コード例 #15
0
ファイル: Player.cs プロジェクト: grgomez/codeingame_practice
        /*
         *  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");
            }
        }
コード例 #16
0
ファイル: Pac.cs プロジェクト: AnkurSheel/codingame
        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);
            }
        }
コード例 #17
0
 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);
     }
 }
コード例 #18
0
        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;
            }
        }
コード例 #19
0
        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);
        }
コード例 #20
0
        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);
        }
コード例 #21
0
        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;
        }
コード例 #22
0
 public SwitchAction(Pac pac, PacType newType) : base(pac)
 {
     NewType = newType;
 }
コード例 #23
0
 public void Switch(PacType toType)
 {
     Console.Write($"SWITCH {Id >> 1} {toType.ToString().ToUpper()} |");
 }
コード例 #24
0
 public ResultEventArgs(bool success, PacType pacType)
 {
     Success = success;
     PacType = pacType;
 }
コード例 #25
0
ファイル: PacObject.cs プロジェクト: dotnet/Kerberos.NET
 public UnknownPacObject(PacType type, ReadOnlyMemory <byte> blob)
 {
     this.PacType = type;
     this.Blob    = blob;
 }
コード例 #26
0
 public static void RegisterType(PacType pacType, Type type)
 {
     KnownTypes[pacType] = type;
 }
コード例 #27
0
 public static bool CanBeat(PacType f, PacType t) => GetAdvantage(f) == t;
コード例 #28
0
ファイル: POrderSwitch.cs プロジェクト: hoggins/codingame
 public POrderSwitch(Pac owner, PacType toType) : base(owner)
 {
     _toType = toType;
 }
コード例 #29
0
 public Pac(int id, Point origin, string pacType)
 {
     this.id      = id;
     this.origin  = origin;
     this.pacType = MapType(pacType);
 }