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>()); }
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 }
/// <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]; } }
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); } } }
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); }
private void OnDrawGizmos() { if (Application.isPlaying) { return; } if (pieceType != _pieceType) { CreatePiece(pieceType); _pieceType = pieceType; } if (groundType != _groundType) { CreateGround(groundType); _groundType = groundType; } }
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; }
/// <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--; } }
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()); } }
/// <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; }
/// <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); } }
public Box(PieceTypes piecetype, uint units) { PieceType = piecetype; Units = units; }
bool AIKingTile(BoardPiece actualPiece, int row, int column, int rowFactor, int columnFactor, PieceTypes targetType) { return(AIBoardTile(actualPiece, row, column, rowFactor, columnFactor, targetType, true)); }
public IConcreteMove Concretize(Position from, Position to, PieceTypes promoteTo) { return new PromotionConcrete(BaseMove, promoteTo, from, to); }
public Piece(PieceTypes type, OwnerTypes owner, PiecePosition position) { Owner = owner; Type = type; Position = position; }
/// <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; }
/// <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; }
private bool CheckKingTile(int row, int column, int rowFactor, int columnFactor, PieceTypes targetType) { return(CheckBoardTile(row, column, rowFactor, columnFactor, targetType, true)); }
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); }
public Piece(PieceTypes type) { Owner = OwnerTypes.Undefined; Type = type; }
public PromotionConcrete(ITemplateMove baseMove, PieceTypes promoteTo, Position from, Position to) { BaseMove = baseMove.Concretize(from, to); PromoteTo = promoteTo; From = from; }
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); }
public void DoActionPlace(PieceTypes pieceType) { CreatePiece(pieceType); piece?.GetComponent <SoundComponent>()?.PlayPlaceOnGrid(); }
public static char GetPieceChar(this PieceTypes p) => PieceChars[(int)p];
/// <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(); }
public static int AsInt(this PieceTypes p) => (int)p;
public static char GetPromotionChar(this PieceTypes p) => PromotionPieceNotation[p.AsInt()];
public static Piece MakePiece(this PieceTypes @this, Player side) => (int)@this | (side.Side << 3);
private Score Eval(PieceTypes pt, Player us) { var result = EvaluatePawns(Player.White) - EvaluatePawns(Player.Black); return(result); }
public static bool IsSlider(this PieceTypes @this) => @this == PieceTypes.Bishop | @this == PieceTypes.Rook | @this == PieceTypes.Queen;
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); }
public ChessPiece(ChessPiece copy) : base(copy) { Type = copy.Type; }