Esempio n. 1
0
        private List <Tuple <int, int> > SetSocialLaw(List <string> messages)
        {
            if (!messages.Exists(m => FibaAcl.GetPerformative(m) == "inform"))
            {
                return(null);
            }

            var informMsg = messages.First(m => FibaAcl.GetPerformative(m) == "inform");
            var content   = FibaAcl.MessageToDict(FibaAcl.GetInnerMessage(informMsg));
            var directive = content["content"];
            var temp      = directive.Substring(directive.IndexOf('(') + 1, directive.Length - directive.IndexOf('(') - 2);
            var pos       = temp.Split(',');
            var posTuple  = new Tuple <int, int>(int.Parse(pos[0]), int.Parse(pos[1]));
            var colsTuple = new Tuple <int, int>(posTuple.Item2, posTuple.Item2 + _room.GetLength(1) / Platform.Directory.Count - 1);

            var result   = new List <Tuple <int, int> >();
            var startRow = _room.GetLength(0) - 1;
            var dx       = -1;

            // Generate path to clean
            for (var col = colsTuple.Item1; col <= colsTuple.Item2; col++)
            {
                startRow = startRow == _room.GetLength(0) - 1 ? 0 : _room.GetLength(0) - 1;
                dx       = dx == -1 ? 1 : -1;

                for (var row = startRow; row < _room.GetLength(0) && row >= 0; row += dx)
                {
                    result.Add(new Tuple <int, int>(row, col));
                }
            }

            return(result);
        }
Esempio n. 2
0
        public void Bid(IEnumerable <string> tasks)
        {
            var n = _room.GetLength(0);

            _wishList.Clear();

            foreach (var task in tasks)
            {
                var innerMessage = FibaAcl.GetInnerMessage(task);
                var messageDict  = FibaAcl.MessageToDict(innerMessage);
                var content      = messageDict["content"];
                var subtask      = content.Substring(0, content.IndexOf('('));
                var cols         = new string[2];

                switch (subtask)
                {
                case "clean":
                    var temp = content.Substring(content.IndexOf('(') + 1, content.Length - content.IndexOf('(') - 2);
                    cols = temp.Split(',');
                    break;
                }

                var colRange = new Tuple <int, int>(int.Parse(cols[0]), int.Parse(cols[1]));

                for (var i = colRange.Item1; i < colRange.Item2; i++)
                {
                    // Distance to extreme points for each column
                    var end1 = new Tuple <int, int>(0, i);
                    var end2 = new Tuple <int, int>(n - 1, i);

                    var dist1 = ManhattanDistance(end1, new Tuple <int, int>(X, Y));
                    var dist2 = ManhattanDistance(end2, new Tuple <int, int>(X, Y));

                    _wishList.Add(new Tuple <double, Tuple <int, int> >(dist1, end1));
                    _wishList.Add(new Tuple <double, Tuple <int, int> >(dist2, end2));
                }
            }

            _wishList.Sort(Comparison);

            foreach (var bid in _wishList)
            {
                Language.Message(Performative.Proposal, Id.ToString(), Platform.Manager.Id.ToString(), bid.Item1 + "," + bid.Item2.Item1 + "," + bid.Item2.Item2);
            }
        }