public Message MakeDecision(AgentInfo agent) { if (agent.ExchangeInfoRequests.Count > 0 && _exchageResponseCountdown <= 0) { var tmp = agent.ExchangeInfoRequests[0]; agent.ExchangeInfoRequests.RemoveAt(0); if (tmp.TeamId == _board.Team.ToString().ToLower()) { _exchageResponseCountdown = 10; return(GenerateExchageResponse(agent, tmp)); } } else { _exchageResponseCountdown--; } if (_board.MoveError) { _board.MoveError = false; return(GetRandomMove("E", "W")); } if (agent.HasPiece) { if (_board.IsFieldToPlaceOn(agent.Position)) { if (_board.GetFieldAt(agent.Position).DistToPiece == 0) { return(GetRandomMove("E", "W")); } return(new Message <PutPieceRequest>(new PutPieceRequest())); } return(GetMoveTo(agent.Position, _board.FieldsToPlaceOn[agent.Position.X].Position)); } if (_board.GetFieldAt(agent.Position)?.DistToPiece == 0 && !_board.IsFieldToPlaceOn(agent.Position)) { return(new Message <PickPieceRequest>(new PickPieceRequest())); } if (Dist(_board.FieldsToPlaceOn[agent.Position.X].Position, agent.Position) < 2) { return(new Message <MoveRequest>(new MoveRequest { Direction = _board.Team == Team.Blue ? "N" : "S" })); } CommonBoard.PosField fieldToTakeFrom; if (!((fieldToTakeFrom = FindFieldToTakeFrom(agent)) is null)) { return(GetMoveTo(agent.Position, fieldToTakeFrom.Position)); }
public Message MakeDecision(AgentInfo agent) { if (_board.MoveError) { _board.MoveError = false; return(GetRandomMove("W", "E", _board.Team == Team.Blue ? "S" : "N")); } if (agent.HasPiece) { Point undiscoveredGoal = FindUndiscoveredGoalCoordinates(agent.Position); if (undiscoveredGoal == agent.Position) { return(new Message <PutPieceRequest>(new PutPieceRequest())); } return(GetMoveTo(agent.Position, undiscoveredGoal)); } if (_board.GetFieldAt(agent.Position)?.DistToPiece == 0) { return(new Message <PickPieceRequest>(new PickPieceRequest())); } CommonBoard.PosField fieldToTakeFrom; if (!((fieldToTakeFrom = FindFieldToTakeFrom(agent)) is null)) { return(GetMoveTo(agent.Position, fieldToTakeFrom.Position)); }
public OrderingSubstrategy(GameStarted gameInfo, CommonBoard board) { _board = board; var sortedTeam = new List <int>(gameInfo.AlliesIds); sortedTeam.Add(gameInfo.AgentId); sortedTeam.Remove(gameInfo.LeaderId); sortedTeam.Sort(); sortedTeam.Add(gameInfo.LeaderId); int myIndex = sortedTeam.IndexOf(gameInfo.AgentId); if (myIndex != 0) { board.neighborIds.nearGoal = sortedTeam[myIndex - 1]; } if (myIndex != sortedTeam.Count - 1) { board.neighborIds.nearFront = sortedTeam[myIndex + 1]; } List <int> subareasLengths = GetSubareasLengths(gameInfo); board.MyBounds = GetMyBounds(gameInfo, subareasLengths, myIndex); board.MySubareaFields = new CommonBoard.PosField[gameInfo.BoardSize.X.Value, board.MyAreaSize]; for (int i = 0; i < gameInfo.BoardSize.X.Value; i++) { for (int j = 0; j < board.MyAreaSize; j++) { board.MySubareaFields[i, j] = new CommonBoard.PosField(i, board.MyBounds.Min + j); } } if (_board.Type != CommonBoard.AgentType.Goalie) { for (int i = 0; i < gameInfo.BoardSize.X.Value; i++) { board.FieldsToPlaceOn[i] = new CommonBoard.PosField(i, (board.Team == Team.Blue ? board.MyBounds.Min - 1 : board.MyBounds.Max + 1)); } } if (_board.Type != CommonBoard.AgentType.Leader) { for (int i = 0; i < gameInfo.BoardSize.X.Value; i++) { board.FieldsToTakeFrom[i] = board.GetFieldAt(new Point(i, (board.Team == Team.Red ? board.MyBounds.Min : board.MyBounds.Max))); } } //Log.Debug("I'm at {@position} and I should be between {@bounds}", // gameInfo.Position, board.MyBounds); //Log.Debug("I'm {agentId} and my neighbors are {neighborNearGoal} and {neighborNearFront}", // gameInfo.AgentId, board.neighborIds.nearGoal, board.neighborIds.nearFront); }