public override (Wheel[], ControlInfo) GetInstruction(Field field) { if (_strategy == null) { throw new DllNotFoundException(); } var nativeField = new Native.Field(field); if (ReverseCoordinate) { nativeField.Reverse(); } var env = new Native.Legacy.Environment(nativeField, whosball, gameState, userData); try { _strategy(ref env); userData = env.UserData; } catch (Exception e) { throw new DllException("Strategy", e); } var controlInfo = new ControlInfo { Command = ControlType.Continue }; var wheel = env.SelfRobots.Select(x => new Wheel() { LeftSpeed = (float)x.VelocityLeft, RightSpeed = (float)x.VelocityRight }).ToArray(); return(wheel, controlInfo); }
public override (Wheel[], ControlInfo) GetInstruction(Field field) { if (_getInstruction == null) { throw new DllNotFoundException(); } // 将 Proto 的结构转为本地结构 var nativeField = new Native.Field(field); var controlInfo = new ControlInfo(); if (ReverseCoordinate) { // 翻转,获得黄方坐标 nativeField.Reverse(); } try { _getInstruction(ref nativeField); } catch (Exception e) { throw new DllException("GetInstruction", e); } return(nativeField.SelfRobots.Select(x => (Wheel)x.wheel).ToArray(), GetControlInfo(controlInfo)); }
public override Placement GetPlacement(Field field) { if (_getPlacement == null) { throw new DllNotFoundException(); } var nativeField = new Native.Field(field); if (ReverseCoordinate) { nativeField.Reverse(); } try { _getPlacement(ref nativeField); } catch (Exception e) { throw new DllException("GetPlacement", e); } return(new Placement { Ball = (Ball)nativeField.ball, Robots = { from x in nativeField.SelfRobots select(Robot)(ReverseCoordinate ? x.Reverse() : x) } }); }
public Environment(Native.Field field, V5RPC.Proto.Team whosball, ResultType gamestate, IntPtr userData) { WhosBall = ToLegacyWhosball(whosball); GameState = ToLegacyGameState(gamestate); SelfRobots = new Legacy.Robot[5]; OpponentRobots = new Legacy.OpponentRobot[5]; for (int i = 0; i < 5; i++) { SelfRobots[i] = new Legacy.Robot(field.SelfRobots[i]); OpponentRobots[i] = new Legacy.OpponentRobot(field.opponentRobots[i]); } CurrentBall = new Legacy.Ball() { Position = new Legacy.Vector3(field.ball.position) }; UserData = userData; // Useless field, just become 0 LastBall = new Legacy.Ball(); PredictedBall = new Legacy.Ball(); FieldBounds = new Legacy.Bounds(); GoalBounds = new Legacy.Bounds(); }