public void TestFindDuplicatesInColumn() { // Arrange string[] inputStringArray = new string[NumberOfSudokuFields]; // Add duplicates to string array: inputStringArray[0] = "5"; // Sector 1 / Row 1 / Column 1 inputStringArray[27] = "5"; // Sector 4 / Row 4 / Column 1 inputStringArray[54] = "5"; // Sector 7 / Row 7 / Column 1 inputStringArray[14] = "7"; // Sector 2 / Row 2 / Column 6 inputStringArray[41] = "7"; // Sector 5 / Row 5 / Column 6 inputStringArray[68] = "7"; // Sector 8 / Row 8 / Column 6 inputStringArray[47] = "7"; // Sector 4 / Row 6 / Column 3 -> not a duplicate FieldColor expectedResultDuplicate = FieldColor.Red; // Duplicates are marked red FieldColor expectedResultNoDuplicate = FieldColor.Black; // Non-duplicates remain black // Act var result = this.testee.GetFieldColorArray(inputStringArray); // Assert Assert.AreEqual(expectedResultDuplicate, result[0]); Assert.AreEqual(expectedResultDuplicate, result[27]); Assert.AreEqual(expectedResultDuplicate, result[54]); Assert.AreEqual(expectedResultDuplicate, result[14]); Assert.AreEqual(expectedResultDuplicate, result[14]); Assert.AreEqual(expectedResultDuplicate, result[68]); Assert.AreEqual(expectedResultNoDuplicate, result[47]); }
public void TestFindDuplicatesInSector() { // Arrange string[] inputStringArray = new string[NumberOfSudokuFields]; // Add duplicates to string array: inputStringArray[0] = "5"; // Sector 1 / Row 1 / Column 1 inputStringArray[10] = "5"; // Sector 1 / Row 2 / Column 2 inputStringArray[60] = "7"; // Sector 9 / Row 7 / Column 7 inputStringArray[70] = "7"; // Sector 9 / Row 8 / Column 8 inputStringArray[50] = "7"; // Sector 5 / Row 6 / Column 6 -> not a duplicate FieldColor expectedResultDuplicate = FieldColor.Red; // Duplicates are marked red FieldColor expectedResultNoDuplicate = FieldColor.Black; // Non-duplicates remain black // Act var result = this.testee.GetFieldColorArray(inputStringArray); // Assert Assert.AreEqual(expectedResultDuplicate, result[0]); Assert.AreEqual(expectedResultDuplicate, result[10]); Assert.AreEqual(expectedResultDuplicate, result[60]); Assert.AreEqual(expectedResultDuplicate, result[70]); Assert.AreEqual(expectedResultNoDuplicate, result[50]); }
public StrategyPlayer(FieldColor playerColor, double offensiveFactor, double defensiveFactor, bool withComputer = true) : base(playerColor) { this.OffensiveFactor = offensiveFactor; this.DefensiveFactor = defensiveFactor; this.random = new Random(); this.withComputer = withComputer; }
public void FieldFactory_CreateFields_FieldColorsAreCorrect(int fieldNumber, FieldColor color) { var list = new StandardFieldFactory().CreateFields(); var index = list.FindIndex(field => field.Number == fieldNumber); Assert.That(list[index].Color, Is.EqualTo(color)); }
public Field(FieldColor fColor) { theFieldColor = fColor; CardLimit = 3; _Cards = new List <Card> { }; }
private bool CheckIfPlayerWon(int playerId) { FieldColor playerColor = Players[playerId].Color; IEnumerable <Field> playerFields = Board.GetFieldsByColor(playerColor); foreach (List <Field> playerWinningAP in playerAPPossibilities[playerId]) { bool apMatched = true; foreach (Field field in playerWinningAP) { if (!playerFields.Any(f => f.Value == field.Value)) { apMatched = false; break; } } if (apMatched) { winningAP = playerWinningAP; return(true); } } return(false); }
public RequiredField(FieldColor _color = FieldColor.Red) { switch (_color) { case FieldColor.Red: color = Color.red; break; case FieldColor.Green: color = Color.green; break; case FieldColor.Blue: color = Color.blue; break; case FieldColor.Yellow: color = Color.yellow; break; default: color = Color.red; break; } }
public void SetFieldColor(FieldColor color, int fieldValue) { if (color == FieldColor.White) { throw new ArgumentException(); } fields.First(f => f.Value == fieldValue).FieldColor = color; }
private FieldColor[] MakeAllFieldsGreen() { FieldColor[] fieldColorArray = new FieldColor[NumberOfSudokuFields]; for (int i = 0; i < fieldColorArray.Length; i++) { fieldColorArray[i] = FieldColor.Green; } return(fieldColorArray); }
public override void Generate() { for (int i = 0; i < this.slotCount; ++i) { ProgramAction action = this.GenerateRandomAction(); FieldColor color = this.GenerateRandomColor(); this.program[i].Action = action; this.program[i].Color = color; } }
public static bool HasDefaultNameOrNull(this FieldColor fieldColor) { if (fieldColor is null) { ErrorDetected($"Error in {nameof(IsDefaultOrNull)}: target {fieldColor}", ReasonType.NullError); return(true); } return(string.IsNullOrEmpty(fieldColor.Name)); }
public void TestFindDuplicatesInRow() { /* * -------------------------------- | SUDOKU ARRAY GRID | | -------------------------------- | R=Row / C=Column / S=Sector | |C1 C2 C3 C4 C5 C6 C7 C8 C9| |S1--------S2--------S3------| | R1| 0 1 2 | 3 4 5 | 6 7 8| | R2| 9 10 11 |12 13 14 |15 16 17| | R3|18 19 20 |21 22 23 |24 25 26| |S4-------|S5-------|S6------| | R4|27 28 29 |30 31 32 |33 34 35| | R5|36 37 38 |39 40 41 |42 43 44| | R6|45 46 47 |48 49 50 |51 52 53| |S7-------|S8-------|S9------| | R7|54 55 56 |57 58 59 |60 61 62| | R8|63 64 65 |66 67 68 |69 70 71| | R9|72 73 74 |75 76 77 |78 79 80| |----------------------------| | */ // Arrange string[] inputStringArray = new string[NumberOfSudokuFields]; // Add duplicates to string array: inputStringArray[0] = "5"; // Sector 1 / Row 1 / Column 1 inputStringArray[3] = "5"; // Sector 2 / Row 1 / Column 4 inputStringArray[6] = "5"; // Sector 3 / Row 1 / Column 7 inputStringArray[64] = "7"; // Sector 7 / Row 8 / Column 2 inputStringArray[67] = "7"; // Sector 8 / Row 8 / Column 5 inputStringArray[70] = "7"; // Sector 9 / Row 8 / Column 8 inputStringArray[38] = "7"; // Sector 4 / Row 5 / Column 3 -> not a duplicate FieldColor expectedResultDuplicate = FieldColor.Red; // Duplicates are marked red FieldColor expectedResultNoDuplicate = FieldColor.Black; // Non-duplicates remain black // Act var result = this.testee.GetFieldColorArray(inputStringArray); // Assert Assert.AreEqual(expectedResultDuplicate, result[0]); Assert.AreEqual(expectedResultDuplicate, result[3]); Assert.AreEqual(expectedResultDuplicate, result[6]); Assert.AreEqual(expectedResultDuplicate, result[64]); Assert.AreEqual(expectedResultDuplicate, result[67]); Assert.AreEqual(expectedResultDuplicate, result[70]); Assert.AreEqual(expectedResultNoDuplicate, result[38]); }
private FieldColor[] MakeDuplicatesRed(int[] sudokuIntArray) { FieldColor[] fieldColorArray = new FieldColor[NumberOfSudokuFields]; bool[] duplicateArray = GetDuplicatesArray(sudokuIntArray); for (int i = 0; i < duplicateArray.Length; i++) { fieldColorArray[i] = duplicateArray[i] ? FieldColor.Red : FieldColor.Black; } return(fieldColorArray); }
public static bool HasDefaultColorOrNull(this FieldColor fieldColor, bool checkForDefaultFieldColor = true) { if (fieldColor is null) { ErrorDetected($"Error in {nameof(IsDefaultOrNull)}: target {fieldColor}", ReasonType.NullError); return(true); } return(fieldColor.Value == default(Xamarin.Forms.Color) || (checkForDefaultFieldColor && fieldColor.Value == DefaultColor)); }
public static bool IsDefaultOrNull(this FieldColor fieldColor, bool checkForDefaultFieldColor = true) { if (fieldColor is null) { ErrorDetected($"Error in {nameof(IsDefaultOrNull)}: target {fieldColor}", ReasonType.NullError); return(true); } return(string.IsNullOrEmpty(fieldColor.Name) && fieldColor.Value == default(Xamarin.Forms.Color) && (!checkForDefaultFieldColor || fieldColor.Value == DefaultColor)); }
public RequiredField(FieldColor _color = FieldColor.Red) { color = _color switch { FieldColor.Red => Color.red, FieldColor.Green => Color.green, FieldColor.Blue => Color.blue, FieldColor.Yellow => Color.yellow, _ => Color.red }; } }
// Constructor public Field(uint number, FieldColor color) { Number = number; Color = color; if (number == 0) { Parity = Parity.Neither; } else { Parity = (number % 2 == 0 ? Parity.Even : Parity.Odd); } }
public void SetColor(Coord coord, FieldColor color) { FieldColor oldColor = colors[coord.X, coord.Y]; colors[coord.X, coord.Y] = color; EventHandler <FieldColorChangedEventArgs> handler = this.FieldColorChanged; if (handler != null) { handler(this, new FieldColorChangedEventArgs(oldColor, color, coord)); } }
public override void Mutate() { bool mutateColor = random.Next(2) == 0; int randomPos = random.Next(this.slotCount); if (mutateColor) { FieldColor color = GenerateRandomColor(); this.program[randomPos].Color = color; } else { ProgramAction action = this.GenerateRandomAction(); this.program[randomPos].Action = action; } }
public static void HandlePropertyChanging(object oldValue, object newValue, string propertyName, bool isWeak = false) { if (isWeak) { return; } if (oldValue == newValue) { return; } if (propertyName == nameof(XamlHelper <TValue> .Name)) { var name = (newValue as string); if (name == null) { ErrorDetected($"Error in {nameof(HandlePropertyChanging)} of {nameof(XamlHelper<TValue>.Name)}: {nameof(newValue)}", ReasonType.NullError); return; } if (string.IsNullOrWhiteSpace(name)) { return; } // FieldColor handling implementation FieldColor.HandleFieldColorBuffer(name, true); } else if (propertyName == nameof(XamlHelper <TValue> .Value)) { var value = (newValue as TValue?); if (value == null) { ErrorDetected($"Error in {nameof(HandlePropertyChanging)} of {nameof(XamlHelper<TValue>.Value)}: {nameof(newValue)}", ReasonType.NullError); return; } if (!DefaultValueList.TrueForAll((item) => !item.Equals(value))) { return; } // FieldColor handling implementation FieldColor.HandleFieldColorBuffer(value, false); } }
public static Player GetPlayerByStrategy(Strategy strategy, FieldColor color, bool withComputer = true) { switch (strategy) { case Strategy.RandomStrategy: return(new RandomBot(color, withComputer)); case Strategy.OffensiveStrategy: return(new StrategyPlayer(color, 0.75, 0.25, withComputer)); case Strategy.DefensiveStratgy: return(new StrategyPlayer(color, 0.25, 0.75, withComputer)); case Strategy.BalancedStrategy: return(new StrategyPlayer(color, 0.5, 0.5, withComputer)); default: return(null); } }
public RequiredFieldAttribute(FieldColor Fieldcolor = FieldColor.Red) { switch (Fieldcolor) { case FieldColor.Red: color = Color.red; break; case FieldColor.Green: color = Color.green; break; case FieldColor.Blue: color = Color.blue; break; case FieldColor.Magenta: color = Color.magenta; break; case FieldColor.Cyan: color = Color.cyan; break; case FieldColor.Yellow: color = Color.yellow; break; case FieldColor.Orange: color = new Color(1, 0.5f, 0); break; case FieldColor.Gray: color = Color.gray; break; default: color = Color.red; break; } }
public void SetFieldColor(FieldColor fieldColor) { SolidColorBrush fieldSolidColorBrush = new SolidColorBrush(Colors.Bisque); switch (fieldColor) { case FieldColor.Standard: fieldSolidColorBrush = (Row + Column) % 2 == 0 ? new SolidColorBrush(Colors.SandyBrown) : new SolidColorBrush(Colors.Bisque); break; case FieldColor.Start: fieldSolidColorBrush = new SolidColorBrush(Colors.LightGreen); break; case FieldColor.End: fieldSolidColorBrush = new SolidColorBrush(Colors.LightPink); break; } Background = fieldSolidColorBrush; }
void puzzle_FieldColorChanged(object sender, FieldColorChangedEventArgs e) { Button button = this.FindButtonForCoords(e.Coord); FieldColor color = this.puzzle.GetColor(e.Coord); switch (color) { case FieldColor.None: button.Background = this.noColorBrush; break; case FieldColor.Red: button.Background = this.redBrush; break; case FieldColor.Green: button.Background = this.greenBrush; break; case FieldColor.Blue: button.Background = this.blueBrush; break; } }
private ProgramExecutionResult CanBeSolvedWithDfs( HashSet <ProgramState> stateSet, bool[,] eatenStarsMask, ref ProgramState state, ref int starsEaten, Program program) { Debug.Assert(state.Instruction == 0); for (int instr = 0; instr < program.GetInstructionCountInFunc(state.Func); ++instr) { state.Instruction = instr; // Loop check if (stateSet.Contains(state)) { return(ProgramExecutionResult.Fail); } FieldColor currentColor = this.colors[state.Position.X, state.Position.Y]; ProgramSlot slot = program.GetProgramSlot(state.Func, state.Instruction); if (slot.Action == ProgramAction.None) { continue; } if (slot.Color != FieldColor.None && slot.Color != currentColor) { continue; } if (slot.Action == ProgramAction.Forward || slot.Action == ProgramAction.Left || slot.Action == ProgramAction.Right) { switch (slot.Action) { case ProgramAction.Left: state.Dir = (state.Dir - 1 + 4) % 4; break; case ProgramAction.Right: state.Dir = (state.Dir + 1) % 4; break; case ProgramAction.Forward: Coord newPosition = state.Position; newPosition.X += shiftX[state.Dir]; newPosition.Y += shiftY[state.Dir]; state.Position = newPosition; if (state.Position.X < 0 || state.Position.Y < 0 || state.Position.X >= this.width || state.Position.Y >= this.height) { return(ProgramExecutionResult.Fail); } if (colors[state.Position.X, state.Position.Y] == FieldColor.None) { return(ProgramExecutionResult.Fail); } // If star was eaten after this turn if (this.stars[state.Position.X, state.Position.Y] && !eatenStarsMask[state.Position.X, state.Position.Y]) { eatenStarsMask[state.Position.X, state.Position.Y] = true; starsEaten += 1; if (starsEaten == this.starsCount) { return(ProgramExecutionResult.StarsEaten); } } break; } } else if (slot.Action == ProgramAction.F1 || slot.Action == ProgramAction.F2 || slot.Action == ProgramAction.F3 || slot.Action == ProgramAction.F4 || slot.Action == ProgramAction.F5) { ProgramState stateToPass = state; stateToPass.Instruction = 0; switch (slot.Action) { case ProgramAction.F1: stateToPass.Func = 0; break; case ProgramAction.F2: stateToPass.Func = 1; break; case ProgramAction.F3: stateToPass.Func = 2; break; case ProgramAction.F4: stateToPass.Func = 3; break; case ProgramAction.F5: stateToPass.Func = 4; break; } stateSet.Add(state); ProgramExecutionResult result = CanBeSolvedWithDfs(stateSet, eatenStarsMask, ref stateToPass, ref starsEaten, program); stateSet.Remove(state); state.Position = stateToPass.Position; state.Dir = stateToPass.Dir; if (result != ProgramExecutionResult.StillWorking) { return(result); } } } return(ProgramExecutionResult.StillWorking); }
/// <summary> /// Sets the background color of a field /// </summary> /// <param name="color">The given FieldColor</param> public void SetColor(FieldColor color) { switch (color) { case FieldColor.Black: this.backgroundColor = TextureManager.Black; break; case FieldColor.Green: this.backgroundColor = TextureManager.Green; break; case FieldColor.Red: this.backgroundColor = TextureManager.Red; break; case FieldColor.White: this.backgroundColor = TextureManager.White; break; } }
public ColorBet(string name, uint amount, FieldColor color) : base(name, amount) { _color = color; }
public CalculationField(int initialTargetValue, FieldColor initialColor) { TargetValue = initialTargetValue; Color = initialColor; }
private static bool SkipDueToOptimizations(ProgramSlot[] code, int funcIndex, int depth, ProgramAction action, FieldColor color) { // Rotation code optimization if ((action == ProgramAction.Left || action == ProgramAction.Right) && depth > 0) { // Do not use consequent opposite rotations with the same color if (code[depth - 1].Color == color && ((code[depth - 1].Action == ProgramAction.Left && action == ProgramAction.Right) || (code[depth - 1].Action == ProgramAction.Right && action == ProgramAction.Left))) { return true; } // Consequent rotation count optimization int i = depth - 1; int sameCount = 1; while (i >= 0 && code[i].Color == color && code[i].Action == action) { sameCount += 1; i -= 1; } // Max 2 rotations right and 1 rotation left if ((sameCount > 2 && action == ProgramAction.Right) || (sameCount > 1 && action == ProgramAction.Left)) return true; } // Recursion optimization - do not call function from itself in the first instruction if (depth == 0 && funcIndex == 0 && action == ProgramAction.F1 || depth == 0 && funcIndex == 1 && action == ProgramAction.F2 || depth == 0 && funcIndex == 2 && action == ProgramAction.F3 || depth == 0 && funcIndex == 3 && action == ProgramAction.F4 || depth == 0 && funcIndex == 4 && action == ProgramAction.F5) { return true; } return false; }
public FieldColorChangedEventArgs(FieldColor oldColor, FieldColor newColor, Coord coord) : base(coord) { this.OldColor = oldColor; this.NewColor = newColor; }
private void LoadDescription(string fileName) { if (!File.Exists(fileName)) { MessageBox.Show(string.Format("File not found: '{0}'", fileName), "Error!", MessageBoxButton.OK, MessageBoxImage.Error); return; } string[] lines = File.ReadAllLines(fileName); if (lines.Length == 0) { MessageBox.Show("Given file does not contain any data.", "Error!", MessageBoxButton.OK, MessageBoxImage.Error); return; } string[] widthAndHeight = lines[0].Split(); if (widthAndHeight.Length != 2) { MessageBox.Show("Given file does not contain any data.", "Error!", MessageBoxButton.OK, MessageBoxImage.Error); return; } bool parseResult = true; int width, height; parseResult &= Int32.TryParse(widthAndHeight[0], out height); parseResult &= Int32.TryParse(widthAndHeight[1], out width); if (!parseResult || width <= 0 || height <= 0) { MessageBox.Show("Field size values are not correct.", "Error!", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (lines.Length != height + 1) { MessageBox.Show("Incorrect line count in input file.", "Error!", MessageBoxButton.OK, MessageBoxImage.Error); return; } FieldColor[] intToColor = new[] { FieldColor.None, FieldColor.Red, FieldColor.Green, FieldColor.Blue }; this.puzzle.Reset(); for (int y = 0; y < height; ++y) { if (lines[y + 1].Length != width) { MessageBox.Show("Incorrect line count in input file.", "Error!", MessageBoxButton.OK, MessageBoxImage.Error); return; } for (int x = 0; x < width; ++x) { int number = lines[y + 1][x]; bool hasStar = ((number & 4) != 0); FieldColor cellColor = intToColor[number & 3]; Coord coord = new Coord(x, y); this.puzzle.SetColor(coord, cellColor); this.puzzle.SetStar(coord, hasStar); } } }
public void SetColor(Coord coord, FieldColor color) { FieldColor oldColor = colors[coord.X, coord.Y]; colors[coord.X, coord.Y] = color; EventHandler<FieldColorChangedEventArgs> handler = this.FieldColorChanged; if (handler != null) handler(this, new FieldColorChangedEventArgs(oldColor, color, coord)); }
public void GreenBet_DifferentFieldColors_WonAmountCorrect(FieldColor color, int wonAmount) { _stubField.Color.Returns(color); Assert.That(_uutGreen.WonAmount(_stubField), Is.EqualTo(wonAmount)); }
public IEnumerable <Field> GetFieldsByColor(FieldColor color) { return(fields.Where(f => f.FieldColor == color)); }