public void DoClientPingSquare(ISquare square) { foreach (int i in _board.GetSquareCache(square).DiagonalSquareIndices) { _board.Data.Squares[i].Client.PingSquare(SquarePingType.Test); } }
public bool Predicate(ISquare testSquare) { if (this.MapHandler.GetNumberLeft(testSquare, out var adjacentBlanks) != 1) { return(false); } this.blankAdjacent = adjacentBlanks.ToArray(); if (this.blankAdjacent.Length != 2) { return(false); } IEnumerable <ISquare> blanks = null; this.neighborsBlanks = ( from adjNum in this.MapHandler.GetAdjacentNumbers(testSquare) where this.MapHandler.GetNumberLeft(adjNum, out blanks) == 1 && blanks.Intersect(this.blankAdjacent).Count() == 2 select blanks.ToArray()) .ToArray(); return(this.neighborsBlanks.Length > 0); }
public void SquareClicked(IGridLocation clickedLocation) { ISquare clickedSquare = CurrentBoard[clickedLocation]; // If a piece is selected, try to move to the chosen location. if (SquareSelected) { Move attemptedMove = new Move(SelectedSquare.Location, clickedLocation); // If this is a possible move, execute the move. Then clear the selection either way. foreach (Move move in AvailableMoves.Where(move => move.Equals(attemptedMove))) { Execute(move); SendMoveMade(); return; } } if (clickedSquare.Type != PieceType.None && clickedSquare.Colour == PlayingColour) { SelectedSquare = clickedSquare; SquareSelected = true; SendHighlightsRequested(CurrentBoard.AvailableDestinations(SelectedSquare)); return; } }
public void DoClientAttemptPieceMove(IPiece piece, ISquare targetSquare) { // Piece p = _pieces[piece.id]; Square s = _board.Data.Squares[targetSquare.id]; // Gather move data MoveData moveData = new MoveData { Board = _board.Data, Piece = p, Square = s }; // Send result to client simulation MoveResultData result = MovementValidator.MoveIsValid(moveData); if (result.Success) { p.Data.CurrentSquare.Data.CurrentPiece = null; p.Data.CurrentSquare = s; s.Data.CurrentPiece = p; } _gameClient.DoPieceMoveValidationResult(result); }
public void RenderBorderBack(ISquare square) { runAnimation(); if (!FillBackground) return; var slice = Slice.ToPercentage(_width, _height); var width = Width.ToPixels(_width, _height); var outset = Outset.ToPixels(_width, _height); float farLeft = square.TopLeft.X - outset.Left.Value; float farRight = square.TopRight.X + outset.Right.Value; float farTop = square.TopLeft.Y + outset.Top.Value; float farBottom = square.BottomLeft.Y - outset.Bottom.Value; var quad = new AGSSquare (new PointF (farLeft + width.Left.Value, farBottom + width.Bottom.Value), new PointF (farRight - width.Right.Value, farBottom + width.Bottom.Value), new PointF (farLeft + width.Left.Value, farTop - width.Top.Value), new PointF (farRight - width.Right.Value, farTop - width.Top.Value)); drawQuad(quad, new FourCorners<Vector2> (new Vector2 (slice.Left.Value, slice.Bottom.Value), new Vector2 (1f - slice.Right.Value, slice.Bottom.Value), new Vector2 (slice.Left.Value, 1f - slice.Top.Value), new Vector2 (1f - slice.Right.Value, 1f - slice.Top.Value))); if (DrawBorderBehind) drawBorders(square); }
public void RenderBorderFront(ISquare square) { if (!DrawBorderBehind) { drawBorders(square); } }
public static void RunGameMove(Game game) { foreach (IPlayer player in game.Players) { Console.Clear(); //rulla tärning int diceroll = Dice.RollDice(player); //välja pjäs Piece piece = game.SelectPiece(player, diceroll); if (piece != null) { int newsquarenr = piece.Steps + diceroll; //stanna på yttre raden om du rullar mindre än 40 if (newsquarenr < 40) { //spara gamla rutan för att skriva drag ISquare oldsquare = piece.CurrentSquare; //flytta pjäs game.MoveToSquare(piece, diceroll); //skriv ut vad som hände bool isNest = oldsquare.GetType() == typeof(Nest); if (isNest) { Console.WriteLine($"Piece nr {piece.PieceNr} has moved from nest to square nr {piece.CurrentSquare.SquareId}"); } else { Console.WriteLine($"Piece nr {piece.PieceNr} has moved from square nr {oldsquare.SquareId} to square nr {piece.CurrentSquare.SquareId}"); } } else //om någon pjäs tagit mer än 40 steg, gå in i vinststräckan { //gå till inre raden if (player.WinSquares != null) { //spara gamla rutan för att skriva drag ISquare oldsquare = piece.CurrentSquare; //flytta pjäs game.WinRowMove(piece, diceroll); //skriv ut vad som hände om pjäsen inte vunnit if (player.Pieces.Contains(piece)) { Console.WriteLine($"Piece nr {piece.PieceNr} has moved from square nr {oldsquare.SquareId} to square nr {piece.CurrentSquare.SquareId}"); Console.WriteLine($"Piece nr {piece.PieceNr} is {5 - piece.CurrentSquare.SquareId} steps from winning"); } } else { //skapa inre raden om den inte finns int steps = newsquarenr - 40; game.SetUpWinSquares(piece, steps); } } } Console.ReadLine(); } }
public void RenderBorderBack(ISquare square) { if (_glUtils.DrawQuad(_frameBuffer, square, _quad)) { return; } float width = _settings.VirtualResolution.Width; float height = _settings.VirtualResolution.Height; IGLColor color = IsSelected ? _selectedColor : _color; IGLColor foldColor = IsSelected ? _selectedFoldColor : _foldColor; float foldHeight = height * (1f / 5f); PointF foldBottom = new PointF(width / 2f, foldHeight); _frameBuffer = _glUtils.BeginFrameBuffer(square, _settings); _glUtils.DrawQuad(0, new Vector3(0, height, 0), new Vector3(width, height, 0), new Vector3(), new Vector3(width, 0, 0), color, color, color, color); _glUtils.DrawTriangle(0, new GLVertex[] { new GLVertex(new Vector2(), _emptyVector, foldColor), new GLVertex(foldBottom.ToVector2(), _emptyVector, foldColor), new GLVertex(new Vector2(width, 0), _emptyVector, foldColor) }); _frameBuffer.End(); _glUtils.DrawQuad(_frameBuffer, square, _quad); }
public static void CheckCapture(IBoard board, ISquare targetSquare) { CheckCaptureHorizontal(board, targetSquare, Square.NeighborDirection.Right); CheckCaptureHorizontal(board, targetSquare, Square.NeighborDirection.Left); CheckCaptureVertical(board, targetSquare, Square.NeighborDirection.Top); CheckCaptureVertical(board, targetSquare, Square.NeighborDirection.Bottom); }
private static void CheckCaptureVertical(IBoard board, ISquare originSquare, Square.NeighborDirection direction) { if (direction == Square.NeighborDirection.Left || direction == Square.NeighborDirection.Right) { throw new ArgumentException(); } ISquare targetSquare = originSquare.Neighbors[direction]; if (targetSquare != null && targetSquare.IsOccupied && targetSquare.Occupant.Player != originSquare.Occupant.Player && !targetSquare.Occupant.IsKing) { IPiece deadPiece = null; ISquare oppositeSquare = targetSquare.Neighbors[direction]; if (oppositeSquare != null && oppositeSquare.IsOccupied && oppositeSquare.Occupant.Player == originSquare.Occupant.Player) { deadPiece = targetSquare.Occupant; } else if (oppositeSquare == null && (targetSquare.Right == null || targetSquare.Left == null)) { if ((targetSquare.Right == null && targetSquare.Left.Occupant != null && targetSquare.Left.Occupant.Player == originSquare.Occupant.Player) || (targetSquare.Left == null && targetSquare.Right.Occupant != null && targetSquare.Right.Occupant.Player == originSquare.Occupant.Player)) { deadPiece = targetSquare.Occupant; } } if (deadPiece != null) { deadPiece.Location = null; targetSquare.Occupant = null; board.Pieces.Remove(deadPiece); } } }
public Move(IGridLocation start, IGridLocation end, Move sideEffect = null, ISquare enPassantSquare = null) { Start = start; End = end; SideEffect = sideEffect; EnPassantSquare = enPassantSquare; }
public SquareSitResponse Sit(SquareSitRequest request) { var res = new SquareSitResponse(); //var userID = Utils.GetUserIDByToken(request.Token); //var square = chessContext.Squares[userID]; var tableId = Utils.GetRequestParam <int>(request.Biz_Content, "table_id"); var table = ChessingManager.Instance.Tables[tableId]; ISquare square = Square; if (square != null) { if (square.Table != null && square.Table != table) { throw new Exception(string.Format("Error when user {0} Sit at table {1}, square with other table ", UserID, tableId)); } } else { var newCamp = !table.Squares.Keys.Contains(Camp.RedCamp) ? Camp.RedCamp : Camp.BlackCamp; square = new Square(newCamp, newCamp == Camp.RedCamp ? ChessColor.Red : ChessColor.Black); ChessingManager.Instance.Squares.Add(UserID, square); } square.Sit(table); return(res); }
private static void AssertType(ISquare square, PieceType type) { if (square.Type != type) { throw new Exception("A piece-specific method was called on the wrong type of piece."); } }
public void AddSquare(long userID, ISquare square) { if (!_squares.Keys.Contains(userID)) { _squares.Add(userID, square); } }
public IEnumerable <IGridLocation> PawnAttackedLocations(ISquare pawn) { AssertType(pawn, PieceType.Pawn); PieceColour colour = pawn.Colour; byte xCoord = pawn.Location.XCoord; byte yCoord = pawn.Location.YCoord; List <IGridLocation> attacked = new List <IGridLocation>(); // If the pawn is on the last row, it's attacking nothing. if (LastRow(pawn)) { return(attacked); } sbyte minusIfWhite = (sbyte)((colour == PieceColour.White) ? -1 : 1); // Add the diagonal squares to the list if they exist on the board. IGridLocation left = new GridLocation((byte)(xCoord - 1), (byte)(yCoord + minusIfWhite)); IGridLocation right = new GridLocation((byte)(xCoord + 1), (byte)(yCoord + minusIfWhite)); if (xCoord != 0) { attacked.Add(left); } if (xCoord != 7) { attacked.Add(right); } return(attacked); }
public IEnumerable <Move> KingMoves(ISquare piece) { AssertType(piece, PieceType.King); IEnumerable <IGridLocation> adjacentLocations = piece.AdjacentLocations(); List <Move> moves = new List <Move>(); foreach (IGridLocation adjacentLocation in adjacentLocations) { moves.Add(new Move(piece.Location, adjacentLocation)); } byte backRank = BackRank(piece.Colour); // Add the castling locations if appropriate if (CanCastleKingSide(piece.Colour)) { moves.Add(new Move(piece.Location, new GridLocation((byte)6, backRank), new Move(new GridLocation((byte)7, BackRank(piece.Colour)), new GridLocation((byte)5, backRank)))); } if (CanCastleQueenSide(piece.Colour)) { moves.Add(new Move(piece.Location, new GridLocation((byte)2, backRank), new Move(new GridLocation((byte)0, backRank), new GridLocation((byte)3, backRank)))); } return(moves.Where(move => !AttackedLocations(piece.Colour).Contains(move.End) && !PiecesOfSameColour(move))); }
/// <summary> /// Returns a list of all the squares that are currently attacked by the piece at the given square. /// </summary> /// <param name="attacker"></param> /// <returns></returns> private IEnumerable <IGridLocation> LocationsAttackedBy(ISquare attacker) { if (attacker.Type == PieceType.None) { throw new Exception("AttackedSquares was called with an empty square as the attacker."); } switch (attacker.Type) { case PieceType.Pawn: return(PawnAttackedLocations(attacker)); case PieceType.Knight: return(DestinationsFromMoves(KnightMoves(attacker))); case PieceType.Bishop: return(DestinationsFromMoves(BishopMoves(attacker))); case PieceType.Rook: return(DestinationsFromMoves(RookMoves(attacker))); case PieceType.Queen: return(DestinationsFromMoves(QueenMoves(attacker))); case PieceType.King: return(KingAttackedLocations(attacker)); default: return(new List <IGridLocation>()); } }
public IEnumerable <Move> AvailableMovesFromSquare(ISquare mover) { if (mover.Type == PieceType.None) { throw new Exception("MoveDestinations was called with an empty square as the mover."); } switch (mover.Type) { case PieceType.Pawn: return(PawnMoves(mover)); case PieceType.Knight: return(KnightMoves(mover)); case PieceType.Bishop: return(BishopMoves(mover)); case PieceType.Rook: return(RookMoves(mover)); case PieceType.Queen: return(QueenMoves(mover)); case PieceType.King: return(KingMoves(mover)); default: return(new List <Move>()); } }
public static void SetDebugInfo <T>(IRequest <T> request, T response, ISquare square) where T : IResponse { if (request.Debug) { response.DebugInfo = GetChessListDebugInfo(square); } }
private void drawBorders(ISquare square) { var slice = Slice.ToPercentage(_width, _height); var width = Width.ToPixels(_width, _height); var outset = Outset.ToPixels(_width, _height); float farLeft = square.TopLeft.X - outset.Left.Value; float farRight = square.TopRight.X + outset.Right.Value; float farTop = square.TopLeft.Y + outset.Top.Value; float farBottom = square.BottomLeft.Y - outset.Bottom.Value; SliceValues border = new SliceValues(SliceMeasurement.Pixels, farLeft, farRight, farTop, farBottom); drawCorners(border, slice, width); switch (Repeat) { case BorderRepeat.Repeat: case BorderRepeat.Round: case BorderRepeat.Space: drawEdges(border, slice, width, Repeat); break; case BorderRepeat.Stretch: drawStretch(border, slice, width); break; default: throw new NotSupportedException(Repeat.ToString()); } }
public void RenderBorderBack(ISquare square) { if (DrawBorderBehind) { drawBorders(square); } }
public void RenderBorderBack(ISquare square) { runAnimation(); if (!FillBackground) { return; } var slice = Slice.ToPercentage(_width, _height); var width = Width.ToPixels(_width, _height); var outset = Outset.ToPixels(_width, _height); float farLeft = square.TopLeft.X - outset.Left.Value; float farRight = square.TopRight.X + outset.Right.Value; float farTop = square.TopLeft.Y + outset.Top.Value; float farBottom = square.BottomLeft.Y - outset.Bottom.Value; var quad = new AGSSquare(new PointF(farLeft + width.Left.Value, farBottom + width.Bottom.Value), new PointF(farRight - width.Right.Value, farBottom + width.Bottom.Value), new PointF(farLeft + width.Left.Value, farTop - width.Top.Value), new PointF(farRight - width.Right.Value, farTop - width.Top.Value)); drawQuad(quad, new FourCorners <Vector2> (new Vector2(slice.Left.Value, slice.Bottom.Value), new Vector2(1f - slice.Right.Value, slice.Bottom.Value), new Vector2(slice.Left.Value, 1f - slice.Top.Value), new Vector2(1f - slice.Right.Value, 1f - slice.Top.Value))); if (DrawBorderBehind) { drawBorders(square); } }
public void RenderBorderBack(ISquare square) { if (_glUtils.DrawQuad(_frameBuffer, square, _quad)) { return; } float width = _settings.VirtualResolution.Width; float height = _settings.VirtualResolution.Height; float foldWidth = (width) * (1f / 5f); float foldHeight = (height) * (1f / 5f); IGLColor color = IsSelected ? _selectedColor : _color; IGLColor foldColor = IsSelected ? _selectedFoldColor : _foldColor; Vector3 foldBottomLeft = new Vector3(width - foldWidth, foldHeight, 0); Vector3 foldTopLeft = new Vector3(width - foldWidth, 0, 0); Vector3 foldTopRight = new Vector3(width, foldHeight, 0); _frameBuffer = _glUtils.BeginFrameBuffer(square, _settings); _glUtils.DrawQuad(0, new Vector3(0f, height, 0), new Vector3(width - foldWidth, height, 0), new Vector3(), foldTopLeft, color, color, color, color); _glUtils.DrawQuad(0, new Vector3(width - foldWidth, height, 0), new Vector3(width, height, 0), foldBottomLeft, foldTopRight, color, color, color, color); _glUtils.DrawTriangle(0, new GLVertex[] { new GLVertex(foldBottomLeft.Xy, _emptyVector, foldColor), new GLVertex(foldTopLeft.Xy, _emptyVector, foldColor), new GLVertex(foldTopRight.Xy, _emptyVector, foldColor) }); _frameBuffer.End(); _glUtils.DrawQuad(_frameBuffer, square, _quad); }
private void Builder(object sender, RoutedEventArgs e) { Builder builder = new ComplexObjectBuilder(); builder.CreateComplexObject(); builder.SetCircle(); builder.SetSquare(); ICircle circle = builder.ComplexObject.Circle; ISquare square = builder.ComplexObject.Square; Rectangle rect = new Rectangle() { Fill = new SolidColorBrush(square.GetSqureColor()), Height = square.GetSideSize(), Width = square.GetSideSize() }; Ellipse el = new Ellipse() { Fill = new SolidColorBrush(circle.GetCirleColor()), Height = circle.GetRadius() * 2, Width = circle.GetRadius() * 2 }; Grid grid = new Grid(); grid.Children.Add(rect); grid.Children.Add(el); Canvas.SetLeft(grid, 10); Canvas.SetTop(grid, y); canvas.Children.Add(grid); y += rect.Height + 5; }
private Grid SetGridParameters(Grid grid, IList <ISquare> squares, int numOfCols) { for (int i = 0; i < grid.RowDefinitions.Count; i++) { // Generate a row X amount of times with Y amount of columns ISquare[] squaresInRow = squares.Skip(i * numOfCols).Take(numOfCols).ToArray(); for (int j = 0; j < grid.ColumnDefinitions.Count; j++) { var cellPanel = new Grid(); ISquare square = squaresInRow[j]; cellPanel.Children.Add(GenerateLabel(square)); // Add players on field if any are in List if (_gameboard.Players.Any()) { var playerPanel = GeneratePlayerIcon(_gameboard.Players, square); cellPanel.Children.Add(playerPanel); } Grid.SetRow(cellPanel, i); Grid.SetColumn(cellPanel, j); grid.Children.Add(cellPanel); } } return(grid); }
public bool CollidesWith(float x, float y) { ISquare boundingBox = BoundingBox; if (boundingBox == null) { return(false); } IArea pixelPerfect = _pixelPerfect.PixelPerfectHitTestArea; if (_drawableInfo.IgnoreViewport && _state != null) { var viewport = _state.Room.Viewport; //todo: Support viewport rotation (+ ignore scaling areas = false?) x = (x - viewport.X) * viewport.ScaleX; y = (y - viewport.Y) * viewport.ScaleY; } if (pixelPerfect == null || !pixelPerfect.Enabled) { if (boundingBox.Contains(new PointF(x, y))) { return(true); } } else { if (pixelPerfect.IsInArea(new PointF(x, y), boundingBox, _scale.ScaleX * _obj.Animation.Sprite.ScaleX, _scale.ScaleY * _obj.Animation.Sprite.ScaleY)) { return(true); } } return(false); }
private StackPanel GeneratePlayerIcon(IList <IPlayer> players, ISquare square) { var playerPanel = new StackPanel() { Orientation = Orientation.Horizontal }; foreach (IPlayer player in players) { if (player.Position != square.Id) { break; } var pawnImage = new Image { Source = new BitmapImage(new Uri(player.Pawn)), Height = 50, Width = 50, }; playerPanel.Children.Add(pawnImage); } return(playerPanel); }
public static void MakeMove(IBoard board, IPiece piece, ISquare targetSquare) { piece.Location.Occupant = null; piece.Location = targetSquare; targetSquare.Occupant = piece; CheckCapture(board, targetSquare); }
private bool TryGetSquareToFlag(ISquare neighbor, Direction direction1, Direction direction2, out ISquare squareToFlag) { squareToFlag = null; (int x, int y)blankCheckIdx1 = GetNext(this.square.Index, direction1), blankCheckIdx2 = GetNext(blankCheckIdx1, direction2); var tempSquare = this.MapHandler.GetSquare(blankCheckIdx1); if (tempSquare == null || !tempSquare.IsBlank) { return(false); } tempSquare = this.MapHandler.GetSquare(blankCheckIdx2); if (!tempSquare.IsBlank) { return(false); } var neighborsBlanks = this.MapHandler.GetAdjacentBlanks(neighbor); if (neighborsBlanks.Length > 3) { return(false); } squareToFlag = neighborsBlanks.Single(sq => sq.Index != blankCheckIdx1 && sq.Index != blankCheckIdx2); return(true); }
private void drawBorders(ISquare square) { var slice = Slice.ToPercentage(_width, _height); var width = Width.ToPixels(_width, _height); var outset = Outset.ToPixels(_width, _height); float farLeft = square.TopLeft.X - outset.Left.Value; float farRight = square.TopRight.X + outset.Right.Value; float farTop = square.TopLeft.Y + outset.Top.Value; float farBottom = square.BottomLeft.Y - outset.Bottom.Value; SliceValues border = new SliceValues (SliceMeasurement.Pixels, farLeft, farRight, farTop, farBottom); drawCorners(border, slice, width); switch (Repeat) { case BorderRepeat.Repeat: case BorderRepeat.Round: case BorderRepeat.Space: drawEdges(border, slice, width, Repeat); break; case BorderRepeat.Stretch: drawStretch(border, slice, width); break; default: throw new NotSupportedException (Repeat.ToString()); } }
public void CheckEnPassant(IPawn pawn, ISquare squaresToMove) { ISquare firstAdjacentSquare = null; ISquare secondAdjacentSquare = null; bool firstCondition = false; bool secondCondition = false; if (squaresToMove.Position.file != 'a') { firstAdjacentSquare = Squares[char.ConvertFromUtf32(squaresToMove.Position.file - 1) + char.GetNumericValue(squaresToMove.Position.rank)]; firstCondition = firstAdjacentSquare.Occupied && firstAdjacentSquare.Piece is IPawn && firstAdjacentSquare.Piece.Player != pawn.Player; } if (squaresToMove.Position.file != 'h') { secondAdjacentSquare = Squares[char.ConvertFromUtf32(squaresToMove.Position.file + 1) + char.GetNumericValue(squaresToMove.Position.rank)]; secondCondition = secondAdjacentSquare.Occupied && secondAdjacentSquare.Piece is IPawn && secondAdjacentSquare.Piece.Player != pawn.Player; } if (firstCondition || secondCondition) { IPawn adjacentPawn = firstCondition ? firstAdjacentSquare.Piece as IPawn : secondAdjacentSquare.Piece as IPawn; ISquare square = pawn.Player.IsPlayer == "Two" ? Squares[squaresToMove.Position.file.ToString() + (char.GetNumericValue(squaresToMove.Position.rank) + 1)] : Squares[squaresToMove.Position.file.ToString() + (char.GetNumericValue(squaresToMove.Position.rank) - 1)]; adjacentPawn.EnPassant = (pawn, square); } }
public EnPassantEnablingMove(ISquare fromSquare, ISquare toSquare, IPiece movingPiece, ISquare enPassantSquare) { FromSquare = fromSquare; ToSquare = toSquare; MovingPiece = movingPiece; EnPassantSquare = enPassantSquare; }
public CastlingMove(Piece king, ISquare from, ISquare to, Piece rook,ISquare castlingRookFrom, ISquare castlingRookTo,int ply) : base(king, from, to, null,ply) { CastlingRook = rook; CastlingRookFrom = castlingRookFrom; CastlingRookTo = castlingRookTo; }
public NormalMove(Piece piece, ISquare from, ISquare to, Piece capture, int ply) { Piece = piece; Ply = ply; _from = from; _to = to; _capture = capture; }
/// <summary> /// Initializes a new instance of the <see cref="Square"/> class. /// </summary> /// <param name="switched"> /// The switched. /// </param> /// <param name="north"> /// The north. /// </param> /// <param name="south"> /// The south. /// </param> /// <param name="east"> /// The east. /// </param> /// <param name="west"> /// The west. /// </param> public Square(bool switched, ISquare north, ISquare south, ISquare east, ISquare west) { this.Switched = switched; this.north = north; this.south = south; this.west = west; this.east = east; }
public IEnumerable<ISquare> GetCellsByDirections(ISquare square, IEnumerable<IDirection> directions, int distance) { var result = new List<ISquare>(); foreach (var direction in directions) { result.AddRange(GetCellsByDirection(square, direction, distance)); } return result; }
public void AddSquare(ISquare square) { if (next <= max) { this.squares[next] = square; next++; } else throw new ApplicationException("Not enough room for this square!"); }
public bool IsMasked(PointF point, ISquare projectionBox, float scaleX, float scaleY) { float leftX = scaleX >= 0f ? projectionBox.BottomLeft.X : projectionBox.BottomRight.X; float rightX = scaleX >= 0f ? projectionBox.BottomRight.X : projectionBox.BottomLeft.X; float bottomY = scaleY >= 0f ? projectionBox.BottomLeft.Y : projectionBox.TopLeft.Y; float topY = scaleY >= 0f ? projectionBox.TopLeft.Y : projectionBox.BottomLeft.Y; float x = MathUtils.Lerp(leftX, 0, rightX, Width - 1, point.X); float y = MathUtils.Lerp(bottomY, 0, topY, Height - 1, point.Y); return IsMasked(new PointF (x, y)); }
/// <summary> /// Fills Grid with ISquares of same type. /// </summary> /// <param name="squareType">The kind of ISquare.</param> /// <param name="gridLenght">How "long" the grid has to be.</param> /// <param name="gridBreath">How "wide" the grid has to be.</param> public Grid(ISquare squareType, int gridLenght, int gridBreath) { var numberOfSquares = ((gridLenght + 2) * (gridBreath + 2)); for (var i = 0; i < numberOfSquares; i++) { _savanna.Add(squareType); } _gridSize = _savanna.Count(); }
public IEnumerable<ISquare> GetCellsByDirection(ISquare square, IDirection direction, int distance) { ISquare newSquare = AddDirection(square, direction); int n = 0; while (IsLegal(newSquare) && (n < distance || distance == 0)) { yield return newSquare; newSquare = AddDirection(newSquare, direction); n++; } }
private void SetSquare () { if(squareType == SquareType.Simple) square = new SimpleSquare (); else if(squareType == SquareType.Reward) square = new RewardSquare (); else if( squareType == SquareType.MoveBackwards) square = new SquareMoveBackwards (moveSquares,squareToGo); else if( squareType == SquareType.MoveForwards) square = new SquareMoveForwards (moveSquares,squareToGo); else square = new SpecialSquare (); }
public void RenderBorderBack(ISquare square) { IGLColor color = IsSelected ? _selectedColor : _color; IGLColor foldColor = IsSelected ? _selectedFoldColor : _foldColor; _glUtils.DrawQuad(0, square.BottomLeft.ToVector3(), square.BottomRight.ToVector3(), square.TopLeft.ToVector3(), square.TopRight.ToVector3(), color, color, color, color); float foldHeight = (square.MaxY - square.MinY) * (1f / 5f); PointF foldBottom = new PointF((square.TopLeft.X + square.TopRight.X) / 2f, square.TopLeft.Y - foldHeight); _glUtils.DrawTriangleFan(0, new GLVertex[] { new GLVertex(square.TopLeft.ToVector2(), _emptyVector, foldColor), new GLVertex(foldBottom.ToVector2(), _emptyVector, foldColor), new GLVertex(square.TopRight.ToVector2(), _emptyVector, foldColor)}); }
private void drawBorders(ISquare square) { FourCorners<IGLColor> colors = Color.Convert(c => c.ToGLColor()); float farLeft = square.TopLeft.X - LineWidth; float farRight = square.TopRight.X + LineWidth; float farTop = square.TopLeft.Y + LineWidth; float farBottom = square.BottomLeft.Y - LineWidth; AGSSquare border = new AGSSquare (new PointF (farLeft, farBottom), new PointF (farRight, farBottom), new PointF (farLeft, farTop), new PointF (farRight, farTop)); float topQuadBottomY = square.TopLeft.Y; float topQuadLeftX = HasRoundCorner.TopLeft ? square.TopLeft.X : farLeft; float topQuadRightX = HasRoundCorner.TopRight ? square.TopRight.X : farRight; AGSSquare topQuad = new AGSSquare (new PointF (topQuadLeftX, topQuadBottomY), new PointF (topQuadRightX, topQuadBottomY), new PointF (topQuadLeftX, farTop), new PointF (topQuadRightX, farTop)); float bottomQuadTopY = square.BottomLeft.Y; float bottomQuadLeftX = HasRoundCorner.BottomLeft ? square.BottomLeft.X : farLeft; float bottomQuadRightX = HasRoundCorner.BottomRight ? square.BottomRight.X : farRight; AGSSquare bottomQuad = new AGSSquare (new PointF (bottomQuadLeftX, farBottom), new PointF (bottomQuadRightX, farBottom), new PointF (bottomQuadLeftX, bottomQuadTopY), new PointF (bottomQuadRightX, bottomQuadTopY)); float horizQuadTop = square.TopLeft.Y; float horizQuadBottom = square.BottomLeft.Y; float leftQuadRightX = square.BottomLeft.X; AGSSquare leftQuad = new AGSSquare (new PointF (farLeft, horizQuadBottom), new PointF (leftQuadRightX, horizQuadBottom), new PointF (farLeft, horizQuadTop), new PointF (leftQuadRightX, horizQuadTop)); float rightQuadLeftX = square.BottomRight.X; AGSSquare rightQuad = new AGSSquare (new PointF (rightQuadLeftX, horizQuadBottom), new PointF (farRight, horizQuadBottom), new PointF (rightQuadLeftX, horizQuadTop), new PointF (farRight, horizQuadTop)); if (HasRoundCorner.TopLeft) drawRoundCorner(square.TopLeft, LineWidth, 270f, border, colors); if (HasRoundCorner.TopRight) drawRoundCorner(square.TopRight, LineWidth, 0f, border, colors); if (HasRoundCorner.BottomLeft) drawRoundCorner(square.BottomLeft, LineWidth, 180f, border, colors); if (HasRoundCorner.BottomRight) drawRoundCorner(square.BottomRight, LineWidth, 90f, border, colors); drawQuad(topQuad, border, colors); drawQuad(bottomQuad, border, colors); drawQuad(leftQuad, border, colors); drawQuad(rightQuad, border, colors); }
public void RenderBorderBack(ISquare square) { float width = square.MaxX - square.MinX; float height = square.MaxY - square.MinY; float arrowWidth = width * (1f/2f); float arrowHeight = height * (1f/2f); float remainingWidth = width - arrowWidth; float remainingHeight = height - arrowHeight; PointF point1, point2, point3; switch (Direction) { case ArrowDirection.Right: point1 = square.TopLeft + new PointF(remainingWidth / 2f, -remainingHeight / 2f); point2 = square.BottomLeft + new PointF(remainingWidth / 2f, remainingHeight / 2f); point3 = square.BottomRight + new PointF(-remainingWidth / 2f, height / 2f); break; case ArrowDirection.Down: point1 = square.TopLeft + new PointF(remainingWidth / 2f, -remainingHeight / 2f); point2 = square.BottomLeft + new PointF(width / 2f, remainingHeight / 2f); point3 = square.TopRight + new PointF(-remainingWidth / 2f, -remainingHeight / 2f); break; case ArrowDirection.Left: point1 = square.TopRight + new PointF(-remainingWidth / 2f, -remainingHeight / 2f); point2 = square.BottomRight + new PointF(-remainingWidth / 2f, remainingHeight / 2f); point3 = square.BottomLeft + new PointF(remainingWidth / 2f, height / 2f); break; case ArrowDirection.Up: point1 = square.TopLeft + new PointF(width / 2f, -remainingHeight / 2f); point2 = square.BottomLeft + new PointF(remainingWidth / 2f, remainingHeight / 2f); point3 = square.BottomRight + new PointF(-remainingWidth / 2f, remainingHeight / 2f); break; default: throw new NotSupportedException(Direction.ToString()); } _glUtils.DrawTriangleFan(0, new GLVertex[] { new GLVertex(point1.ToVector2(), _emptyVector, ArrowColor), new GLVertex(point2.ToVector2(), _emptyVector, ArrowColor), new GLVertex(point3.ToVector2(), _emptyVector, ArrowColor)}); }
public void RenderBorderBack(ISquare square) { float foldWidth = (square.MaxX - square.MinX) * (1f / 5f); float foldHeight = (square.MaxY - square.MinY) * (1f / 5f); IGLColor color = IsSelected ? _selectedColor : _color; IGLColor foldColor = IsSelected ? _selectedFoldColor : _foldColor; PointF foldBottomLeft = square.TopRight - new PointF(foldWidth, foldHeight); PointF foldTopLeft = square.TopRight - new PointF(foldWidth, 0f); PointF foldTopRight = square.TopRight - new PointF(0f, foldHeight); _glUtils.DrawQuad(0, square.BottomLeft.ToVector3(), (square.BottomRight - new PointF(foldWidth, 0f)).ToVector3(), square.TopLeft.ToVector3(), foldTopLeft.ToVector3(), color, color, color, color); _glUtils.DrawQuad(0, (square.BottomRight - new PointF(foldWidth, 0f)).ToVector3(), square.BottomRight.ToVector3(), foldBottomLeft.ToVector3(), foldTopRight.ToVector3(), color, color, color, color); _glUtils.DrawTriangleFan(0, new GLVertex[] { new GLVertex(foldBottomLeft.ToVector2(), _emptyVector, foldColor), new GLVertex(foldTopLeft.ToVector2(), _emptyVector, foldColor), new GLVertex(foldTopRight.ToVector2(), _emptyVector, foldColor)}); }
private NormalMove GetEnPassantMove(ISquare enPassantSquare, ISquare destinationSquare, int ply) { if (Square.Rank != _startRank + (MoveForward*3)) return null; if (Board.GetSquareStatus(enPassantSquare) != SquareStatus.Occupied) return null; var piece = Board.GetPieceOn(enPassantSquare) as Pawn; if (piece == null || piece.Moves.Count <= 0) return null; var lastMove = piece.Moves.Last(); if (lastMove is PawnDoubleMove && lastMove.Ply==ply-1) return new EnPassantMove(this,Square,destinationSquare,piece,ply); return null; }
private NormalMove GetCaptureMove(ISquare toCheck,int ply) { if (Board.GetSquareStatus(toCheck) == SquareStatus.Occupied) { var piece = Board.GetPieceOn(toCheck); if (piece.Color != Color) return new NormalMove(this, Square, toCheck, piece, ply); } return null; }
private void drawQuad(ISquare quad, ISquare border, FourCorners<IGLColor> colors) { GLColor bottomLeftColor = getColor(colors, border, quad.BottomLeft); GLColor bottomRightColor = getColor(colors, border, quad.BottomRight); GLColor topRightColor = getColor(colors, border, quad.TopRight); GLColor topLeftColor = getColor(colors, border, quad.TopLeft); _glUtils.DrawQuad(0, quad.BottomLeft.ToVector3(), quad.BottomRight.ToVector3(), quad.TopLeft.ToVector3(), quad.TopRight.ToVector3(), bottomLeftColor, bottomRightColor, topLeftColor, topRightColor); }
public void RenderBorderFront(ISquare square) { if (!DrawBorderBehind) drawBorders(square); }
public bool IsInArea(PointF point, ISquare projectionBox, float scaleX, float scaleY) { return _areaComponent.IsInArea(point, projectionBox, scaleX, scaleY); }
private GLColor getColor(FourCorners<IGLColor> colors, ISquare border, PointF point) { return getColor(colors, MathUtils.Lerp(border.BottomLeft.X, 0f, border.BottomRight.X, 1f, point.X), MathUtils.Lerp(border.BottomRight.Y, 0f, border.TopRight.Y, 1f, point.Y)); }
private void drawRoundCorner(PointF center, float radius, float angle, ISquare border, FourCorners<IGLColor> colors) { Vector2 tex = new Vector2 (); GLVertex centerVertex = new GLVertex (center.ToVector2(), tex, getColor(colors, border, center)); _roundCorner[0] = centerVertex; float step = (90f / (_roundCorner.Length - 2)); for (int i = 1; i < _roundCorner.Length; i++) { float anglerad = (float)Math.PI * angle / 180.0f; float x = (float)Math.Sin(anglerad) * radius; float y = (float)Math.Cos(anglerad) * radius; angle += step; PointF point = new PointF (x + center.X, y + center.Y); _roundCorner[i] = new GLVertex (point.ToVector2(), tex, getColor(colors, border, point)); } _glUtils.DrawTriangleFan(0, _roundCorner); }
public EnPassantMove(Piece piece, ISquare from, ISquare to, Piece capture, int ply) : base(piece, @from, to, capture,ply) { }
private bool IsLegal(ISquare square) { return square.X >= 1 && square.X <= BoardSize && square.Y >= 1 && square.Y <= BoardSize; }
private Cell GetCell(ISquare square) { return _cells.SingleOrDefault(c => c.IsEqualTo(square)); }
public bool SquareIsEmpty(ISquare square) { return !_cells.Any(c => c.IsEqualTo(square)); }
public bool SquareIsColor(ISquare square, PieceColor color) { var cell = GetCell(square); return cell != null && cell.Color == color; }
public void RenderBorderBack(ISquare square) { if (DrawBorderBehind) drawBorders(square); }
public ConstructorSelectorTestModel(ISquare square) { }
public PawnDoubleMove(Piece piece, ISquare from, ISquare to, int ply) : base(piece, from, to, null, ply) { }