public Storage(Point point, EPieceType type, EColor color) { Point = point; Type = type; Color = color; Taken = false; }
/// <summary> /// Invoked whenever a capture is attempted during the Strategy phase. /// Creates the Capture data and switches to the Action portion of the game. /// </summary> /// <param name="move">The move that generated this capture attempt</param> private void OnCaptureAttempted(Move move) { EPieceType light = EPieceType.None; EPieceType dark = EPieceType.None; // Determine pieces with heuristic where From is always the current team's moving piece switch (StrategyGame.Instance.TurnState) { case ETeam.Light: light = GameBoard.Instance[move.From]; dark = GameBoard.Instance[move.To]; break; case ETeam.Dark: dark = GameBoard.Instance[move.From]; light = GameBoard.Instance[move.To]; break; } // Create final capture data for action portion Capture = new CaptureData(move, light, dark, (int)StrategyGame.Instance.TurnState); // Begin switch to Action portion SwitchToAction(); }
/// <summary> /// Constructor /// </summary> /// <param name="captureMove">The move that generated this capture</param> /// <param name="light">The light piece in the capture event</param> /// <param name="dark">The dark piece in the capture event</param> /// <param name="turn">Which team's turn is it</param> public CaptureData(Move captureMove, EPieceType light, EPieceType dark, int turn) { CaptureMove = captureMove; LightPiece = light; DarkPiece = dark; Turn = turn; }
public CellStatusViewModel(int identifier, EFieldType fieldType, EPieceType pieceType, EPieceColor pieceColor) { _identifier = identifier; _fieldType = fieldType; _pieceType = pieceType; _pieceColor = pieceColor; }
public void Promote(EPieceType type) { Debug.Assert(Type == EPieceType.PAWN, "You cannot use this method except for Pawn."); Debug.Assert(type != EPieceType.PAWN, "Pawn cannot promote to Pawn."); Type = type; }
public void PromoteTo(int pos, EPieceType piece) { EChessTeam color = GetColorFromPos(pos); PieceData data = GetPieceFromPos(pos, color); SetBitValue(EPieceTypeToBitBoardIndex(data.piece, color), pos, false); SetBitValue(EPieceTypeToBitBoardIndex(piece, color), pos, true); }
public static CPiece Create(Int32 id, EPieceType pieceType, EPieceColor pieceColor, CTile tile) { return(new CPiece( id, new BitmapImage(new Uri($"/Images/{pieceColor}/{pieceType}.png", UriKind.RelativeOrAbsolute)), SMovementValidatorFactory.GetMovementValidator(pieceType), pieceColor, tile)); }
public BitBoardIndex GetBitBoardIndex(EChessTeam team, EPieceType piece) { if (team == EChessTeam.None) { return(BitBoardIndex.NONE); } return(EPieceTypeToBitBoardIndex(piece, team)); }
public void SetPieceAtSquare(int index, EChessTeam team, EPieceType piece) { BitBoard.BitBoardIndex tmpIndex = bitBoard.GetBitBoardIndex(team, piece); if (tmpIndex != BitBoard.BitBoardIndex.NONE) { bitBoard.SetBitValue(tmpIndex, index, true); } bitBoard.SetBitValue(BitBoard.BitBoardIndex.FREE_CASE, index, false); bitBoard.SetBitValue(BitBoard.BitBoardIndex.OCCUPED_CASE, index, true); }
private static Image CreatePieceImage(EPieceColor color, EPieceType type, CTile tile) { return(new Image { Source = new BitmapImage(new Uri($"/Images/{color}/{type}.png", UriKind.RelativeOrAbsolute)), Width = CPiece.PieceSize, Height = CPiece.PieceSize, Margin = new Thickness(tile.X * CPiece.PieceSize, tile.Y * CPiece.PieceSize, 0, 0) }); }
// Add a piece during gameplay - used for pawn promotion public void AddPiece(EPieceType type) { GameObject[] pieces = new GameObject[pieceTypeDict[type].Length + 1]; for (int i = 0; i < pieceTypeDict[type].Length; i++) { pieces[i] = pieceTypeDict[type][i]; } pieceTypeDict[type] = pieces; }
/// <summary> /// Returns whether or not a piece is at the location specified. /// Checks a square in a direction relative to the index provided. /// Only returns true if the pieceType and pieceColor match. /// </summary> /// <param name="index">The index to check for a piece at</param> /// <param name="pieceType">The type of the piece we are checking for</param> /// <param name="direction">The direction we are looking in</param> /// <returns>True if there is a specific piece in the specified direction, else false</returns> public bool PieceAt(int index, EPieceType pieceType, EDirection direction) { // Save the row and column for processing and prepare new index int row = Row(index); int col = Col(index); int newIndex = -1; // Find the new index and check if a piece is there switch (direction) { case EDirection.North: newIndex = IndexFromRowAndCol(row + 1, col); break; case EDirection.South: newIndex = IndexFromRowAndCol(row - 1, col); break; case EDirection.East: newIndex = IndexFromRowAndCol(row, col + 1); break; case EDirection.West: newIndex = IndexFromRowAndCol(row, col - 1); break; case EDirection.Northeast: newIndex = IndexFromRowAndCol(row + 1, col + 1); break; case EDirection.Northwest: newIndex = IndexFromRowAndCol(row + 1, col - 1); break; case EDirection.Southeast: newIndex = IndexFromRowAndCol(row - 1, col + 1); break; case EDirection.Southwest: newIndex = IndexFromRowAndCol(row - 1, col - 1); break; default: newIndex = index; break; } if (!TileExists(newIndex)) { return(false); } return(board[newIndex] != PTAsInt(EPieceType.None) && board[newIndex] == PTAsInt(pieceType)); }
public BitBoardIndex EPieceTypeToBitBoardIndex(EPieceType piece, EChessTeam team) { if (team == EChessTeam.None) { throw new ArgumentException("team", team.ToString()); } string s_team = (team == EChessTeam.White) ? "WHITE_" : "BLACK_"; s_team += piece.ToString(); return((BitBoardIndex)Enum.Parse(typeof(BitBoardIndex), s_team.ToUpper(), true)); }
public ICardModel NewCardModel(IPlayerModel owner, EPieceType type) { var template = GetCardTemplate(type); if (template == null) { Error($"Failed to find card template {type} for {owner}"); return(null); } return(Registry.New <ICardModel>(owner, template)); }
public static CMovementValidator GetMovementValidator(EPieceType type) { return(type switch { EPieceType.Pawn => PawnMovementValidator, EPieceType.Knight => KnightMovementValidator, EPieceType.Bishop => BishopMovementValidator, EPieceType.Rook => RookMovementValidator, EPieceType.Queen => QueenMovementValidator, EPieceType.King => KingMovementValidator, _ => throw new InvalidEnumArgumentException($"Unknown piece type: {type}") });
private void SetPieceAtSquare(int index, EChessTeam team, EPieceType piece) { if (index > Squares.Count) { return; } BoardSquare square = Squares[index]; square.Piece = piece; square.Team = team; Squares[index] = square; }
public static BitBoard GetAttacks(this Square square, EPieceType pieceType, BitBoard occupied = new BitBoard()) { return(pieceType == EPieceType.Knight || pieceType == EPieceType.King ? PseudoAttacksBB[pieceType.AsInt(), square.AsInt()] : pieceType == EPieceType.Bishop ? square.BishopAttacks(occupied) : pieceType == EPieceType.Rook ? square.RookAttacks(occupied) : pieceType == EPieceType.Queen ? square.QueenAttacks(occupied) : Zero); }
protected ICardModel GetCardFromHand(EPieceType type) { var card = Hand.Cards.FirstOrDefault(c => c.PieceType == type); if (card == null) { Error($"Don't have a {type} in hand!"); return(null); } Hand.Remove(card); return(card); }
public void AddPiece(EPieceType pieceType, Square square, Player side) { var piece = pieceType.MakePiece(side); BoardPieces[piece.AsInt()] |= square; OccupiedBySide[side.Side] |= square; BoardLayout[square.AsInt()] = piece; if (!IsProbing) { PieceUpdated?.Invoke(piece, square); } }
/// <summary> /// Adds a piece to the board, and updates the hash keys if needed /// </summary> /// <param name="square">The square for the piece</param> /// <param name="side">For which side the piece is to be added</param> /// <param name="pieceType">The type of piece to add</param> private void AddPiece(Square square, Player side, EPieceType pieceType) { Piece piece = (int)pieceType | (side << 3); Position.AddPiece(piece, square); State.Key ^= piece.GetZobristPst(square); if (pieceType == EPieceType.Pawn) { State.PawnStructureKey ^= piece.GetZobristPst(square); } State.Material.Add(piece); }
public MoveResults GetMovements(Coord coord, EPieceType type) { var max = Math.Max(Width, Height); switch (type) { case EPieceType.King: return(GetMoveResults(coord, 1, _surrounding)); case EPieceType.Peon: return(GetMoveResults(coord, 1, _orthogonals)); case EPieceType.Archer: return(GetMoveResults(coord, max, _diagnonals)); case EPieceType.Gryphon: return(GetMoveResults(coord, 1, _knightMoves)); case EPieceType.Queen: return(GetMoveResults(coord, max, _orthogonals.Concat(_diagnonals).ToArray())); case EPieceType.Siege: break; case EPieceType.Ballista: return(GetMoveResults(coord, 2, _orthogonals)); case EPieceType.Barricade: break; case EPieceType.None: break; case EPieceType.Paladin: break; case EPieceType.Priest: break; case EPieceType.Castle: return(GetMoveResults(coord, max, _orthogonals)); case EPieceType.Dragon: return(GetMoveResults(coord, 1, _diamond)); } return(null); }
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { EPieceType type = (EPieceType)values[0]; EPieceColor color = (EPieceColor)values[1]; if (type == EPieceType.Empty || color == EPieceColor.Empty) { return(null); } string resourceKey = ""; resourceKey += type.ToString(); resourceKey += color.ToString(); return(resourceDictionary[resourceKey]); }
public ICardTemplate GetCardTemplate(EPieceType pieceType) { var templates = Database.CardTemplates.OfType(pieceType).ToArray(); if (templates.Length == 0) { Error($"Failed to find card template of type {pieceType}"); return(null); } if (templates.Length > 1) { Warn($"Found {templates.Length} templates of type {pieceType} - using first found"); } return(templates[0]); }
public static BitBoard XrayAttacks(this Square square, EPieceType pieceType, BitBoard occupied, BitBoard blockers) { switch (pieceType) { case EPieceType.Bishop: return(square.XrayBishopAttacks(occupied, blockers)); case EPieceType.Rook: return(square.XrayRookAttacks(occupied, blockers)); case EPieceType.Queen: return(XrayBishopAttacks(square, occupied, blockers) | XrayRookAttacks(square, occupied, blockers)); default: return(EmptyBitBoard); } }
private void GetAllPiecesOfType(ref List <PieceData> list, long bitBoard, EPieceType piece, EChessTeam team) { int bitIndex = 0; int iterator = 0; while (bitIndex != -1) { FindFirstSetBit(bitBoard, ref bitIndex, ref iterator); if (bitIndex == -1) { return; } list.Add(new PieceData(piece, team, bitIndex)); } }
public CardTemplate(ECardType type, EPieceType pieceType, string name, int manaCost, int attack, int health, IEnumerable <EAbility> abilities = null, string flavourText = "") : base(null) { Type = type; PieceType = pieceType; Id = Guid.NewGuid(); Name = name; ManaCost = manaCost; Power = attack; Health = health; if (abilities != null) { Abilities = abilities.ToList(); } FlavourText = flavourText; }
private void generateCellViewModels(int rows, int cols) { int id = 0; for (int row = 0; row < rows; row++) { List <ICellStatusViewModel> colList = new List <ICellStatusViewModel>(); _cells.Add(colList); for (int col = 0; col < cols; col++) { EFieldType fieldType = ((row % 2) + col) % 2 == 0 ? EFieldType.Light : EFieldType.Dark; EPieceType pieceType = getPieceType(row, col); EPieceColor pieceColor = getPieceColor(row); colList.Add(new CellStatusViewModel(id, fieldType, pieceType, pieceColor)); id++; } } }
/// <summary> /// Checks if a move is valid on the board (based on game rules) /// </summary> /// <param name="type">The type of the piece</param> /// <param name="m">The move data</param> /// <returns>True if the move is valid, else false</returns> public bool ValidMove(EPieceType type, Move m) { // Checks if the move generated is strictly invalid if (m.Invalid) { return(false); } // Calls the correct child function based on the piece type switch (type) { // TODO: Remove this and add actual checks default: return(true); } return(false); }
void UpdatePieces() { teamPiecesArray[0].Hide(); teamPiecesArray[1].Hide(); for (int i = 0; i < boardState.Squares.Count; i++) { BoardSquare square = boardState.Squares[i]; if (square.Team == EChessTeam.None) { continue; } int teamId = (int)square.Team; EPieceType pieceType = square.Piece; teamPiecesArray[teamId].SetPieceAtPos(pieceType, GetWorldPos(i)); } }
public void TestAllBasicMove() { Square expectedFrom = ESquare.a2; Square expectedTo = ESquare.h8; const EPieceType expectedMovingPieceType = EPieceType.Pawn; Piece expectedMovingPiece = EPieces.WhitePawn; Piece expectedCapturedPiece = EPieces.BlackKnight; Piece expectedPromotionPiece = EPieces.WhiteQueen; const EMoveType expectedMoveType = EMoveType.Promotion; // full move spectrum var move = new Move(expectedMovingPiece, expectedCapturedPiece, expectedFrom, expectedTo, expectedMoveType, expectedPromotionPiece); var actualFrom = move.GetFromSquare(); var actualTo = move.GetToSquare(); var actualMovingEPieceType = move.GetMovingPieceType(); var actualMovingPiece = move.GetMovingPiece(); var actualCapturedPiece = move.GetCapturedPiece(); var actualPromotionPiece = move.GetPromotedPiece(); var actualEMoveType = move.GetMoveType(); // test promotion status Assert.True(move.IsPromotionMove()); Assert.True(move.IsQueenPromotion()); // test squares Assert.Equal(expectedFrom, actualFrom); Assert.Equal(expectedTo, actualTo); // test pieces Assert.Equal(expectedMovingPieceType, actualMovingEPieceType); Assert.Equal(expectedMovingPiece, actualMovingPiece); Assert.Equal(expectedCapturedPiece, actualCapturedPiece); Assert.Equal(expectedPromotionPiece, actualPromotionPiece); // move type Assert.Equal(expectedMoveType, actualEMoveType); Assert.False(move.IsCastlelingMove()); Assert.False(move.IsDoublePush()); Assert.False(move.IsEnPassantMove()); }