private void ReduceRegion(int skip, SudokuRegion region, SudokuState state, ICollection <IEvent> events) { var quad = 0u; buffer.Clear(); foreach (var index in region.Skip(skip)) { var value = state[index]; if (SudokuCell.Count(value) < 4) { quad |= value; // Joined the represent more then 3 values. if (SudokuCell.Count(quad) > 4 || buffer.Count > 3) { return; } buffer.Add(index); } } if (buffer.Count == 4) { Fetch(quad, buffer, region, state, events); } }
/// <inheritdoc /> public void Solve(SudokuPuzzle puzzle, SudokuState state, ICollection <IEvent> events) { foreach (var region in puzzle.Regions) { foreach (var intersected in region.Intersected) { intersection.Clear(); intersection.AddRange(region.Intersect(intersected)); // We found candidate intersections if (intersection.Count > 1) { foreach (var value in puzzle.SingleValues) { var pre = events.Count; Solve(state, region, intersected, value, events); if (pre != events.Count) { return; } } } } } }
public void ClearList() { var list = new SimpleList<int>() { 1, 2, 3 }; list.Clear(); int[] clearedList = { 0, 0, 0, 0, 0, 0, 0, 0}; CollectionAssert.Equals(clearedList, list); }
private void ReduceRegion(uint pair, SudokuRegion region, SudokuState state, ICollection <IEvent> events) { HiddenPairs.Clear(); foreach (var index in region) { var and = state[index] & pair; // at least on of the two is pressent. if (and != 0) { // If not both are present or we already had 2, return. if (and != pair || HiddenPairs.Count > 1) { return; } HiddenPairs.Add(index); } } if (HiddenPairs.Count == 2) { Fetch(pair, HiddenPairs, state, events); } }
/// <summary>Releases the list for reuse, and clears it.</summary> public void ReleaseAndClear(SimpleList <T> list) { Guard.NotNull(list, nameof(list)); Release(list); list.Clear(); }
public void Clear() { SimpleList <DateTime> dates = new SimpleList <DateTime>(new DateTime[] { new DateTime(), DateTime.Now }); Assert.AreEqual(2, dates.Count); dates.Clear(); Assert.AreEqual(0, dates.Count); Assert.AreEqual(2, dates.Capacity); }
public void testEmpty() { SimpleList <int> tester = new SimpleList <int>(); Assert.True(tester.IsEmpty()); tester.Append(0); tester.Append(1); tester.Append(2); Assert.False(tester.IsEmpty()); tester.Clear(); Assert.True(tester.IsEmpty()); }
public void CanAddAndClear() { var sourceNode = new Node(Utils.Id("foo")); var simpleList = new SimpleList <I32>(); simpleList.Init(sourceNode, db); for (int i = 0; i < 100; i++) { simpleList.Add(new I32 { v = i }); } simpleList.Clear(); Assert.Empty(simpleList); }
public void Solve(uint value, SudokuRegion first, SudokuRegion second, SudokuRegionType otherType, SudokuState state, ICollection <IEvent> events) { buffer.Clear(); for (var index = 0; index < 9; index++) { var indexFirst = first[index]; var indexSecond = second[index]; var joinFirst = state[indexFirst] & value; var joinSecond = state[indexSecond] & value; if (joinFirst == 0) { if (joinSecond != 0) { return; } } else { if (joinSecond == 0 || buffer.Count > 3) { return; } buffer.Add(indexFirst); buffer.Add(indexSecond); } } if (buffer.Count == 4) { var reducded = Fetch( value, first.Intersected.FirstOrDefault(r => r.RegionType == otherType), state, events); reducded |= Fetch( value, second.Intersected.FirstOrDefault(r => r.RegionType == otherType), state, events); if (reducded) { events.Add(ReducedOptions.Ctor <ReduceXWing>()); } } }
static void Main(string[] args) { SimpleList<int> _strings = new SimpleList<int>(); _strings.Add(1); _strings.Add(2); _strings.Add(3); _strings.Add(4); _strings.Add(5); var count = _strings.Count; var number5 = _strings[4]; _strings[4] = 6; var number6 = _strings[4]; _strings.Insert(4, 5); var number1 = _strings.RemoveAt(0); _strings.Clear(); }
/// <summary> /// Finds the list of locations that will be captured if a token was placed at the current location by the given player /// </summary> /// <param name="player">The player placing the token</param> /// <returns>The list of captured token locations</returns> private static SimpleList<int> FindCapturedTokens() { int player = Battle.CurrentTurn; SimpleList<int> spots = new SimpleList<int>(); // Checks in all 8 directions, starting with North for (int d = 0; d < 8; ++d) { int searchX = Battle.X + xChanges[d]; int searchY = Battle.Y + yChanges[d]; // Gets the list of possible moves SimpleList<int> possibleSpots = new SimpleList<int>(); // Allow it to search only within the grid's range while (searchX >= 0 && searchX < 10 && searchY >= 0 && searchY < 10) { int spot = Battle.Field[10 * searchY + searchX]; // If it's an enemy piece, remember the location if (spot == 3 - player) possibleSpots.Add(10 * searchY + searchX); // Stop when it's an owned piece else if (possibleSpots.Size > 0 && spot == player) { break; } // Stop and clear the list if it's an empty piece else { possibleSpots.Clear(); break; } searchX += xChanges[d]; searchY += yChanges[d]; } // If the loop ended because of going out of range, clear the list if (searchX < 0 || searchX > 9 || searchY < 0 || searchY > 9) possibleSpots.Clear(); // Add all the valid spots found that weren't cleared foreach (int i in possibleSpots) spots.Add(i); } return spots; }
/// <summary> /// The computer's playing algorithm /// Determines where to play for the AI /// Possibly can be expanded upon to make a better AI /// (prioritizing corners or further considerations) /// /// Current Process: /// - Finds all possible moves /// - Give each move a rating depending on what skill it is /// - Counts how many tokens that can be lost next round for each move /// - Weighs the options using (rating - loss), higher being better /// - Keeps a list of the best option(s) /// - Picks a move from the list of best options and uses it /// </summary> /// <param name="filter">The list of accepted actions</param> /// <returns>the location of the "best" move</returns> public static Move Run(params int[] filter) { // Records the best option when measured by ( captured pieces - vulnerable pieces ) int best = 0; // Saves the board to refresh after checking int[] boardBackup = new int[100]; Battle.Field.Board.CopyTo(boardBackup, 0); Boolean couldMove = false; // Finds where the computer can move SimpleList<Move> moves = FindPossibleMoves(2); // Records the locations of the best choices SimpleList<Move> bestMoves = new SimpleList<Move>(); int hp = Battle.Player.Health; int hp2 = Battle.Foe.Health; Battle.ApEnabled(false); // Weigh each move according to the ( captured pieces - vulnerable pieces ) idea foreach (Move a in moves) { if (a.Action == 0) couldMove = true; // Apply the filter if (filter.Length != 0) { Boolean good = false; foreach (int i in filter) if (a.Action == i) good = true; if (!good) continue; } Battle.X = a.Location % 10; Battle.Y = a.Location / 10; // Get the rating of the skill Type type = Type.GetType(actionPrefix + actionNames[a.Action]); int c = (int)type.InvokeMember("Rate", BindingFlags.InvokeMethod, null, null, null); // Get how many tokens can be lost to the human type.InvokeMember("Perform", BindingFlags.InvokeMethod, null, null, null); int l = FindPotentialLoss(); Battle.ExtraTurns = 0; // Keep moves within 2 of the "best" and clear all old moves if the new move is much better if (c - l > best + 2 || bestMoves.Size == 0) { best = c - l; bestMoves.Clear(); bestMoves.Add(a); } else if (c - 1 >= best - 2) bestMoves.Add(a); // Refresh the board after checking the spot boardBackup.CopyTo(Battle.Field.Board, 0); } // Restore the hps back to what it was before the tests Battle.Player.Damage(Battle.Player.Health - hp); Battle.Foe.Damage(Battle.Foe.Health - hp2); Battle.ApEnabled(true); // If the computer found a best option, return it if (bestMoves.Size > 0 && couldMove) { Move bestMove = bestMoves[new Random().Next(0, bestMoves.Size)]; return bestMove; } return null; }
public void TearDown() { _listValues.Clear(); _listValues = default; }
public void ClearList() { activeList.Clear(); sleepList.Clear(); }