Exemple #1
0
        public Transaction Turn(MyCell[] myBlocks)
        {
            var source = GetSource(myBlocks);

            NeighbourCell target = null;

            if (myBlocks.Length >= ids.Count)
            {
                AddId(myBlocks);
                target = GetTarget(myBlocks, source.Resources);

                if (target == null)
                {
                    target = GetTargetOther(myBlocks, source.Resources);
                }
            }
            else
            {
                target = GetTargetOtherAggressively(myBlocks, source.Resources);
            }

            var resource = 0;

            if (target != null)
            {
                resource = _rnd.Next(target.Resources + 1, source.Resources);
            }
            else
            {
                target   = GetTargetNeighbourOwn(myBlocks, source);
                resource = source.Resources;
            }

            return(new Transaction(source.Id, target.Id, resource));
        }
Exemple #2
0
        private NeighbourCell GetTargetOtherAggressively(MyCell[] myBlocks, int sourceResources)
        {
            int           c = 0;
            NeighbourCell countNeighbourCell = null;

            for (int i = 0; i < myBlocks.Length; i++)
            {
                for (int ii = 0; ii < myBlocks[i].Neighbours.Length; ii++)
                {
                    if (myBlocks[i].Neighbours[ii].Owner != CellOwner.Own)
                    {
                        int count = myBlocks[i].Neighbours.Count(item => item.Owner == CellOwner.Own);
                        if (countNeighbourCell == null || myBlocks[i].Neighbours[ii].Resources <= countNeighbourCell.Resources && count > c)
                        {
                            c = count;
                            countNeighbourCell = myBlocks[i].Neighbours[ii];
                        }
                    }
                }
            }

            if (countNeighbourCell != null && countNeighbourCell.Resources < sourceResources)
            {
                return(countNeighbourCell);
            }

            return(null);
        }
Exemple #3
0
        private NeighbourCell GetTarget(MyCell[] myBlocks)
        {
            NeighbourCell neighbourCellNone  = null;
            NeighbourCell neighbourCellOther = null;

            for (int i = 0; i < myBlocks.Length; i++)
            {
                for (int ii = 0; ii < myBlocks[i].Neighbours.Length; ii++)
                {
                    if (myBlocks[i].Neighbours[ii].Owner == CellOwner.None)
                    {
                        if (neighbourCellNone == null || myBlocks[i].Neighbours[ii].Resources < neighbourCellNone.Resources)
                        {
                            neighbourCellNone = myBlocks[i].Neighbours[ii];
                        }
                    }
                    else if (myBlocks[i].Neighbours[ii].Owner == CellOwner.Other)
                    {
                        if (neighbourCellOther == null || myBlocks[i].Neighbours[ii].Resources < neighbourCellOther.Resources)
                        {
                            neighbourCellOther = myBlocks[i].Neighbours[ii];
                        }
                    }
                }
            }
            if (neighbourCellNone == null)
            {
                return(neighbourCellOther);
            }
            return(neighbourCellNone);
        }
Exemple #4
0
 public MyCell(HexagonCell hexagonCell, string ownerName)
 {
     Id         = hexagonCell.Id;
     Resources  = hexagonCell.Resources;
     Neighbours = new NeighbourCell[hexagonCell.Neighbours.Length];
     for (int i = 0; i < hexagonCell.Neighbours.Length; i++)
     {
         Neighbours[i] = new NeighbourCell(hexagonCell.Neighbours[i], ownerName);
     }
 }
Exemple #5
0
        private NeighbourCell GetTargetNeighbourOwn(MyCell source)
        {
            int           neighboursCount = 0;
            NeighbourCell neighbourCell   = null;

            for (int i = 0; i < source.Neighbours.Length; i++)
            {
                int count = source.Neighbours.Count(item => item.Owner == CellOwner.Own);
                if (neighbourCell == null || count > neighboursCount || (count >= neighboursCount && source.Neighbours[i].Resources >= neighbourCell.Resources))
                {
                    neighboursCount = count;
                    neighbourCell   = source.Neighbours[i];
                }
            }
            return(neighbourCell);
        }
Exemple #6
0
        private NeighbourCell GetTargetNeighbourOwn(MyCell[] myBlocks, MyCell source)
        {
            int           neighboursCount = 0;
            NeighbourCell neighbourCell   = null;

            for (int i = 0; i < source.Neighbours.Length; i++)
            {
                if (source.Neighbours[i].Owner == CellOwner.Own)
                {
                    int count = source.Neighbours.Count(item => item.Owner == CellOwner.Own);
                    if (neighbourCell == null || count > neighboursCount || (count >= neighboursCount && source.Neighbours[i].Resources >= neighbourCell.Resources))
                    {
                        neighboursCount = count;
                        neighbourCell   = source.Neighbours[i];
                    }
                }
            }
            if (neighbourCell != null)
            {
                return(neighbourCell);
            }

            for (int i = 0; i < myBlocks.Length; i++)
            {
                for (int ii = 0; ii < myBlocks[i].Neighbours.Length; ii++)
                {
                    if (myBlocks[i].Neighbours[ii].Owner == CellOwner.Own)
                    {
                        return(myBlocks[i].Neighbours[ii]);
                    }
                }
            }

            for (int i = 0; i < myBlocks.Length; i++)
            {
                for (int ii = 0; ii < myBlocks[i].Neighbours.Length; ii++)
                {
                    if (neighbourCell == null || source.Resources >= neighbourCell.Resources)
                    {
                        neighbourCell = myBlocks[i].Neighbours[ii];
                    }
                }
            }

            return(neighbourCell);
        }
Exemple #7
0
        private NeighbourCell GetTargetOther(MyCell[] myBlocks, int sourceResources)
        {
            const int RESOURCES = 1;

            NeighbourCell minNeighbourCell = null;

            NeighbourCell[] countNeighbourCell = new NeighbourCell[7];
            for (int i = 0; i < myBlocks.Length; i++)
            {
                for (int ii = 0; ii < myBlocks[i].Neighbours.Length; ii++)
                {
                    if (myBlocks[i].Neighbours[ii].Owner != CellOwner.Own)
                    {
                        if (minNeighbourCell == null || myBlocks[i].Neighbours[ii].Resources < minNeighbourCell.Resources)
                        {
                            minNeighbourCell = myBlocks[i].Neighbours[ii];
                        }

                        int count = myBlocks[i].Neighbours.Count(item => item.Owner == CellOwner.Own);

                        if (countNeighbourCell[count] == null || myBlocks[i].Neighbours[ii].Resources <= countNeighbourCell[count].Resources)
                        {
                            countNeighbourCell[count] = myBlocks[i].Neighbours[ii];
                        }
                    }
                }
            }

            for (int i = countNeighbourCell.Length - 1; i >= 0; i--)
            {
                if (countNeighbourCell[i] != null)
                {
                    if (countNeighbourCell[i].Resources - i * RESOURCES < minNeighbourCell.Resources && countNeighbourCell[i].Resources < sourceResources)
                    {
                        return(countNeighbourCell[i]);
                    }
                }
            }

            if (minNeighbourCell.Resources < sourceResources)
            {
                return(minNeighbourCell);
            }

            return(null);
        }
Exemple #8
0
        private NeighbourCell GetTarget(List <NeighbourCell> neighbourCells, int sourceResources)
        {
            NeighbourCell neighbourCell = null;

            for (int i = 0; i < neighbourCells.Count; i++)
            {
                if (neighbourCell == null || neighbourCells[i].Resources < neighbourCell.Resources)
                {
                    neighbourCell = neighbourCells[i];
                }
            }

            if (neighbourCell != null && neighbourCell.Resources < sourceResources)
            {
                return(neighbourCell);
            }

            return(null);
        }
Exemple #9
0
        private NeighbourCell GetTargetNone(MyCell[] myBlocks)
        {
            NeighbourCell neighbourCell = null;

            for (int i = 0; i < myBlocks.Length; i++)
            {
                for (int ii = 0; ii < myBlocks[i].Neighbours.Length; ii++)
                {
                    if (myBlocks[i].Neighbours[ii].Owner == CellOwner.None)
                    {
                        if (neighbourCell == null || myBlocks[i].Neighbours[ii].Resources < neighbourCell.Resources)
                        {
                            neighbourCell = myBlocks[i].Neighbours[ii];
                        }
                    }
                }
            }
            return(neighbourCell);
        }