private void DoMove(Command c, MapCell target, int shipId)
 {
     if (c != null)
     {
         ValueMapping.AddNegativeShip(c.Ship, target);
         Fleet.AddMove(c);
     }
     else
     {
         Log.LogMessage($"Ship {shipId} tried to move to {target.position.ToString()} but could not.");
     }
 }
        public void Will_returnAttributeDataTypeMapping_When_Requested()
        {
            ValueMapping mapping = MappingFactory.GetMapping(MappingTypes.ATTRIBUTE_DATA_TYPE);

            Assert.IsNotNull(mapping);
            Assert.AreEqual(MappingTypes.ATTRIBUTE_DATA_TYPE, mapping.MappingType);
            Assert.AreEqual(typeof(char), mapping.ValueType);
            Assert.IsTrue(mapping.PossibleValues.ContainsKey('A'));
            Assert.AreEqual("Alpha numeric", mapping.PossibleValues['A']);
            Assert.IsTrue(mapping.PossibleValues.ContainsKey('N'));
            Assert.AreEqual("Numeric", mapping.PossibleValues['N']);
        }
        public void Will_ReturnStatusMapping_When_Requested()
        {
            ValueMapping mapping = MappingFactory.GetMapping(MappingTypes.STATUS);

            Assert.IsNotNull(mapping);
            Assert.AreEqual(MappingTypes.STATUS, mapping.MappingType);
            Assert.AreEqual(typeof(char), mapping.ValueType);
            Assert.IsTrue(mapping.PossibleValues.ContainsKey('N'));
            Assert.AreEqual("Normal", mapping.PossibleValues['N']);
            Assert.IsTrue(mapping.PossibleValues.ContainsKey('P'));
            Assert.AreEqual("Parked", mapping.PossibleValues['P']);
            Assert.IsTrue(mapping.PossibleValues.ContainsKey('C'));
            Assert.AreEqual("Closed", mapping.PossibleValues['C']);
            Assert.IsTrue(mapping.PossibleValues.ContainsKey('T'));
            Assert.AreEqual("Terminated", mapping.PossibleValues['T']);
        }
        private void ButtonDelete_Click(object sender, RoutedEventArgs e)
        {
            if (Selected == null)
            {
                MessageBox.Show("Select line", "Not selected", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }

            MessageBoxResult result = MessageBox.Show("Do you want to delete this line?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question);

            if (result == MessageBoxResult.Yes)
            {
                var selected = Selected;
                Selected = null;
                Items.Remove(selected);
            }
        }
        public override void CommandShips()
        {
            var list = new List <Projection>();

            Fleet.AvailableShips.ForEach(s => list.Add(new Projection(s)));
            list = list.OrderBy(p => p.numTurns).ToList();
            while (list.Count > 0)
            {
                // switch next to a ship on a dropoff if it's surrounded
                var next = list[0];
                foreach (var proj in list.Where(l => l.ship.OnDropoff))
                {
                    if (proj.ship.Neighbors.All(n => Fleet.CollisionCells.Contains(n) || n.IsOccupied()))
                    {
                        next = proj;
                        break;
                    }
                }
                var s = next.ship;
                if (next.valuer.TurnsToFill(s, ValueMapping.IsPreviousTarget(s.Id, next.valuer.Target.position)) != next.numTurns)
                {
                    list[list.IndexOf(next)] = new Projection(s);
                    list.OrderBy(p => p.numTurns);
                    continue;
                }
                Command move;
                if (!s.CanMove)
                {
                    move = s.StayStill("Ship cannot move, forcing it to stay still... Target " + next.valuer.Target.position.ToString() + "... Expected Turns: " + next.numTurns);
                }
                else if (!(s.CurrentMapCell.Neighbors.Any(n => n.halite > GameInfo.UpperThirdAverage && n.halite > s.CellHalite * MyBot.HParams[Parameters.STAY_MULTIPLIER])) &&
                         s.CellHalite > GameInfo.UpperThirdAverage && Safety.IsSafeMove(s, Direction.STILL))
                {
                    move = s.StayStill("Forcing ship to sit still... Target " + next.valuer.Target.position.ToString() + "... Expected Turns: " + next.numTurns);
                }
                else
                {
                    move = next.GetMove();
                }
                DoMove(move, next.valuer.Target, next.ship.Id);
                list.Remove(next);
            }
        }
        public void Will_ReturnBflagMapping_When_Requested()
        {
            ValueMapping mapping = MappingFactory.GetMapping(MappingTypes.BFLAG);

            Assert.IsNotNull(mapping);
            Assert.AreEqual(MappingTypes.BFLAG, mapping.MappingType);
            Assert.AreEqual(typeof(int), mapping.ValueType);
            Assert.IsTrue(mapping.PossibleValues.ContainsKey(1));
            Assert.AreEqual("Address(A)", mapping.PossibleValues[1]);
            Assert.IsTrue(mapping.PossibleValues.ContainsKey(2));
            Assert.AreEqual("Memory/cache(M)", mapping.PossibleValues[2]);
            Assert.IsTrue(mapping.PossibleValues.ContainsKey(4));
            Assert.AreEqual("Workflow(W)", mapping.PossibleValues[4]);
            Assert.IsTrue(mapping.PossibleValues.ContainsKey(8));
            Assert.AreEqual("Master file(MF)", mapping.PossibleValues[8]);
            Assert.IsTrue(mapping.PossibleValues.ContainsKey(16));
            Assert.AreEqual("Dates on relations", mapping.PossibleValues[16]);
            Assert.IsTrue(mapping.PossibleValues.ContainsKey(32));
            Assert.AreEqual("Form", mapping.PossibleValues[32]);
        }
 public Projection(Ship s)
 {
     this.valuer   = ValueMapping.FindBestTarget(s);
     this.numTurns = this.valuer.TurnsToFill(s, ValueMapping.IsPreviousTarget(s.Id, this.valuer.Target.position));
     this.ship     = s;
 }