public void DragOver(MathTask task) { var selectedSquare = board[selectedMathTask.Row, selectedMathTask.Col]; var destinationSquare = board[task.Row, task.Col]; var indexOfSelectedSquare = Squares.IndexOf(selectedSquare); var indexOfDestinationSquare = Squares.IndexOf(destinationSquare); var newSelectedSquare = new Square( selectedSquare.Row, selectedSquare.Col, selectedSquare.Color, new Empty(selectedSquare.Row, selectedSquare.Col)); Squares[indexOfSelectedSquare] = newSelectedSquare; selectedMathTask.Row = destinationSquare.Row; selectedMathTask.Col = destinationSquare.Col; var newDestinationSwuare = new Square( destinationSquare.Row, destinationSquare.Col, destinationSquare.Color, selectedMathTask); Squares[indexOfDestinationSquare] = newDestinationSwuare; this.board[selectedSquare.Row, selectedSquare.Col] = newSelectedSquare; this.board[destinationSquare.Row, destinationSquare.Col] = newDestinationSwuare; Task.Run(() => { MessageBox.Show(task.ToString()); }); }
public List <Location> GetRandomLocations() { return(Squares.Where(x => x.IsEmpty && x.IsRandom) .Select(x => x.Location).ToList()); // TODO - Need to make following logic iterative till most hit Quadrant with empty Squares is found. //var quadrant = GetMostSucessfulQuadrant(); //if (quadrant == Quadrant.Error) //{ // return Squares.Where(x => x.OccupancyType == OccupancyType.Nothing && x.IsRandom) // .Select(x => x.Location).ToList(); //} //else //{ // Console.WriteLine($"Quadrant: {quadrant}"); // if (!GetLocationsByQuadrantQuery(quadrant).Any()) // { // if (quadrant > Quadrant.First) // { // quadrant -= 1; // } // if (quadrant < Quadrant.Fourth) // { // quadrant += 1; // } // } // return GetLocationsByQuadrantQuery(quadrant).ToList(); }
public void TranslateHorizontally(MoveDirection direction) { if (!ChangeOccured) { if ((direction == MoveDirection.Right && lastMove == MoveDirection.Right) || (direction == MoveDirection.Left && lastMove == MoveDirection.Left)) { return; } } ChangeOccured = false; var rows = Squares.GroupBy(r => r.Y).ToList(); foreach (var row in rows) { if (direction == MoveDirection.Left) { PushRow(row.OrderBy(x => x.X).ToList(), direction); } else { PushRow(row.OrderByDescending(x => x.X).ToList(), direction); } } }
/// <summary> /// Used to remove the potential values for a cell. /// Will check the rest of the board to find any others that can be solved. /// Solved squares have their potential values cleared /// </summary> /// <param name="cell">The cell to set permanently to a value</param> private void SolidifySquareValue(Square cell) { //Don't do any work if it hasn't been set nor it has already been solidified (list is empty) if (cell.IsSet && cell.PotentialValues.Count != 0) { //Remove All Potential Values For Specified Square cell.PotentialValues.Clear(); RemovePotentialValuesFromRow(cell.Row, cell.Value); RemovePotentialValuesFromColumn(cell.Column, cell.Value); RemovePotentialValuesFromQuaderant(cell.Value, cell); // Set the Value for any square that only have one remaining PotentialValue foreach (Square square in Squares.Where(s => !s.IsSet && (s.PotentialValues.Count == 1))) { //Set the newly found value SetSquareValue(square.Row, square.Column, square.PotentialValues[0]); //Permanently set the value and continue the solve SolidifySquareValue(square); } } }
public SquareOfSquares() { this.InitializeComponent(); Root.RowDefinitions.Clear(); Root.RowDefinitions.Clear(); for (int i = 0; i < 112; i++) { Root.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) }); Root.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }); } foreach (InnerSquare square in GetSquares()) { var ctl = new ContentControl(); ctl.SetValue(Grid.RowProperty, square.Position.Y); ctl.SetValue(Grid.ColumnProperty, square.Position.X); ctl.SetValue(Grid.ColumnSpanProperty, square.Side); ctl.SetValue(Grid.RowSpanProperty, square.Side); Root.Children.Add(ctl); Squares.Add(ctl); } }
private async void squaresListBox_SelectionChanged(object sender, Windows.UI.Xaml.Controls.SelectionChangedEventArgs e) { if (squaresListBox.SelectedIndex != -1) { categoriesListBox.ItemsSource = await Squares.GetCategories(((Squares.Square)squaresListBox.SelectedItem).id); } }
private Battleship FindLargestHorizontalShip() { //the algorithm: 1iterate through each row cell by cell. //once empty cell is found move to the righ until the the cell is not empty of the board edge is reached //keep track of sizes. If the size is larger than the previous one create new battleship //return largest battleship int size = 0; Battleship battleship = null; for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { if (Squares.Where(s => s.X == x && s.Y == y).First().IsEmpty) { for (int i = x + 1; i < Width; i++) { if (Squares.Where(s => s.X == i && s.Y == y).First().IsEmpty&& size < i - x) { battleship = new Battleship(); battleship.AddSquares(Squares.Where(s => s.Y == y && s.X <= i)); size = battleship.Squares.Count; } } } } } return(battleship); }
public void DrawCurrentState(int picNum) { for (int y = 0; y < Squares.GetLength(0); y++) { for (int x = 0; x < Squares.GetLength(1); x++) { Squares[x, y].Render(Bitmap, Color.White); } } foreach (Square square in ClosedSet) { square.Render(Bitmap, Color.Red); } foreach (Square square in OpenSet) { square.Render(Bitmap, Color.Green); } foreach (Square square in Path) { square.Render(Bitmap, Color.Blue); } End.Render(Bitmap, Color.Black); Start.Render(Bitmap, Color.Black); string picName = $"{picNum}.bmp"; Bitmap.Save(picName); Console.WriteLine($"Drawn next state at: {Directory.GetCurrentDirectory()}\\{picName}"); }
public void CreateSquares(sbyte boardSize, IEnumerable <SquareViewModel> squares) { var width = (int)WindowWidth / boardSize; var height = width; var sqList = squares.ToList(); for (sbyte i = 0; i < boardSize; i++) { for (sbyte j = 0; j < boardSize; j++) { var pos = new Position(i, j); var square = new SquareViewModel(pos, FindColor(pos)) { ImagePath = null, Height = height, Width = width, }; sqList.Add(square); } } sqList .OrderByDescending(sq => sq.Position.ColumnNo) .ThenBy(sq => sq.Position.RowNo).ToList() .ForEach(sq => Squares.Add(sq)); }
private static void AddBoards(FlatMeshBuilder meshBuilder, BoardsInput input) { var vertices = Squares.Vertices(); var boardVertices = new Vector3[vertices.Length]; for (int i = 0; i < boardVertices.Length; ++i) { boardVertices[i] = Mathx.Multiply(vertices[i].X_Y(), input.extents) + input.offset; } var boardHeight = input.height / input.count; for (int i = 0; i < input.count; ++i) { var boardTop = input.top - boardHeight * i; var v0 = boardVertices[0] + boardTop; var v1 = boardVertices[1] + boardTop; var v2 = boardVertices[2] + boardTop; var v3 = boardVertices[3] + boardTop; var v4 = (v0 + v1) * 0.5f - boardHeight; var v5 = (v2 + v3) * 0.5f - boardHeight; meshBuilder.AddTriangle(v0, v1, v2); meshBuilder.AddTriangle(v0, v2, v3); meshBuilder.AddTriangle(v1, v4, v5); meshBuilder.AddTriangle(v1, v5, v2); meshBuilder.AddTriangle(v4, v0, v3); meshBuilder.AddTriangle(v4, v3, v5); } }
public void TranslateVertically(MoveDirection direction) { if (!ChangeOccured) { if ((direction == MoveDirection.Bottom && lastMove == MoveDirection.Bottom) || (direction == MoveDirection.Top && lastMove == MoveDirection.Top)) { return; } } ChangeOccured = false; var cols = Squares.GroupBy(r => r.X).ToList(); foreach (var col in cols) { if (direction == MoveDirection.Top) { PushCol(col.OrderBy(x => x.Y).ToList(), direction); } else { PushCol(col.OrderByDescending(x => x.Y).ToList(), direction); } } }
private static void AddBar(FlatMeshBuilder meshBuilder, BarInput input) { var barRotationY = Quaternion.AngleAxis(input.angleY, Vector3.up); var v0 = -input.spike + input.offset; var v5 = input.height + input.spike + input.offset; var vertices = Squares.Vertices(); for (int i1 = 0, i0 = vertices.Length - 1; i1 < vertices.Length; i0 = i1++) { var vertex0 = vertices[i0].X_Y(); var vertex1 = vertices[i1].X_Y(); var v1 = barRotationY * vertex0 * input.radius + input.offset; var v2 = barRotationY * vertex1 * input.radius + input.offset; var v3 = v1 + input.height; var v4 = v2 + input.height; meshBuilder.AddTriangle(v0, v2, v1); meshBuilder.AddTriangle(v1, v2, v4); meshBuilder.AddTriangle(v1, v4, v3); meshBuilder.AddTriangle(v3, v4, v5); } }
/// <summary> /// Finds numbers in quadrents that can only be one value and updates that square with its /// proper value. /// </summary> /// <returns>True if changed a value, false if nothing was changed</returns> private bool FindSingleNumbersInQuadrents() { bool changedSquare = false; foreach (Blocks block in Enum.GetValues(typeof(Blocks))) { //Find Singles of Each number in Each quadrent for (int i = 1; i < 10; i++) { //int to keep track of number found int numValues = 0; // SearchQuadrent foreach (Square square in Squares.Where(s => !s.IsSet && (s.Block == block) && s.PotentialValues.Contains(i))) { numValues++; } //Update single square if one is found if (numValues == 1) { Square newSolvedSquare = Squares.Single(s => !s.IsSet && (s.Block == block) && s.PotentialValues.Contains(i)); SetSquareValue(newSolvedSquare.Row, newSolvedSquare.Column, i); SolidifySquareValue(newSolvedSquare); //Mark that something was changed changedSquare = true; } } } return(changedSquare); }
private Battleship FindLargestVerticalShip() { int size = 0; Battleship battleship = null; for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { if (Squares.Where(s => s.X == x && s.Y == y).First().IsEmpty) { for (int i = y + 1; i < Height; i++) { if (Squares.Where(s => s.Y == i && s.X == x).First().IsEmpty&& size <= i - y) { battleship = new Battleship(); battleship.AddSquares(Squares.Where(s => s.X == x && s.Y >= y && s.Y <= i)); size = battleship.Squares.Count; } } } } } return(battleship); }
public GridSquare this[GridSquarePosition position] { get { return(Squares.Find(s => s.Position == position)); } }
/// <summary> /// Populates the page with content passed during navigation. Any saved state is also /// provided when recreating a page from a prior session. /// </summary> /// <param name="sender"> /// The source of the event; typically <see cref="NavigationHelper"/> /// </param> /// <param name="e">Event data that provides both the navigation parameter passed to /// <see cref="Frame.Navigate(Type, object)"/> when this page was initially requested and /// a dictionary of state preserved by this page during an earlier /// session. The state will be null the first time a page is visited.</param> private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e) { //if (Frame.BackStack.Count != 0 && Frame.BackStack.First().SourcePageType == typeof(LoginPage)) // Frame.BackStack.Remove(Frame.BackStack.First()); // TODO: Create an appropriate data model for your problem domain to replace the sample data //var sampleDataGroups = await SampleDataSource.GetGroupsAsync(); //this.DefaultViewModel["Groups"] = sampleDataGroups; //var posts = await Posts.GetActivities(null, null, null); //FontIcon icon = new FontIcon(); //icon.Glyph = (await Notifications.GetNotificationCount()).ToString(); //notificationAppBarButton.Icon = icon; //itemGridView.ItemsSource = posts.posts; var squares = await Squares.GetSquares(); //communitiesGridView.Source = squares; communitiesHub.DataContext = squares; var circles = await Circles.GetCircles(); circlesHub.DataContext = circles; FontIcon icon = new FontIcon(); icon.Glyph = (await Notifications.GetNotificationCount()).ToString(); notificationAppBarButton.Icon = icon; favouritesHub.DataContext = commands; }
public IEnumerator WHEN_FillAllGameDataFunctionCalled_THEN_GameDataIsFilled() { // Make all games labelled as played Globals.isBalloonsButtonOn = false; Globals.isCTFButtonOn = false; Globals.isImageHitButtonOn = false; Globals.isSquaresButtonOn = false; Globals.isCatchTheBallButtonOn = false; Globals.isJudgeTheBallButtonOn = false; Globals.isSaveOneBallButtonOn = false; BatterySessionManagement batterySessionManagement = new BatterySessionManagement(); batterySessionManagement.FillAllGameData(); yield return(null); // Game data should be filled with actual gameplay data from each game Assert.AreEqual(Balloons.GetGameplayData(), batterySessionManagement.balloonsData); Assert.AreEqual(CatchTheThief.GetGameplayData(), batterySessionManagement.ctfData); Assert.AreEqual(Squares.GetGameplayData(), batterySessionManagement.squaresData); Assert.AreEqual(ImageHit.GetGameplayData(), batterySessionManagement.imageHitData); Assert.AreEqual(CatchTheBall.GetGameplayData(), batterySessionManagement.catchTheBallData); Assert.AreEqual(JudgeTheBall.GetGameplayData(), batterySessionManagement.judgeTheBallData); Assert.AreEqual(SaveOneBall.GetGameplayData(), batterySessionManagement.saveOneBallData); }
public string RenderBoard() { string[] allowedValues = new string[] { xGlyph, oGlyph }; var transformed = Squares.Select(s => allowedValues.Contains(s?.ToUpper()) ? s.ToUpper() : spacer); return(string.Format(Board, transformed.ToArray())); }
/// <summary> /// Populates the page with content passed during navigation. Any saved state is also /// provided when recreating a page from a prior session. /// </summary> /// <param name="sender"> /// The source of the event; typically <see cref="NavigationHelper"/> /// </param> /// <param name="e">Event data that provides both the navigation parameter passed to /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and /// a dictionary of state preserved by this page during an earlier /// session. The state will be null the first time a page is visited.</param> private async void navigationHelper_LoadState(object sender, LoadStateEventArgs e) { var squares = await Squares.GetSquares(); itemsViewSource.Source = squares; // TODO: Assign a bindable collection of items to this.DefaultViewModel["Items"] }
public List <Square> GetNeighbours(Location location) { int row = location.Row; int column = location.Column; List <Square> neighbours = new List <Square>(); if (row > 1) { neighbours.Add(Squares.At(row - 1, column)); } if (column < Configuration.Columns) { neighbours.Add(Squares.At(row, column + 1)); } if (column > 1) { neighbours.Add(Squares.At(row, column - 1)); } if (row < Configuration.Rows) { neighbours.Add(Squares.At(row + 1, column)); } return(neighbours); }
private void FillSqrRight(Board board, Square sqr) { for (int i = 0; i < Length; i++) { Squares.Add(board.Squares[sqr.X + i, sqr.Y]); board.Squares[sqr.X + i, sqr.Y].Ship = this; } }
/// <summary> /// Sets a square's value based on the row and column. Recursively calls itself. /// </summary> /// <param name="row">Horizontal Directions</param> /// <param name="column">Vertical Directions</param> /// <param name="value">Value to set square at</param> public void SetSquareValue(int row, int column, int value) { //Get the square from the list Square activeSquare = Squares.Single(x => (x.Row == row) && (x.Column == column)); //Set the value (this is not permanent) activeSquare.Value = value; }
public void AddSquares(IEnumerable <Square> squares) { foreach (var item in squares) { item.IsEmpty = false; } Squares.AddRange(squares); }
private void FillSqrBottom(Board board, Square sqr) { for (int i = 0; i < Length; i++) { Squares.Add(board.Squares[sqr.X, sqr.Y - i]); board.Squares[sqr.X, sqr.Y - i].Ship = this; } }
private void RemovePotentialValuesFromQuaderant(int value, Square sqareInQuadrent) { // Remove value from other squares in the same quadrant foreach (Square square in Squares.Where(s => !s.IsSet && (s.Block == sqareInQuadrent.Block))) { square.PotentialValues.Remove(value); } }
public void RoundSquareTest() { int radius = 3; double expected = 28.27; Squares figure = new Squares(); Assert.AreEqual(expected, figure.RoundSquare(radius)); }
private void RemovePotentialValuesFromRow(int row, int value) { // Remove value from other squares in the same row foreach (Square square in Squares.Where(s => !s.IsSet && (s.Row == row))) { square.PotentialValues.Remove(value); } }
private void Goto(GridItem item) { if (item.PathIndex == null) { item.PathIndex = Squares.Max(x => x.PathIndex ?? 0) + 1; Route.Add(item); } }
private void RemovePotentialValuesFromColumn(int column, int value) { // Remove value from other squares in the same column foreach (Square square in Squares.Where(s => !s.IsSet && (s.Column == column))) { square.PotentialValues.Remove(value); } }
void Start() { //searches for object type square and assigns it to my square mySquare = GameObject.FindObjectOfType <Squares>(); //saves the distance between the ball and the paddle squareToBallVector = this.transform.position - mySquare.transform.position; }
public static UInt64 GetKnightAttacksBitboard(Squares square) { return KnightAttacksBitboardsField[(int)square]; }
/// <summary> /// The move squares. /// </summary> /// <param name="squares"> /// The squares. /// </param> private void MoveSquares(ref Squares squares) { Square square; square = Board.GetSquare(this.Base.Square.Ordinal - 1); if (square != null && (square.Piece == null || (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable))) { squares.Add(square); } square = Board.GetSquare(this.Base.Square.Ordinal + 15); if (square != null && (square.Piece == null || (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable))) { squares.Add(square); } square = Board.GetSquare(this.Base.Square.Ordinal + 16); if (square != null && (square.Piece == null || (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable))) { squares.Add(square); } square = Board.GetSquare(this.Base.Square.Ordinal + 17); if (square != null && (square.Piece == null || (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable))) { squares.Add(square); } square = Board.GetSquare(this.Base.Square.Ordinal + 1); if (square != null && (square.Piece == null || (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable))) { squares.Add(square); } square = Board.GetSquare(this.Base.Square.Ordinal - 15); if (square != null && (square.Piece == null || (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable))) { squares.Add(square); } square = Board.GetSquare(this.Base.Square.Ordinal - 16); if (square != null && (square.Piece == null || (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable))) { squares.Add(square); } square = Board.GetSquare(this.Base.Square.Ordinal - 17); if (square != null && (square.Piece == null || (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable))) { squares.Add(square); } }
public static UInt64 Clear(this UInt64 bitboard, Squares square) { return bitboard & Bitboard.ClearMasksField[(int)square]; }
public static bool IsSet(this UInt64 bitboard, Squares square) { return (bitboard & Bitboard.SetMasksField[(int)square]) != 0; }
public static UInt64 Set(this UInt64 bitboard, Squares square) { return bitboard | Bitboard.SetMasksField[(int)square]; }