/** * * calculateMatch() * Calculates the amount of black and white hits when comparing guess with c. * Returns a Match struct. * **/ private Match calculateMatch(ColorSequence guess, ColorSequence c) { int blackHits = 0; int whiteHits = 0; // compare for black hits for (int i = 0; i < DEPTH; i++) { blackVisited[i] = false; whiteVisited[i] = false; // compare the selected color with the code in same location to see if black hit if (guess[i] == c[i]) { blackHits++; blackVisited[i] = true; continue; } } // compare for white hits for (int i = 0; i < DEPTH; i++) { if (blackVisited[i]) continue; // if guess generated black hit, no need to see if it will be a white hit // compare with all other colors in code to see if white hit for (int j = 0; j < DEPTH; j++) { if (j == i) continue; // already checked these when looking for black hits above if (guess[j] != c[i] || blackVisited[j] || whiteVisited[j]) continue; whiteHits++; whiteVisited[j] = true; break; } } return new Match(blackHits, whiteHits); }
/// <summary> /// Send a command to the the display controller along with parameters. /// </summary> /// <param name="command">Command to send.</param> /// <param name="data">Span to send as parameters for the command.</param> private void SendCommand(Ssd1351Command command, Span <byte> data) { Span <byte> commandSpan = stackalloc byte[] { (byte)command }; SendSPI(commandSpan, true); if (data != null && data.Length > 0) { SendSPI(data); // detect certain commands that may alter the state of the device. This is done as the // SPI device cannot read registers from the ssd1351 and so changes need to be captured switch (command) { // capture changes to the colour depth and colour sequence case Ssd1351Command.SetRemap: _colorSequence = (ColorSequence)((data[0] >> 2) & 0x01); _colorDepth = (ColorDepth)((data[0] >> 6) & 0x03); break; } } }
}/*testCompareTo*/ private ColorSequence createDefinedColorCombo() { ColorSequence definedColorCombo = new ColorSequence(); definedColorCombo.addLast(Colors.Yellow); definedColorCombo.addLast(Colors.Green); definedColorCombo.addLast(Colors.Blue); definedColorCombo.addLast(Colors.Red); return definedColorCombo; }/*createDefinedColorCombo*/
} /*checkAnswerAndGiveFeedbackFor*/ private bool answerIsAllowed(ColorSequence guess) { for (byte i = 0; i < guess.Length; i++) for (byte j = 0; j < guess.Length; j++) if (i != j && guess.getColorOnPlace(i) == guess.getColorOnPlace(j)) return false; return true; } /*answerAllowed*/
} /*Randomizer*/ #endregion Properties #region Constructors public GameState(byte tries, byte pins, byte colors, bool computerIsPlaying, ColorSequence secretCombo = null) { NrOfTries = tries; NrOfPins = pins; NrOfAvailableColors = colors; ComputerIsPlaying = computerIsPlaying; TurnHistory = new List <ColorSequence>(); FeedbackHistory = new List <Feedback>(); TurnNumber = 1; SecretCombo = secretCombo ?? createSecretCombo(); } /*GameState*/
public static void WriteColorSequence(EndianAwareBinaryWriter writer, ColorSequence sequence) { writer.WriteInt32(sequence.Keypoints.Length); for (var i = 0; i < sequence.Keypoints.Length; i++) { writer.WriteSingle(sequence.Keypoints[i].Time); writer.WriteSingle(sequence.Keypoints[i].Value.R); writer.WriteSingle(sequence.Keypoints[i].Value.G); writer.WriteSingle(sequence.Keypoints[i].Value.B); } }
} /*Mastermind*/ #endregion constructors #region behavior internal Feedback checkAnswerAndGiveFeedbackFor(ColorSequence comboToCheck) { if (!answerIsAllowed(comboToCheck)) throw new ArgumentException(); Feedback fb = getSecretCombo().compareToColorsequence(comboToCheck); GameState.TurnHistory.Add(comboToCheck); GameState.FeedbackHistory.Add(fb); GameState.updateTurn(); return fb; } /*checkAnswerAndGiveFeedbackFor*/
// recursive approach is easiest way to populate possibilities (colors ^ slots = 8 ^ 5 = 32768) private void generatePossibilities(ColorSequence c, int n) { if (n == DEPTH) { current_set.Add(c); return; } for(int i = 0; i < COLORS; i++) { ColorSequence c2 = (ColorSequence)c.Clone(); c2[n] = (byte)(1 << i); generatePossibilities(c2, n + 1); } }
public void Save(TrailEffect effect) { active = effect.active; ignoreFrames = effect.ignoreFrames; duration = effect.duration; continuous = effect.continuous; smooth = effect.smooth; checkWorldPosition = effect.checkWorldPosition; minDistance = effect.minDistance; worldPositionRelativeOption = effect.worldPositionRelativeOption; worldPositionRelativeTransform = effect.worldPositionRelativeTransform; checkScreenPosition = effect.checkScreenPosition; minPixelDistance = effect.minPixelDistance; maxStepsPerFrame = effect.maxStepsPerFrame; checkTime = effect.checkTime; timeInterval = effect.timeInterval; checkCollisions = effect.checkCollisions; orientToSurface = effect.orientToSurface; ground = effect.ground; surfaceOffset = effect.surfaceOffset; collisionLayerMask = effect.collisionLayerMask; drawBehind = effect.drawBehind; cullMode = effect.cullMode; subMeshMask = effect.subMeshMask; colorOverTime = effect.colorOverTime; color = effect.color; colorSequence = effect.colorSequence; colorCycleDuration = effect.colorCycleDuration; colorStartPalette = effect.colorStartPalette; pingPongSpeed = effect.pingPongSpeed; this.effect = effect.effect; texture = effect.texture; scale = effect.scale; scaleStartRandomMin = effect.scaleStartRandomMin; scaleStartRandomMax = effect.scaleStartRandomMax; scaleOverTime = effect.scaleOverTime; scaleUniform = effect.scaleUniform; localPositionRandomMin = effect.localPositionRandomMin; localPositionRandomMax = effect.localPositionRandomMax; laserBandWidth = effect.laserBandWidth; laserIntensity = effect.laserIntensity; laserFlash = effect.laserFlash; lookTarget = effect.lookTarget; lookToCamera = effect.lookToCamera; textureCutOff = effect.textureCutOff; normalThreshold = effect.normalThreshold; useLastAnimationState = effect.useLastAnimationState; maxBatches = effect.maxBatches; meshPoolSize = effect.meshPoolSize; animationStates = effect.animationStates; }
// -------------------------------------------------- // UI message handlers public void OnClickToConnect() { LastUsername = StateFluxClient.Instance.userName = GetLoginUsername(); StateFluxClient.Instance.requestedPlayerColor = ColorSequence.Next(); if (String.IsNullOrWhiteSpace(LastUsername)) { DebugLog($"LobbyManager.OnClickToConnect no username!"); } else { DebugLog($"LobbyManager.OnClickToConnect as {LastUsername}"); StateFluxClient.Instance.Login(); } }
} /*updateTurn*/ private ColorSequence createRandomSequence(byte length) { ColorSequence randomCombo = new ColorSequence(); bool[] used = new bool[NrOfAvailableColors]; for (byte i = 0; i < length; i++) { int tmp; do { tmp = Randomizer.Next(NrOfAvailableColors); } while (used[tmp]); randomCombo.addLast((Colors)tmp); used[tmp] = true; } return randomCombo; } /*createRandomSequence*/
public Player CreatePlayerSession(string playerName) { Player player = new Player { Name = playerName, Id = ShortGuid.Generate(), SessionData = new PlayerSessionData { SessionId = ShortGuid.Generate(), WebsocketSessionId = this.ID }, Color = ColorSequence.Next() }; Server.Instance.playerRepository.InsertPlayer(player); Server.Instance.Players.Add(player); LogMessage($"Created player {player.Name} with session '{player.SessionData.SessionId}'. Added to players & saved to database"); return(player); }
public void Save(BinaryRobloxFileWriter writer) { BinaryRobloxFile file = writer.File; File = file; INST inst = file.Classes[ClassIndex]; var props = new List <Property>(); foreach (int instId in inst.InstanceIds) { Instance instance = file.Instances[instId]; var instProps = instance.Properties; if (!instProps.TryGetValue(Name, out Property prop)) { throw new Exception($"Property {Name} must be defined in {instance.GetFullName()}!"); } else if (prop.Type != Type) { throw new Exception($"Property {Name} is not using the correct type in {instance.GetFullName()}!"); } props.Add(prop); } writer.Write(ClassIndex); writer.WriteString(Name); writer.Write(TypeId); switch (Type) { case PropertyType.String: props.ForEach(prop => { byte[] buffer = prop.HasRawBuffer ? prop.RawBuffer : null; if (buffer == null) { string value = prop.CastValue <string>(); buffer = Encoding.UTF8.GetBytes(value); } writer.Write(buffer.Length); writer.Write(buffer); }); break; case PropertyType.Bool: { props.ForEach(prop => { bool value = prop.CastValue <bool>(); writer.Write(value); }); break; } case PropertyType.Int: { var ints = props .Select(prop => prop.CastValue <int>()) .ToList(); writer.WriteInts(ints); break; } case PropertyType.Float: { var floats = props .Select(prop => prop.CastValue <float>()) .ToList(); writer.WriteFloats(floats); break; } case PropertyType.Double: { props.ForEach(prop => { double value = prop.CastValue <double>(); writer.Write(BinaryRobloxFileWriter.GetBytes(value)); }); break; } case PropertyType.UDim: { var UDim_Scales = new List <float>(); var UDim_Offsets = new List <int>(); props.ForEach(prop => { UDim value = prop.CastValue <UDim>(); UDim_Scales.Add(value.Scale); UDim_Offsets.Add(value.Offset); }); writer.WriteFloats(UDim_Scales); writer.WriteInts(UDim_Offsets); break; } case PropertyType.UDim2: { var UDim2_Scales_X = new List <float>(); var UDim2_Scales_Y = new List <float>(); var UDim2_Offsets_X = new List <int>(); var UDim2_Offsets_Y = new List <int>(); props.ForEach(prop => { UDim2 value = prop.CastValue <UDim2>(); UDim2_Scales_X.Add(value.X.Scale); UDim2_Scales_Y.Add(value.Y.Scale); UDim2_Offsets_X.Add(value.X.Offset); UDim2_Offsets_Y.Add(value.Y.Offset); }); writer.WriteFloats(UDim2_Scales_X); writer.WriteFloats(UDim2_Scales_Y); writer.WriteInts(UDim2_Offsets_X); writer.WriteInts(UDim2_Offsets_Y); break; } case PropertyType.Ray: { props.ForEach(prop => { Ray ray = prop.CastValue <Ray>(); Vector3 pos = ray.Origin; writer.Write(pos.X); writer.Write(pos.Y); writer.Write(pos.Z); Vector3 dir = ray.Direction; writer.Write(dir.X); writer.Write(dir.Y); writer.Write(dir.Z); }); break; } case PropertyType.Faces: case PropertyType.Axes: { props.ForEach(prop => { byte value = prop.CastValue <byte>(); writer.Write(value); }); break; } case PropertyType.BrickColor: { var brickColorIds = props .Select(prop => prop.CastValue <BrickColor>()) .Select(value => value.Number) .ToList(); writer.WriteInts(brickColorIds); break; } case PropertyType.Color3: { var Color3_R = new List <float>(); var Color3_G = new List <float>(); var Color3_B = new List <float>(); props.ForEach(prop => { Color3 value = prop.CastValue <Color3>(); Color3_R.Add(value.R); Color3_G.Add(value.G); Color3_B.Add(value.B); }); writer.WriteFloats(Color3_R); writer.WriteFloats(Color3_G); writer.WriteFloats(Color3_B); break; } case PropertyType.Vector2: { var Vector2_X = new List <float>(); var Vector2_Y = new List <float>(); props.ForEach(prop => { Vector2 value = prop.CastValue <Vector2>(); Vector2_X.Add(value.X); Vector2_Y.Add(value.Y); }); writer.WriteFloats(Vector2_X); writer.WriteFloats(Vector2_Y); break; } case PropertyType.Vector3: { var Vector3_X = new List <float>(); var Vector3_Y = new List <float>(); var Vector3_Z = new List <float>(); props.ForEach(prop => { Vector3 value = prop.CastValue <Vector3>(); Vector3_X.Add(value.X); Vector3_Y.Add(value.Y); Vector3_Z.Add(value.Z); }); writer.WriteFloats(Vector3_X); writer.WriteFloats(Vector3_Y); writer.WriteFloats(Vector3_Z); break; } case PropertyType.CFrame: case PropertyType.Quaternion: case PropertyType.OptionalCFrame: { var CFrame_X = new List <float>(); var CFrame_Y = new List <float>(); var CFrame_Z = new List <float>(); if (Type == PropertyType.OptionalCFrame) { writer.Write((byte)PropertyType.CFrame); } props.ForEach(prop => { CFrame value = null; if (prop.Value is Quaternion q) { value = q.ToCFrame(); } else { value = prop.CastValue <CFrame>(); } if (value == null) { value = new CFrame(); } Vector3 pos = value.Position; CFrame_X.Add(pos.X); CFrame_Y.Add(pos.Y); CFrame_Z.Add(pos.Z); int orientId = value.GetOrientId(); writer.Write((byte)(orientId + 1)); if (orientId == -1) { if (Type == PropertyType.Quaternion) { Quaternion quat = new Quaternion(value); writer.Write(quat.X); writer.Write(quat.Y); writer.Write(quat.Z); writer.Write(quat.W); } else { float[] components = value.GetComponents(); for (int i = 3; i < 12; i++) { float component = components[i]; writer.Write(component); } } } }); writer.WriteFloats(CFrame_X); writer.WriteFloats(CFrame_Y); writer.WriteFloats(CFrame_Z); if (Type == PropertyType.OptionalCFrame) { writer.Write((byte)PropertyType.Bool); props.ForEach(prop => { if (prop.Value is null) { writer.Write(false); return; } if (prop.Value is Optional <CFrame> optional) { writer.Write(optional.HasValue); return; } var cf = prop.Value as CFrame; writer.Write(cf != null); }); } break; } case PropertyType.Enum: { var enums = new List <uint>(); props.ForEach(prop => { if (prop.Value is uint raw) { enums.Add(raw); return; } int signed = (int)prop.Value; uint value = (uint)signed; enums.Add(value); }); writer.WriteInterleaved(enums); break; } case PropertyType.Ref: { var InstanceIds = new List <int>(); props.ForEach(prop => { int referent = -1; if (prop.Value != null) { Instance value = prop.CastValue <Instance>(); if (value.IsDescendantOf(File)) { string refValue = value.Referent; int.TryParse(refValue, out referent); } } InstanceIds.Add(referent); }); writer.WriteInstanceIds(InstanceIds); break; } case PropertyType.Vector3int16: { props.ForEach(prop => { Vector3int16 value = prop.CastValue <Vector3int16>(); writer.Write(value.X); writer.Write(value.Y); writer.Write(value.Z); }); break; } case PropertyType.NumberSequence: { props.ForEach(prop => { NumberSequence value = prop.CastValue <NumberSequence>(); var keyPoints = value.Keypoints; writer.Write(keyPoints.Length); foreach (var keyPoint in keyPoints) { writer.Write(keyPoint.Time); writer.Write(keyPoint.Value); writer.Write(keyPoint.Envelope); } }); break; } case PropertyType.ColorSequence: { props.ForEach(prop => { ColorSequence value = prop.CastValue <ColorSequence>(); var keyPoints = value.Keypoints; writer.Write(keyPoints.Length); foreach (var keyPoint in keyPoints) { Color3 color = keyPoint.Value; writer.Write(keyPoint.Time); writer.Write(color.R); writer.Write(color.G); writer.Write(color.B); writer.Write(keyPoint.Envelope); } }); break; } case PropertyType.NumberRange: { props.ForEach(prop => { NumberRange value = prop.CastValue <NumberRange>(); writer.Write(value.Min); writer.Write(value.Max); }); break; } case PropertyType.Rect: { var Rect_X0 = new List <float>(); var Rect_Y0 = new List <float>(); var Rect_X1 = new List <float>(); var Rect_Y1 = new List <float>(); props.ForEach(prop => { Rect value = prop.CastValue <Rect>(); Vector2 min = value.Min; Rect_X0.Add(min.X); Rect_Y0.Add(min.Y); Vector2 max = value.Max; Rect_X1.Add(max.X); Rect_Y1.Add(max.Y); }); writer.WriteFloats(Rect_X0); writer.WriteFloats(Rect_Y0); writer.WriteFloats(Rect_X1); writer.WriteFloats(Rect_Y1); break; } case PropertyType.PhysicalProperties: { props.ForEach(prop => { bool custom = (prop.Value != null); writer.Write(custom); if (custom) { PhysicalProperties value = prop.CastValue <PhysicalProperties>(); writer.Write(value.Density); writer.Write(value.Friction); writer.Write(value.Elasticity); writer.Write(value.FrictionWeight); writer.Write(value.ElasticityWeight); } }); break; } case PropertyType.Color3uint8: { var Color3uint8_R = new List <byte>(); var Color3uint8_G = new List <byte>(); var Color3uint8_B = new List <byte>(); props.ForEach(prop => { Color3uint8 value = prop.CastValue <Color3uint8>(); Color3uint8_R.Add(value.R); Color3uint8_G.Add(value.G); Color3uint8_B.Add(value.B); }); byte[] rBuffer = Color3uint8_R.ToArray(); writer.Write(rBuffer); byte[] gBuffer = Color3uint8_G.ToArray(); writer.Write(gBuffer); byte[] bBuffer = Color3uint8_B.ToArray(); writer.Write(bBuffer); break; } case PropertyType.Int64: { var longs = new List <long>(); props.ForEach(prop => { long value = prop.CastValue <long>(); longs.Add(value); }); writer.WriteInterleaved(longs, value => { // Move the sign bit to the front. return((value << 1) ^ (value >> 63)); }); break; } case PropertyType.SharedString: { var sharedKeys = new List <uint>(); SSTR sstr = file.SSTR; if (sstr == null) { sstr = new SSTR(); file.SSTR = sstr; } props.ForEach(prop => { var shared = prop.CastValue <SharedString>(); if (shared == null) { byte[] empty = Array.Empty <byte>(); shared = SharedString.FromBuffer(empty); } string key = shared.Key; if (!sstr.Lookup.ContainsKey(key)) { uint id = (uint)sstr.Lookup.Count; sstr.Strings.Add(id, shared); sstr.Lookup.Add(key, id); } uint hashId = sstr.Lookup[key]; sharedKeys.Add(hashId); }); writer.WriteInterleaved(sharedKeys); break; } case PropertyType.ProtectedString: { props.ForEach(prop => { var protect = prop.CastValue <ProtectedString>(); byte[] buffer = protect.RawBuffer; writer.Write(buffer.Length); writer.Write(buffer); }); break; } case PropertyType.UniqueId: { props.ForEach(prop => { var guid = prop.CastValue <Guid>(); byte[] buffer = guid.ToByteArray(); writer.Write(buffer); }); break; } default: { RobloxFile.LogError($"Unhandled property type: {Type} in {this}!"); break; } } }
} /*MSolver*/ #endregion Properties #region constructors public Mastermind(byte tries, byte pins, byte colors, bool computerIsPlaying, ColorSequence secretCombo) : this(new GameState(tries, pins, colors, computerIsPlaying, secretCombo)) { }
/** * Shows the AI's guess on the screen, with the appropriate pegs for the match it received. * The bool return value signifies whether game is over or not, which is handled by play(), this function's caller. */ private bool showOnGui(ColorSequence guess, Match m) { int x; // show the guess on the screen for (x = 0; x < DEPTH; x++) { mastermind.holes[x, mastermind.activeRow].Image = mastermind.images[log2(guess[x])]; } // show appropriate pins for the match x = 0; for (int i = 0; i < m.blackHits; i++) mastermind.pegs[x++, mastermind.activeRow - 1].Image = mastermind.blackPegImage; for (int i = 0; i < m.whiteHits; i++) mastermind.pegs[x++, mastermind.activeRow - 1].Image = mastermind.whitePegImage; for (; x < DEPTH; x++) mastermind.pegs[x, mastermind.activeRow - 1].Image = mastermind.emptyPegImage; for (x = 0; x < DEPTH; x++) mastermind.pegs[x, mastermind.activeRow - 1].Visible = true; mastermind.Refresh(); // check for game end conditions if (m.blackHits == DEPTH) { cleanUp(); TimeSpan ts = stopWatch.Elapsed; MessageBox.Show("The AI cracked the code in " + ( 9 - mastermind.activeRow) + " attempts! Processing took " + ts.Minutes + ":" + ts.Seconds + "." + ts.Milliseconds, "Computer wins!", MessageBoxButtons.OK, MessageBoxIcon.Information); return true; } else { mastermind.progressBar.Location = new Point(mastermind.progressBar.Location.X, mastermind.progressBar.Location.Y - 55); mastermind.lblPossibilities.Location = new Point(mastermind.lblPossibilities.Location.X, mastermind.lblPossibilities.Location.Y - 55); if (--mastermind.activeRow == 0) // ran out of attempts, they lose { cleanUp(); TimeSpan ts = stopWatch.Elapsed; MessageBox.Show("The AI failed to crack the code in 8 attempts. Bad luck!Processing took " + ts.Minutes + ":" + ts.Seconds + "." + ts.Milliseconds, "Computer loses!", MessageBoxButtons.OK, MessageBoxIcon.Information); return true; } } return false; }
// play the game! private void play() { // convert GUI representation of code to AI representation of code byte[] seq = new byte[5]; for(int i = 0; i < DEPTH; i++) { seq[i] = (byte)(1 << mastermind.code[i]); } ColorSequence code = new ColorSequence(seq); // first guess is always the same because it is proven to be best in worst-case byte[] firstGuess = {1,1,2,4,8}; ColorSequence guess = new ColorSequence(firstGuess); Match m = calculateMatch(code, guess); if (showOnGui(guess, m)) return; current_set = restrictSet(guess, m.whiteHits, m.blackHits); for (int i = 1; i <= 8; i++) { mastermind.lblPossibilities.Text = "Possibilities: " + current_set.Count; mastermind.progressBar.Maximum = current_set.Count; mastermind.progressBar.Value = 0; Possibility bestPossibility = new Possibility(int.MaxValue, null, 0, 0); foreach (ColorSequence possibility in current_set) { Possibility profile = profilePossibility(possibility, bestPossibility); if (profile.worstCaseSetCount < bestPossibility.worstCaseSetCount) // found a better possibility { bestPossibility = profile; } //Console.WriteLine(bestPossibility.ToString()); mastermind.progressBar.Value += 1; Application.DoEvents(); } //Console.WriteLine(bestPossibility); m = calculateMatch(code, bestPossibility.sequence); if (showOnGui(bestPossibility.sequence, m)) return; current_set = restrictSet(bestPossibility.sequence, m.whiteHits, m.blackHits); } }
private int calculatePossibilitiesLeftAfterAssumedResponse(ColorSequence c, int w, int b, int currentBest) { int count = 0; foreach (ColorSequence possibility in current_set) { Match m = calculateMatch(possibility, c); if (m.blackHits == b && m.whiteHits == w) count++; if (count >= currentBest) // already worse than best, so just return now return count; } return count; }
/** * profilePossibility * This takes a ColorSequence and profiles the possibility. * This means that it calculates the worst-case scenario, where guessing this possibility leads to the largest number of remaining possible sequences. */ private Possibility profilePossibility(ColorSequence possibility, Possibility bestPossibility) { int maxPossibilities = 0; int maxW = 0; int maxB = 0; for (int w = 0; w <= 5; w++) { for (int b = 0; b <= 5; b++) { if (w + b > 5) continue; // skip the white/black combination if it's not possible int possibilitiesRemaining = calculatePossibilitiesLeftAfterAssumedResponse(possibility, w, b, bestPossibility.worstCaseSetCount); if (possibilitiesRemaining >= bestPossibility.worstCaseSetCount) { // aready worse than best possibility's count, so no point in continuing return new Possibility(possibilitiesRemaining, possibility, w, b); } if (possibilitiesRemaining > maxPossibilities) { maxPossibilities = possibilitiesRemaining; maxW = w; maxB = b; } } } return new Possibility(maxPossibilities, possibility, maxW, maxB); }
/** * restricts current_set to only those sequences which would hold true if the guess "c" * returns w white hits and b black hits. * Returns a new set containing these, which is promptly discarded if it doesn't minimize possibilities. */ private HashSet<ColorSequence> restrictSet(ColorSequence c, int w, int b) { HashSet<ColorSequence> new_set = new HashSet<ColorSequence>(csc); foreach(ColorSequence possibility in current_set) { Match m = calculateMatch(possibility, c); if (m.blackHits == b && m.whiteHits == w) new_set.Add(possibility); } return new_set; }
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node) { ColorSequence value = prop.CastValue <ColorSequence>(); node.InnerText = value.ToString() + ' '; }
/// <summary> /// This command changes the mapping between the display data column address and the segment driver. /// It allows flexibility in OLED module design. This command only affects subsequent data input. /// Data already stored in GDDRAM will have no changes. /// </summary> /// <param name="colorDepth">Number of colors displayed. (defaults to 0x65K)</param> /// <param name="commonSplit">Defines if to split commons odd then even columns. (defaults to odd/even)</param> /// <param name="seg0Common">Column address 0 is mapped to SEG0 when set to Column0. Column address 127 is mapped to SEG0 when set to Column127. (defaults to Segment0 = Column0)</param> /// <param name="colorSequence">Colors are ordered R->G->B when set to RGB. Colors are ordered B->G->A when set to BGR. (defaults to BGR)</param> public void SetSegmentReMapColorDepth(ColorDepth colorDepth = ColorDepth.ColourDepth65K, CommonSplit commonSplit = CommonSplit.OddEven, Seg0Common seg0Common = Seg0Common.Column0, ColorSequence colorSequence = ColorSequence.BGR) { if (colorDepth == ColorDepth.ColourDepth262K16Bit) { throw new ArgumentException("Color depth 262k format 2 is not supported via the SPI interface.", nameof(colorDepth)); } if (colorDepth == ColorDepth.ColourDepth256) { throw new ArgumentException("Color depth 256 not supported.", nameof(colorDepth)); } SendCommand(Ssd1351Command.SetRemap, (byte)(((int)colorDepth << 6) + ((int)commonSplit << 5) + ((int)seg0Common << 4) + ((int)colorSequence << 2))); }
public void btnGuess_Click(object sender, EventArgs e) { if (!Mastermind.gameIsOver()) { try { ColorSequence guess = new ColorSequence(); for (int i = 0; i < Mastermind.GameState.NrOfPins; i++) guess.addLast( ClrPicker.parseEnum <Colors>( CtrlController.LblArrayPlayer[Mastermind.GameState.TurnNumber - 1, i].BackColor.ToKnownColor().ToString())); passGuessAndGetFeedback(guess); } catch (ArgumentException) { MessageBox.Show( string.Format("Every pin must have a color and a color can't be used twice..."), string.Format("Error")); } } } /*btnGuess_Click*/
} /*showOptions*/ private void passGuessAndGetFeedback(ColorSequence guess) { Feedback feedback = Mastermind.checkAnswerAndGiveFeedbackFor(guess); int tmp = 0; for (byte j = 0; j < feedback.CorrectPositionAndColor; j++) { CtrlController.LblArrayFeedBackPins[Mastermind.GameState.TurnNumber - 2, tmp].BackColor = Color.Black; tmp++; } for (byte j = 0; j < feedback.CorrectColor; j++) { CtrlController.LblArrayFeedBackPins[Mastermind.GameState.TurnNumber - 2, tmp].BackColor = Color.White; tmp++; } if (Mastermind.gameIsOver()) { MessageBox.Show(Mastermind.GameState.Won ? "Won" : "Lost"); CtrlController.unvealSecret(); } else { if (CtrlController.BtnGuess != null) CtrlController.BtnGuess.Top += 50; pnlPlace.ScrollControlIntoView(CtrlController.LblArrayPlayer[Mastermind.GameState.TurnNumber - 1, 0]); CtrlController.highlightAccesiblePlayerLabels(); } } /*passGuessAndGetFeedback*/