예제 #1
0
파일: Storage.cs 프로젝트: vanBras/Chess1
 public Storage(Point point, EPieceType type, EColor color)
 {
     Point = point;
     Type  = type;
     Color = color;
     Taken = false;
 }
예제 #2
0
    /// <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();
    }
예제 #3
0
 /// <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;
 }
예제 #4
0
 public CellStatusViewModel(int identifier, EFieldType fieldType, EPieceType pieceType, EPieceColor pieceColor)
 {
     _identifier = identifier;
     _fieldType  = fieldType;
     _pieceType  = pieceType;
     _pieceColor = pieceColor;
 }
예제 #5
0
        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;
        }
예제 #6
0
파일: BitBoard.cs 프로젝트: Lawlets/ChessAI
        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);
        }
예제 #7
0
 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));
 }
예제 #8
0
파일: BitBoard.cs 프로젝트: Lawlets/ChessAI
        public BitBoardIndex GetBitBoardIndex(EChessTeam team, EPieceType piece)
        {
            if (team == EChessTeam.None)
            {
                return(BitBoardIndex.NONE);
            }

            return(EPieceTypeToBitBoardIndex(piece, team));
        }
예제 #9
0
 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);
 }
예제 #10
0
 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)
     });
 }
예제 #11
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;
        }
예제 #12
0
    /// <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));
    }
예제 #13
0
파일: BitBoard.cs 프로젝트: Lawlets/ChessAI
        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));
        }
예제 #14
0
        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}")
     });
예제 #16
0
        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;
        }
예제 #17
0
 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);
 }
예제 #18
0
        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);
        }
예제 #19
0
        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);
            }
        }
예제 #20
0
        /// <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);
        }
예제 #21
0
        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]);
        }
예제 #23
0
        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]);
        }
예제 #24
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);
            }
        }
예제 #25
0
파일: BitBoard.cs 프로젝트: Lawlets/ChessAI
        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));
            }
        }
예제 #26
0
 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++;
                }
            }
        }
예제 #28
0
    /// <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);
    }
예제 #29
0
    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));
        }
    }
예제 #30
0
        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());
        }