Esempio n. 1
0
        public bool CanApply(Position from, Position to, IGameState state, PieceTypes promoteTo)
        {
            if (state[from].Player.Order == 1 && to.Rank == 8 || state[from].Player.Order == 2 && to.Rank == 1)
                return BaseMove.CanApply(from, to, state) && CanPromoteToList.Contains(promoteTo);

            return false;
        }
        public GameObject CreateSquarePiece(PieceTypes type, bool initlalSetup)
        {
            var piece = ObjectPool.Instantiate(GameResources.GameObjects["Piece"], Vector3.zero);

            var squarePiece = piece.GetComponent <SquarePiece>();

            squarePiece.Type = type;

            var pieceBuilder = GetPieceBuilder(type, squarePiece);

            pieceBuilder.initialsetup = initlalSetup;
            pieceBuilder.scoreValue   = GetScoreValue(ref type);
            pieceBuilder.squarePiece  = squarePiece;
            pieceBuilder.BuildPiece();

            return(piece);
        }
        public static ISquarePiece ChangePiece(ISquarePiece piece, PieceTypes newPieceType)
        {
            GameResources.PlayEffect("Piece Change", piece.transform.position);

            var newPiece = Instance.CreateSquarePiece(newPieceType, false);

            newPiece.transform.position = piece.transform.position;
            newPiece.transform.parent   = piece.transform.parent;
            newPiece.GetComponent <SquarePiece>().Position = piece.Position;

            PieceManager.Instance.Pieces.Remove(piece);
            PieceManager.Instance.Pieces.Add(newPiece.GetComponent <SquarePiece>());

            piece.gameObject.SetActive(false);

            return(newPiece.GetComponent <SquarePiece>());
        }
Esempio n. 4
0
    public void DestroyPiece()
    {
        Destroy(piece.gameObject);

        var ActionPointComponent = GetComponent <ActionPointComponent>();

        if (ActionPointComponent)
        {
            ActionPointComponent.actualActionPoints = 0;
        }

        piece     = null;
        pieceType = PieceTypes.Nothing;

#if UNITY_EDITOR
        _pieceType = pieceType;
#endif
    }
Esempio n. 5
0
        /// <summary>
        /// Returns desired Piece object
        /// </summary>
        /// <param name="Type">Type of piece</param>
        /// <param name="color">Color for this piece. Only used in case of GUI output. Only in case block is generator</param>
        /// <param name="moves">Total moves, only if case block is a generator</param>
        public static Piece Build(PieceTypes Type, ConsoleColor color = ConsoleColor.Black, int moves = -1, int x = -1, int y = -1)
        {
            switch (Type)
            {
            case PieceTypes.SolidBlock:
                return(new Piece_SolidBlock());

            case PieceTypes.Generator:
                id++;
                return(new Piece_Generator(moves, id, x, y));

            case PieceTypes.Fillable:
                return(new Piece_Fillable());

            default:
                throw new Exception("Error fetching Piece type");
            }
        }
        private void GetPieceType(string triggerOn, string[] parts)
        {
            var type = parts[0];

            if (string.IsNullOrWhiteSpace(type))
            {
                PieceType = PieceTypes.Empty;
            }

            else if (!EnumHelpers.IsValue <PieceTypes>(type[0]))
            {
                throw new ArgumentException($"Invalid piece type specificed in trigger: {triggerOn}");
            }
            else
            {
                PieceType = (PieceTypes)type[0];
            }
        }
Esempio n. 7
0
    public void CreatePiece(PieceTypes newPieceTypes)
    {
        pieceType = newPieceTypes;

        if (piece != null)
        {
            DestroyImmediate(piece.gameObject);
        }

        if (pieceType != PieceTypes.Nothing)
        {
            Piece prefab = GridManager.Instance.GetPiecePrefab(pieceType);

            if (prefab != null)
            {
                piece = Instantiate(prefab, transform.position, prefab.transform.rotation, transform);
            }
        }
    }
Esempio n. 8
0
        private Score EvaluatePieces(PieceTypes pt, Player us)
        {
            var them = ~us;

            var pieces = _pos.Squares(pt, us);

            if (pieces.IsEmpty)
            {
                return(Score.Zero);
            }

            var result = Score.Zero;

            foreach (var square in pieces)
            {
            }

            return(result);
        }
Esempio n. 9
0
    private void OnDrawGizmos()
    {
        if (Application.isPlaying)
        {
            return;
        }

        if (pieceType != _pieceType)
        {
            CreatePiece(pieceType);
            _pieceType = pieceType;
        }

        if (groundType != _groundType)
        {
            CreateGround(groundType);
            _groundType = groundType;
        }
    }
Esempio n. 10
0
        public IConcreteMove GetPossibleMove(Position to, IGameState state, PieceTypes promotionTo)
        {
            foreach (ITemplateMove m in PossibleMoves)
            {
                if (m is Promotion)
                {
                    var p = m as Promotion;
                    if (p.CanApply(Pos, to, state, promotionTo))
                        return p.Concretize(Pos, to, promotionTo);
                }
                else
                {
                    if (m.CanApply(Pos, to, state))
                        return m.Concretize(Pos, to);
                }
            }

            return null;
        }
Esempio n. 11
0
 /// <summary>
 /// Decrements the value of the 'current' piece.
 /// </summary>
 /// <param name="currentPiece">Currently selected piece.</param>
 private static void RemovePiece(PieceTypes currentPiece)
 {
     if (currentPiece == PieceTypes.RedSquare)
     {
         P2Squares--;
     }
     else if (currentPiece == PieceTypes.RedCircle)
     {
         P2Circles--;
     }
     else if (currentPiece == PieceTypes.WhiteSquare)
     {
         P1Squares--;
     }
     else if (currentPiece == PieceTypes.WhiteCircle)
     {
         P1Circles--;
     }
 }
Esempio n. 12
0
        public void GenerateTiles(Vector2 Start, float tileSpacing)
        {
            LevelManager.Instance.SelectedLevel = LevelManager.Instance.GetNextLevel();

            string[] pattern = LevelManager.Instance.SelectedLevel.Pattern;

            int rows    = pattern.Length;
            int columns = pattern[0].Length;

            var YPositions = new float[rows];
            var XPositions = new float[columns];
            var pieces     = new List <ISquarePiece>(rows * columns);

            for (int x = 0; x < columns; x++)
            {
                for (int y = 0; y < rows; y++)
                {
                    float xPos = Start.x + (x * tileSpacing);
                    float yPos = Start.y - (y * tileSpacing);

                    YPositions[y] = yPos;
                    XPositions[x] = xPos;

                    string     row  = pattern[y];
                    PieceTypes type = (PieceTypes)row[x];

                    if (type == PieceTypes.Empty)
                    {
                        continue;
                    }

                    var piece = GenerateTile(type, xPos, yPos, x, y, true);

                    piece.transform.parent = GridParent;

                    pieces.Add(piece.GetComponent <SquarePiece>());
                }
            }
            PieceManager.Instance.Setup(pieces, XPositions, YPositions);

            GridGenerated?.Invoke();
        }
        private PieceBuilder GetPieceBuilder(PieceTypes type, ISquarePiece squarePiece)
        {
            switch (type)
            {
            case PieceTypes.Change:
                return(new Change());

            case PieceTypes.Chest:
                return(new Chest());

            case PieceTypes.DoublePoints:
            case PieceTypes.TriplePoints:
                return(new MultipliedPoints());

            case PieceTypes.Heart:
                return(new ExtraLife());

            case PieceTypes.Heavy:
                return(new Heavy());

            case PieceTypes.Locked:
                return(new Locked());

            case PieceTypes.Rainbow:
                return(new Rainbow());

            case PieceTypes.Swapping:
                return(new Swapping());

            case PieceTypes.FadePiece:
                return(new FadePiece());

            case PieceTypes.Bomb:
                return(new Bomb());

            case PieceTypes.Normal:
            case PieceTypes.Empty:
            default:
                return(new Normal());
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Adds the chosen Piece to the chosen Column.
        /// </summary>
        /// <param name="column">Number of the selected column</param>
        /// <param name="currentPiece">Currently selected piece</param>
        public void Add(int column, PieceTypes currentPiece)
        {
            // Check if the chosen column is full.
            if (!CanAdd(column))
            {
                return;
            }

            /* Starting at the top, move down to check for the correct position
             * to assign the chosen Piece. */
            int currentRow = 0;

            while (currentRow < Rows - 1 &&
                   grid[currentRow + 1, column] == PieceTypes.Bar)
            {
                currentRow++;
            }

            // Place the chosen piece when it gets to the right Row.
            grid[currentRow, column] = currentPiece;
        }
Esempio n. 15
0
 /// <summary>
 /// Check if the player's selected piece is still available to be played.
 /// </summary>
 /// <param name="currentPiece">Currently selected piece.</param>
 /// <returns>True of False depending on whether or not the player still
 ///  has pieces left to play.</returns>
 private static bool CheckPiece(PieceTypes currentPiece)
 {
     if (currentPiece == PieceTypes.RedSquare && (P2Squares > 0))
     {
         return(true);
     }
     else if (currentPiece == PieceTypes.RedCircle && (P2Circles > 0))
     {
         return(true);
     }
     else if (currentPiece == PieceTypes.WhiteSquare && (P1Squares > 0))
     {
         return(true);
     }
     else if (currentPiece == PieceTypes.WhiteCircle && (P1Circles > 0))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Esempio n. 16
0
 public Box(PieceTypes piecetype, uint units)
 {
     PieceType = piecetype;
     Units     = units;
 }
Esempio n. 17
0
 bool AIKingTile(BoardPiece actualPiece, int row, int column, int rowFactor, int columnFactor, PieceTypes targetType)
 {
     return(AIBoardTile(actualPiece, row, column, rowFactor, columnFactor, targetType, true));
 }
Esempio n. 18
0
 public IConcreteMove Concretize(Position from, Position to, PieceTypes promoteTo)
 {
     return new PromotionConcrete(BaseMove, promoteTo, from, to);
 }
Esempio n. 19
0
 public Piece(PieceTypes type, OwnerTypes owner, PiecePosition position)
 {
     Owner    = owner;
     Type     = type;
     Position = position;
 }
Esempio n. 20
0
 /// <summary>
 /// Create a new piece given a color and type
 /// </summary>
 /// <param name="color">The color the piece belongs to.</param>
 /// <param name="type">The type of the piece.</param>
 public Piece(ChessColors color, PieceTypes type, bool hasMoved = true)
 {
     Color         = color;
     Type          = type;
     this.hasMoved = hasMoved;
 }
Esempio n. 21
0
 /// <summary>
 /// Promote a piece to another type
 /// </summary>
 /// <para>
 /// This is mostly used for queening.
 /// </para>
 /// <param name="pieceType">The piece's new type</param>
 public void Promote(PieceTypes pieceType)
 {
     Type = pieceType;
 }
Esempio n. 22
0
 private bool CheckKingTile(int row, int column, int rowFactor, int columnFactor, PieceTypes targetType)
 {
     return(CheckBoardTile(row, column, rowFactor, columnFactor, targetType, true));
 }
Esempio n. 23
0
    private bool CheckBoardTile(int row, int column, int rowFactor, int columnFactor, PieceTypes targetType, bool isKing = false, BoardPiece lastPiece = null)
    {
        if (OnBoardLimits(row, column) == false)
        {
            return(false);
        }

        if (board[row, column].currentPiece == null)
        {
            if (lastPiece != null)
            {
                board[row, column].ApplyColorEffect(false);
            }
            else
            {
                board[row, column].ApplyColorEffect(true);
            }

            BoardInfoHolder newInfo = new BoardInfoHolder();
            newInfo.piece = lastPiece;
            newInfo.tile  = board[row, column];

            listAvaliableMoves.Add(newInfo);

            if (isKing == true)
            {
                CheckBoardTile(row + rowFactor, column + columnFactor, rowFactor, columnFactor, targetType, isKing, lastPiece);
            }

            return(true);
        }

        //Check effects when piece != null
        if (board[row, column].currentPiece != null && lastPiece == null)
        {
            if (board[row, column].currentPiece.CheckPieceType(targetType))
            {
                return(false);
            }

            return(CheckBoardTile(row + rowFactor, column + columnFactor, rowFactor, columnFactor, targetType, isKing, board[row, column].currentPiece));
        }

        return(false);
    }
Esempio n. 24
0
 public Piece(PieceTypes type)
 {
     Owner = OwnerTypes.Undefined;
     Type  = type;
 }
Esempio n. 25
0
 public PromotionConcrete(ITemplateMove baseMove, PieceTypes promoteTo, Position from, Position to)
 {
     BaseMove = baseMove.Concretize(from, to);
     PromoteTo = promoteTo;
     From = from;
 }
Esempio n. 26
0
 public void Apply(IGameState state)
 {
     var p = state[From] as ChessPiece;
     PromoteFrom = p.Type;
     BaseMove.Apply(state);
     p.Type = PromoteTo;
     p.PossibleMoves.Clear();
     ChessPieceFactory.AddMoves(p);
 }
Esempio n. 27
0
    public void DoActionPlace(PieceTypes pieceType)
    {
        CreatePiece(pieceType);

        piece?.GetComponent <SoundComponent>()?.PlayPlaceOnGrid();
    }
Esempio n. 28
0
 public static char GetPieceChar(this PieceTypes p) => PieceChars[(int)p];
Esempio n. 29
0
        /// <summary>
        /// Method that creates the object board, and runs the game on a while cycle.
        /// </summary>
        public static void StartPlay()
        {
            //  Create a board.
            World board = new World();
            // Default value of the selected column to start at the middle.
            int currentColumn = 3;
            // 'result' will recive the winning condition.
            string result = "";
            // Stores the information on what player's turn it is.
            PlayerType player = PlayerType.One;
            // Stores the information on what piece is currently selected.
            PieceTypes currentPiece = PieceTypes.WhiteSquare;

            // Start a Do-While cycle.
            do
            {
                // Clear the board and redraw it with the new 'current' info.
                Console.Clear();
                // Call the 'DrawHeader' Method to draw the header.
                DrawHeader(board, currentColumn, player, currentPiece);
                // Call the 'DrawBoard' Method to draw the board.
                board.DrawBoard();

                // Get input from the user.
                ConsoleKeyInfo key = Console.ReadKey();

                /* Left and right arrow keys can be used to move over one
                 * column at a time.*/
                if (key.Key == ConsoleKey.LeftArrow && currentColumn > 0)
                {
                    currentColumn--;
                }
                else if (key.Key == ConsoleKey.RightArrow && currentColumn < 6)
                {
                    currentColumn++;

                    /* Up and Down arrows can be used to select between the diferent
                     * pieces depending on witch player's turn it is.*/
                }
                else if ((key.Key == ConsoleKey.UpArrow ||
                          key.Key == ConsoleKey.DownArrow) &&
                         player == PlayerType.One)
                {
                    // Up or down to choose the pieces form, as player one.
                    if (currentPiece == PieceTypes.WhiteCircle)
                    {
                        currentPiece = PieceTypes.WhiteSquare;
                    }
                    else if (currentPiece == PieceTypes.WhiteSquare)
                    {
                        currentPiece = PieceTypes.WhiteCircle;
                    }

                    /* Up and Down arrows can be used to select between the diferent
                     * pieces depending on witch player's turn it is*/
                }
                else if ((key.Key == ConsoleKey.UpArrow ||
                          key.Key == ConsoleKey.DownArrow) &&
                         player == PlayerType.Two)
                {
                    // Up or down to choose the pieces form, as player two.
                    if (currentPiece == PieceTypes.RedCircle)
                    {
                        currentPiece = PieceTypes.RedSquare;
                    }
                    else if (currentPiece == PieceTypes.RedSquare)
                    {
                        currentPiece = PieceTypes.RedCircle;
                    }

                    /* When the 'Enter' key is pressed we will verify everything
                     * to make sure, that the chosen piece can be played.*/
                }
                else if (key.Key == ConsoleKey.Enter)
                {
                    /* Ask if the selected column is not full and if the player still has
                     * the selected piece available to play.*/
                    if (board.CanAdd(currentColumn) && CheckPiece(currentPiece))
                    {
                        // Adds the selected pice to the right 'cell' on the array.
                        board.Add(currentColumn, currentPiece);
                        // Decreases the piece counter.
                        RemovePiece(currentPiece);
                        // Checks for a winning condition
                        result = board.Win(result);
                        // Changes the player's turn.
                        if (player == PlayerType.One)
                        {
                            player = PlayerType.Two;
                        }
                        else
                        {
                            player = PlayerType.One;
                        }
                    }

                    /* Automatically switches the default player 1 piece in case he doesn't have
                     * a square or circle available to play anymore. */
                    if (player == PlayerType.One)
                    {
                        if (P1Squares > 0)
                        {
                            currentPiece = PieceTypes.WhiteSquare;
                        }
                        else
                        {
                            currentPiece = PieceTypes.WhiteCircle;
                        }

                        /* Automatically switches the default player 2 piece in case he doesn't have
                         * a square or circle available to play anymore. */
                    }
                    else if (player == PlayerType.Two)
                    {
                        if (P2Squares > 0)
                        {
                            currentPiece = PieceTypes.RedSquare;
                        }
                        else
                        {
                            currentPiece = PieceTypes.RedCircle;
                        }
                    }
                }

                /* If both players run out of pieces then the winning condition
                 * becomes a Tie.*/
                if (P1Circles == 0 && P1Squares == 0 &&
                    P2Circles == 0 && P2Squares == 0 &&
                    result == "")
                {
                    result = "It's a tie!";
                }
                // Runs the Do-While cycle while there is no winning condition.
            } while (result == "");

            // Clears the Console.
            Console.Clear();
            // Write the information about who won.
            Console.WriteLine(result);
            // Asks for an input return to the Menu.
            Console.WriteLine("\nPress Any Key to Return to Menu...");
            Console.ReadKey();

            // Resets all necessary values before returning to the Menu.
            P1Circles = 10;
            P1Squares = 11;
            P2Circles = 10;
            P2Squares = 11;

            // Calls method 'DrawMenu()', to return to the Menu.
            Menu.DrawMenu();
        }
Esempio n. 30
0
 public static int AsInt(this PieceTypes p) => (int)p;
Esempio n. 31
0
 public static char GetPromotionChar(this PieceTypes p) => PromotionPieceNotation[p.AsInt()];
Esempio n. 32
0
 public static Piece MakePiece(this PieceTypes @this, Player side) => (int)@this | (side.Side << 3);
Esempio n. 33
0
        private Score Eval(PieceTypes pt, Player us)
        {
            var result = EvaluatePawns(Player.White) - EvaluatePawns(Player.Black);

            return(result);
        }
Esempio n. 34
0
 public static bool IsSlider(this PieceTypes @this) => @this == PieceTypes.Bishop | @this == PieceTypes.Rook | @this == PieceTypes.Queen;
Esempio n. 35
0
    bool AIBoardTile(BoardPiece actualPiece, int row, int column, int rowFactor, int columnFactor, PieceTypes targetType, bool isKing = false, BoardPiece lastPiece = null)
    {
        if (OnBoardLimits(row, column) == false)
        {
            return(false);
        }

        if (board[row, column].currentPiece == null)
        {
            AIMoviment newMove = new AIMoviment();
            newMove.piece        = actualPiece;
            newMove.target       = board[row, column];
            newMove.eliminatedBy = lastPiece;

            listAvaliableMoves.Add(newMove);

            if (isKing == true)
            {
                AIBoardTile(actualPiece, row + rowFactor, column + columnFactor, rowFactor, columnFactor, targetType, isKing, lastPiece);
            }

            return(true);
        }

        //Check effects when piece != null
        if (board[row, column].currentPiece != null && lastPiece == null)
        {
            if (board[row, column].currentPiece.CheckPieceType(targetType))
            {
                return(false);
            }

            return(AIBoardTile(actualPiece, row + rowFactor, column + columnFactor, rowFactor, columnFactor, targetType, isKing, board[row, column].currentPiece));
        }

        return(false);
    }
Esempio n. 36
0
 public ChessPiece(ChessPiece copy)
     : base(copy)
 {
     Type = copy.Type;
 }