Example #1
0
        public override (List <Vector2Int> movements, List <Vector2Int> enemies) Movements()
        {
            var result   = new List <Vector2Int>();
            var enemies  = new List <Vector2Int>();
            var occupied = PiecesManager.GetOccupied();

            // Direction of Movement
            var dir = 1;

            if (team.Equals(Team.Black))
            {
                dir = -1;
            }
            var i = poss.x + dir;

            // Check Enemies
            var enemy1 = new Vector2Int(poss.x + dir, poss.y + 1);
            var enemy2 = new Vector2Int(poss.x + dir, poss.y - 1);

            if (occupied.Contains(enemy1) && PiecesManager.IsEnemy(enemy1, team))
            {
                enemies.Add(enemy1);
            }
            if (occupied.Contains(enemy2) && PiecesManager.IsEnemy(enemy2, team))
            {
                enemies.Add(enemy2);
            }


            // Checks collisions
            var vect = new Vector2Int(i, poss.y);

            if (occupied.Contains(vect))
            {
                return(result, enemies);
            }
            result.Add(vect);

            // First extra step
            var vect2 = new Vector2Int(i + dir, poss.y);

            if (_firstMove && !occupied.Contains(vect2))
            {
                result.Add(vect2);
            }

            return(result, enemies);
        }
Example #2
0
        public override (List <Vector2Int> movements, List <Vector2Int> enemies) Movements()
        {
            var(movements, enemies) = AMovement(PiecesManager.GetOccupied(), PiecesManager.GetDimensions(), 1);
            var otherTeam    = team.Equals(Team.White) ? Team.Black : Team.White;
            var validVectors = PiecesManager.GetValidVectors();

            // Movements following check rules
            var(movementsOther, enemiesOther) = PiecesManager.AllMovements(otherTeam);
            var movementsValid = movements.Except(movementsOther).Intersect(validVectors).ToList();

            // Verifies check or checkmate
            _check     = enemiesOther.Contains(poss);
            _checkmate = _check && movementsValid.Count <= 0;

            return(movementsValid, enemies);
        }
Example #3
0
        public override (List <Vector2Int> movements, List <Vector2Int> enemies) Movements()
        {
            var occupied   = PiecesManager.GetOccupied(team);
            var dimensions = PiecesManager.GetDimensions();

            var function = new Vector2Int(1, 2);

            var(positives, enemies1) = KnightMovement(occupied, function, dimensions);

            function = new Vector2Int(2, 1);
            var(negatives, enemies2) = KnightMovement(occupied, function, dimensions);

            var movements = positives.Concat(negatives).ToList();
            var enemies   = enemies1.Concat(enemies2).ToList();

            return(movements, enemies);
        }
Example #4
0
 private void Start()
 {
     _piece         = GetComponent <Piece>();
     _piecesManager = GetComponentInParent <PiecesManager>();
 }
Example #5
0
 // Converts the pawn to a queen
 private void Promote()
 {
     Debug.LogFormat("Pawn promoted, team: {0}, poss: {1}", team, poss);
     PiecesManager.PromotePawn(transform.position, poss, team);
     PiecesManager.KillPiece(gameObject, poss);
 }
Example #6
0
 public override (List <Vector2Int> movements, List <Vector2Int> enemies) MovementsForCheck()
 {
     return(AMovement(PiecesManager.GetOccupied(), PiecesManager.GetDimensions(), 1));
 }
Example #7
0
 protected void Start()
 {
     PiecesManager = FindObjectOfType <PiecesManager>();
 }