protected override bool ParseCommand(string cmd) { if (IsQueryRequest) { return(cmd.Length == 0); } var parts = cmd.Split(','); if (parts.Length != 2) { return(false); } if (parts[0][0] == '+' || parts[0][0] == '-') { EnableXS = (BitState)parts[0][0]; parts[0] = parts[0].Substring(1); } XS = (ExtendedSettings)int.Parse(parts[0]); if (parts[1][0] == '+' || parts[1][0] == '-') { EnableOptions2 = (BitState)parts[1][0]; parts[1] = parts[1].Substring(1); } Options2 = int.Parse(parts[1]); return(true); }
public string getCommand(Move move) { var mapPos = BitState.GetMapIndex(position); int comx = mapPos.Item1; int comy = mapPos.Item2; switch (move.direction) { case MoveDirection.Right: comx++; break; case MoveDirection.Left: comx--; break; case MoveDirection.Up: comy--; break; case MoveDirection.Down: comy++; break; } if (move.type == MoveType.Move) { return("MOVE " + comx + " " + comy); } else { return("BOMB " + comx + " " + comy); } }
/// <summary> /// 写Bit位值 /// </summary> /// <param name="mr"></param> /// <param name="ch"></param> /// <param name="bs"></param> /// <returns></returns> public short SetBitState(PlcMemory mr, string ch, BitState bs) { byte[] rd = new byte[30]; short num = short.Parse(ch.Split(new char[] { '.' })[0]); short offset = short.Parse(ch.Split(new char[] { '.' })[1]); byte[] buffer2 = FinsClass.FinsCmd(RorW.Write, mr, MemoryType.Bit, num, offset, 1); byte[] array = new byte[0x23]; buffer2.CopyTo(array, 0); array[0x22] = (byte)bs; if (BasicClass.SendData(array) == 0) { if (BasicClass.ReceiveData(rd) == 0) { bool flag = true; if (rd[11] == 3) { flag = ErrorCode.CheckHeadError(rd[15]); } if (flag) { if (ErrorCode.CheckEndCode(rd[0x1c], rd[0x1d])) { return(0); } return(-1); } } return(-1); } return(-1); }
public static void Main(string[] args) { var timer = new Stopwatch(); timer.Start(); BitMaps.GenerateMoves(); BitMaps.GenerateBombs(); timer.Stop(); char[,] map = new char[13, 11]; List <Robot> bots = new List <Robot>(); List <Bomb> bombs = new List <Bomb>(); var bomb = new Bomb(); bomb.position = 2; bomb.owner = 0; bomb.range = 3; bomb.countDown = 7; bombs.Add(bomb); bomb = new Bomb(); bomb.position = 13; bomb.owner = 0; bomb.range = 3; bomb.countDown = 4; bombs.Add(bomb); for (int i = 0; i < 11; i++) { for (int j = 0; j < 13; j++) { map[j, i] = '.'; } } var r = new Robot(); r.owner = 0; var x = 0; var y = 0; r.position = BitState.GetBitIndex(x, y); r.param1 = 1; r.param2 = 3; bots.Add(r); var bgs = new BitState(map, bots, bombs, 0); var best = BitSolution.generateBestRandomSolution(bgs, 0, 20, 90); //var move = new Move(MoveType.Move, MoveDirection.Stay); var move = best.moves[0]; bgs.getBot(0).getCommand(move); bgs.play(best, 0); bgs.score(0); Console.Error.WriteLine(timer.ElapsedMilliseconds); }
protected virtual void OnUserOutput4StateChanged(BitState newState) { if (UserOutput4StateChanged == null) { return; } UserOutput4StateChanged(this, new EventArgs <BitState>(newState)); }
protected virtual void OnShiftLightStateChanged(BitState newState) { if (ShiftLightStateChanged == null) { return; } ShiftLightStateChanged(this, new EventArgs <BitState>(newState)); }
protected virtual void OnRevLimitStateChanged(BitState newState) { if (RevLimitStateChanged == null) { return; } RevLimitStateChanged(this, new EventArgs <BitState>(newState)); }
public CircuitState(List <List <VarDef> > varDefs) { VariableValues = new Dictionary <string, BinaryVarValue>(varDefs.Count); foreach (var variables in varDefs) { var variable = variables[0]; BitState[] bits = new BitState[variable.Size]; Array.Fill(bits, BitState.Zero); VariableValues.Add(variable.ID, new BinaryVarValue(bits, variables, true)); } this.Time = 0; }
/// <summary> /// 写值方法-按位bit(单个) /// </summary> /// <param name="mr">地址类型枚举</param> /// <param name="ch">地址000.00</param> /// <param name="bs">开关状态枚举EtherNetPLC.BitState,0/1</param> /// <returns></returns> public short SetBitState(PlcMemory mr, string ch, BitState bs) { byte[] buffer = new byte[30]; short cnInt = short.Parse(ch.Split('.')[0]); short cnBit = short.Parse(ch.Split('.')[1]); byte[] arrayhead = FinsClass.FinsCmd(RorW.Write, mr, MemoryType.Bit, cnInt, cnBit, 1); byte[] array = new byte[35]; arrayhead.CopyTo(array, 0); array[34] = (byte)bs; if (BasicClass.SendData(array) == 0) { if (BasicClass.ReceiveData(buffer) == 0) { //命令返回成功,继续查询是否有错误码,然后在读取数据 bool succeed = true; if (buffer[11] == 3) { succeed = ErrorCode.CheckHeadError(buffer[15]); } if (succeed)//no header error { //endcode为fins指令的返回错误码 if (ErrorCode.CheckEndCode(buffer[28], buffer[29])) { //完全正确的返回0 return(0); } else { return(-1); } } else { return(-1); } } else { return(-1); } } else { return(-1); } }
internal static void VisitScalarValueChange(ReadOnlyMemory <byte> text, IDToVarDef idToVariable, SimPass pass, BitAllocator bitAlloc) { UnsafeMemory <BitState> bits = bitAlloc.GetBits(1); BitState bit = ToBitState(text.Span[0]); var id = text.Slice(1); bits.Span[0] = bit; if (idToVariable.TryGetValue(id, out List <VarDef>?variable)) { pass.BinValue = new BinaryVarValue(bits, variable, ((int)bit & 0b10) == 0); } else { throw new Exception($"Unknown variable identifier: {id}"); } }
public void Reset() { IgnitionAdvance = 0; Rpm = 0; Load = 0; IgnitionCell = new IgnitionCellIndex(byte.MaxValue, byte.MaxValue); IgnitionConfiguration = IgnitionConfiguration.Unknown; AuxiliaryInput = 0; AdvanceCorrectionBin = 0; AdvanceCorrection = 0; UserOutput1State = BitState.Inactive; UserOutput2State = BitState.Inactive; UserOutput3State = BitState.Inactive; UserOutput4State = BitState.Inactive; ShiftLightState = BitState.Inactive; RevLimitState = BitState.Inactive; }
internal void Populate(GetStateResponse response, EdisType edisType) { IgnitionAdvance = response.CurrentIgnitionAdvance; Rpm = response.GetCurrentRpmValue(edisType); Load = response.CurrentLoadValue; IgnitionCell = new IgnitionCellIndex(response.CurrentLoadBin, response.CurrentRpmBin); UserOutput1State = response.UserOutput1; UserOutput2State = response.UserOutput2; UserOutput3State = response.UserOutput3; UserOutput4State = response.UserOutput4; ShiftLightState = response.ShiftLightState; RevLimitState = response.RevLimitState; IgnitionConfiguration = response.IgnitionConfiguration; AuxiliaryInput = response.AuxiliaryInputValue; AdvanceCorrectionBin = response.CurrentAdvanceCorrectionBin; AdvanceCorrection = response.CurrentAdvanceCorrectionValue; }
internal static unsafe (UnsafeMemory <BitState> bits, bool isValidBinary) ToBitStates(ReadOnlySpan <byte> valueText, BitAllocator bitAlloc) { UnsafeMemory <BitState> bitsMem = bitAlloc.GetBits(valueText.Length); Span <BitState> bits = bitsMem.Span; ulong isValidBinary = 0; int index = 0; if (Ssse3.IsSupported && bits.Length >= Vector128 <byte> .Count) { int vecBitCount = bits.Length / Vector128 <byte> .Count; fixed(BitState *bitsPtr = bits) { fixed(byte *textPtr = valueText) { Vector128 <ulong> isValidBin = Vector128 <ulong> .Zero; for (; index < vecBitCount; index++) { var charText = Avx.LoadVector128(textPtr + index * Vector128 <byte> .Count); var byteText = Avx.Shuffle(charText, shuffleIdxs); var firstBit = Avx.And(onlyFirstBit, Avx.Or(byteText, Avx.ShiftRightLogical(byteText.AsInt32(), 1).AsByte())); var secondBit = Avx.And(onlySecondBit, Avx.ShiftRightLogical(byteText.AsInt32(), 5).AsByte()); var bytesAsBitStates = Avx.Or(firstBit, secondBit); Avx.Store((byte *)bitsPtr + bits.Length - (index + 1) * Vector128 <byte> .Count, bytesAsBitStates); isValidBin = Avx.Or(isValidBin, secondBit.AsUInt64()); } isValidBinary = isValidBin.GetElement(0) | isValidBin.GetElement(1); } } index *= Vector128 <byte> .Count; } for (; index < bits.Length; index++) { BitState bit = ToBitState(valueText[index]); bits[bits.Length - index - 1] = bit; isValidBinary |= (uint)bit & 0b10; } return(bitsMem, isValidBinary == 0); }
void OnMouseDown() { Debug.Log("OnMouseDown"); switch (State) { case BitState.Uncertainty: State = BitState.On; break; case BitState.On: State = BitState.Off; break; case BitState.Off: State = BitState.Uncertainty; break; default: throw new ArgumentOutOfRangeException(); } }
public void ParseVectorBinarySize22ValueChange() { BitState[] expectedBits = new BitState[] { BitState.One, BitState.One, BitState.Zero, BitState.Zero, BitState.Zero, BitState.One, BitState.Zero, BitState.Zero, BitState.Zero, BitState.One, BitState.Zero, BitState.One, BitState.One, BitState.Zero, BitState.Zero, BitState.One, BitState.Zero, BitState.One, BitState.One, BitState.One, BitState.Zero, BitState.One }; string vcdString = @$ " $var wire {expectedBits.Length} ! _T_4 $end $enddefinitions $end b{expectedBits.BitsToString()} !"; VCD vcd = Parse.FromString(vcdString); Assert.AreEqual(1, vcd.Declarations.Count); Assert.IsTrue(vcd.Declarations[0] is VarDef); var variable = vcd.Declarations[0] as VarDef; ISimCmd[] simCmds = vcd.GetSimulationCommands().ToArray(); Assert.AreEqual(1, simCmds.Length); Assert.IsTrue(simCmds[0] is BinaryVarValue); var valueChange = (BinaryVarValue)simCmds[0]; CollectionAssert.AreEqual(expectedBits, valueChange.Bits.ToArray()); Assert.AreEqual(variable, valueChange.Variables[0]); }
public bool SameValue(ref BinaryVarValue other, bool isSigned) { if (Bits.Length == other.Bits.Length) { return(SameValue(ref other)); } ReadOnlySpan <BitState> minL = Bits.Length < other.Bits.Length ? Bits : other.Bits; ReadOnlySpan <BitState> maxL = Bits.Length < other.Bits.Length ? other.Bits : Bits; if (minL.Length == 0) { for (int i = 0; i < maxL.Length; i++) { if (maxL[i] != BitState.Zero) { return(false); } } return(true); } BitState expectedRemainer = isSigned ? minL[^ 1] : BitState.Zero;
public Bit(BitState state) { _value = state == BitState.Zero ? 0 : 1; }
public void GetBitIndexTest_1_1_ReturnsNeg1() { Assert.AreEqual(-1, BitState.GetBitIndex(1, 1)); }
public void GetMapIndexTest_0_Returns0_0() { Assert.AreEqual(new Tuple <int, int>(0, 0), BitState.GetMapIndex(0)); }
public void GetMapIndexTest_112_Returns12_10() { Assert.AreEqual(new Tuple <int, int>(12, 10), BitState.GetMapIndex(112)); }
public void GetBitIndexTest_0_0_Returns0() { Assert.AreEqual(0, BitState.GetBitIndex(0, 0)); }
public void GetBitIndexTest_8_1_Returns17() { Assert.AreEqual(17, BitState.GetBitIndex(8, 1)); }
public static char ToChar(this BitState bit) { ReadOnlySpan <byte> bitAsChar = new byte[] { (byte)'0', (byte)'1', (byte)'X', (byte)'Z' }; return((char)bitAsChar[(int)bit & 0b11]);
public void GetBitIndexTest_12_10_Returns112() { Assert.AreEqual(112, BitState.GetBitIndex(12, 10)); }