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)); }
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); }
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); }
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); } }
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); }
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); }
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); }
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); }
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); }