Example #1
0
        public static square makeSquare(pieceType newType, pieceColour newColour, squarePos newPos)
        {
            square toRet ;
            switch (newType)
            {
                case pieceType.none:
                    toRet = new square(newPos);
                    break;
                case pieceType.pawn:
                    toRet = new pawnSquare(newPos, newColour);
                    break;
                case pieceType.rook:
                    toRet = new rookSquare(newPos, newColour);
                    break;
                case pieceType.bishop:
                    toRet = new bishopSquare(newPos, newColour);
                    break;
                case pieceType.knight:
                    toRet = new knightSquare(newPos, newColour);
                    break;
                case pieceType.queen:
                    toRet = new queenSquare(newPos, newColour);
                    break;
                case pieceType.king:
                    toRet = new kingSquare(newPos, newColour);
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }

            return toRet;
        }
Example #2
0
        public move(square src, square dst, pieceType toPromoteTo)
        {
            srcPos = src.position;
            dstPos = dst.position;
            _srcSquare = src;

            if (src.type != pieceType.pawn)
                throw new Exception("Attempt to promote non-pawn");
            if (toPromoteTo == pieceType.pawn)
                throw new Exception("Attempt to promote a pawn to a pawn");
            if (toPromoteTo == pieceType.none)
                throw new Exception("Attempt to promote a pawn to an empty space");

            isPawnPromotion = true;
            typeToPromoteTo = toPromoteTo;

            if (dst.type != pieceType.none)
            {
                isCapture = true;
                capturedSquare = dst;
                capturedSquarePos = dst.position;
            }

            if (src.type == pieceType.king)
                findCastlingRookPositions();
        }
Example #3
0
 /// <summary>
 /// Checks if the attemptedMove is a pawn reaching the end rank. If so, opens a pawnPromotion window that
 /// prompts the player to choose a piece to promote the pawn to. If the player chooses to promote to a pawn
 /// his move is disallowed as a pawn cannot be promoted to a pawn on the final rank
 /// </summary>
 /// <param name="attemptedMove"></param>
 /// <returns>True if a pawn was promoted, false otherwise.</returns>
 private bool checkForAndApplyPawnPromotion(ChessMove attemptedMove)
 {
     if (attemptedMove.piece.getType() == pieceType.pawn)
     {
         if (attemptedMove.final.rank() == '8')
         {
             pieceType promotedTo = pawnPromotion(pieceColour.light);
             if (promotedTo == pieceType.pawn)
             {
                 placePieceBack();
                 return(true);
             }
             this.liftedPiece = ChessPiece.newChessPiece(promotedTo, pieceColour.light);
         }
         else if (attemptedMove.final.rank() == '1')
         {
             pieceType promotedTo = pawnPromotion(pieceColour.dark);
             if (promotedTo == pieceType.pawn)
             {
                 placePieceBack();
                 return(true);
             }
             this.liftedPiece = ChessPiece.newChessPiece(promotedTo, pieceColour.dark);
         }
     }
     return(false);
 }
Example #4
0
    public gamePiece SpawnNewPiece(int x, int y, pieceType type)
    {
        GameObject newPiece = (GameObject)Instantiate(piecePrefabDict[type], GetWorldPositon(x, y), Quaternion.identity);

        newPiece.transform.parent = transform;
        pieces[x, y] = newPiece.GetComponent <gamePiece>();
        pieces[x, y].Init(x, y, this, type);
        return(pieces[x, y]);
    }
Example #5
0
 public void becomeHost()
 {
     connectionsPanel.SetActive(false);
     nc = new NetConn(pw, onConnectCB, "localhost", 12345, mode.HOST);
     hostStatus.gameObject.SetActive(true);
     hostStatus.text = "Waiting for connection...";
     isHost          = true;
     playerType      = pieceType.XPIECE;
     enemyType       = pieceType.OPIECE;
 }
Example #6
0
 public void becomeClient()
 {
     connectionsPanel.SetActive(false);
     nc = new NetConn(pw, onConnectCB, "localhost", 12345, mode.CLIENT);
     hostStatus.gameObject.SetActive(true);
     hostStatus.text = "Attempting to connect...";
     isHost          = false;
     playerType      = pieceType.OPIECE;
     enemyType       = pieceType.XPIECE;
 }
    public void SetUpPiece(ChessPlayer player, pieceType type)
    {
        this.player = player;

        pieceName    = type.pieceName;
        infiniteMove = type.moveStyles.Item1;
        anyMove      = type.moveStyles.Item2;
        ghostMove    = type.moveStyles.Item3;
        SetMoveAttackVectors(type);
        SetSprite(pieceName);
    }
Example #8
0
    //Method to initialize Robot's pieces
    public void Initialize(int type)
    {
        //Initialize piece type
        switch (type)
        {
        case 0:
            _type = pieceType.leg_l;
            break;

        case 1:
            _type = pieceType.leg_r;
            break;

        case 2:
            _type = pieceType.arm_l;
            break;

        case 3:
            _type = pieceType.arm_r;
            break;
        }

        //Initialize conectors data
        _numberConectors = Random.Range(1, _maxConectors + 1);
        _colors          = new Color[_numberConectors];

        //Instantiate the conectors
        for (int i = 0; i < _numberConectors; i++)
        {
            //Instantiate(_conectorPrefab, transform.GetChild(i + 1));        //The i+1 is because the first child in the prefab is the sprite.
            _colors[i] = colors[Random.Range(0, colors.Length)];            //Pick random color.
            if (transform.GetChild(i + 1).TryGetComponent <SpriteRenderer>(out SpriteRenderer spriteRenderer))
            {
                transform.GetChild(i + 1).gameObject.SetActive(true);
                spriteRenderer.color = _colors[i];      //Asign color to component's spriteRenderer.
                                                        //(Must be a sprite. If not, pick the right component; not SpriteRenderer)
            }
            ;
        }

        //Disable the Conectors we won't use. The prefab has 3 conectors, so we hide the ones we won't use.
        for (int i = _numberConectors; i < _maxConectors; i++)
        {
            transform.GetChild(i + 1).gameObject.SetActive(false);
        }

        //Initialize it's aura
        _aura = Instantiate(_auraPrefab, transform);
        _aura.SetActive(false);
        this.gameObject.SetActive(false);
        used = false;
    }
Example #9
0
        /// <summary>
        /// Opens the pawn promotion window and return what piece the user chose to promote his pawn to. Does not return
        /// until the pawn promotion window is closed.
        /// </summary>
        /// <param name="colour">The colour of the pawn being promoted</param>
        /// <returns>What the pawn will be promoted to, or a pawn if there will be no promotion</returns>
        private pieceType pawnPromotion(pieceColour colour)
        {
            pieceType returned = pieceType.pawn;

            PawnPromotionWindow pawnPromotionWindow = new PawnPromotionWindow();

            pawnPromotionWindow.setPromotionPieceColours(colour);

            pawnPromotionWindow.promotedToPiece += value => returned = value;

            pawnPromotionWindow.ShowDialog();

            pawnPromotionWindow.Close();

            return(returned);
        }
    private void SetMoveAttackVectors(pieceType type)
    {
        moveVectors.Clear();
        attackVectors.Clear();
        foreach ((int, int)mv in type.moveVectors.Item1)
        {
            print("One of the move vectors: " + mv);
            moveVectors.Add(new Vector2(mv.Item1, mv.Item2));
        }

        foreach ((int, int)av in type.moveVectors.Item2)
        {
            print("One of the Attacl vectors: " + av);
            if (av == (0, 0))
            {
                attackVectors = moveVectors;
            }
        public void setPieceType(pieceType newPieceType)
        {
            myPieceType = newPieceType;

            if (myPieceType == pieceType.NOPIECE)
            {
                myPictureBox.Image = null;
            }
            else
            {
                if (myPieceType == pieceType.WHITEPIECE)
                {
                    myPictureBox.Image = Properties.Resources.WhitePiece;
                }
                else
                {
                    myPictureBox.Image = Properties.Resources.BlackPiece;
                }
            }
        }
Example #12
0
 public static int getMaterialAdvantage(pieceType pieces)
 {
     switch (pieces)
     {
         case pieceType.none:
             return 0;
         case pieceType.pawn:
             return 1;
         case pieceType.bishop:
             return 3;
         case pieceType.knight:
             return 3;
         case pieceType.rook:
             return 5;
         case pieceType.queen:
             return 8;
         case pieceType.king:
             // Do not return int.Maxval, in order to avoid overflow. Situations with no king
             // are already handled as wins or losses.
             return 0;
         default:
             throw new Exception("Unrecognised piece");
     }
 }
 public void switchType()
 {
     if (myPieceType == pieceType.NOPIECE)
     {
         return;
     }
     else
     {
         if (myPieceType == pieceType.WHITEPIECE)
         {
             myPieceType = pieceType.BLACKPIECE;
             myPictureBox.Image = Properties.Resources.BlackPiece;
             myPictureBox.Invalidate();
             myPictureBox.Visible = true;
         }
         else
         {
             myPieceType = pieceType.WHITEPIECE;
             myPictureBox.Image = Properties.Resources.WhitePiece;
             myPictureBox.Invalidate();
             myPictureBox.Visible = true;
         }
     }
 }
Example #14
0
 protected ChessPiece(colors color, pieceType piece, Location location)
 {
     Color           = color;
     PieceType       = piece;
     CurrentLocation = location;
 }
Example #15
0
 internal Rook(colors color, pieceType piece, Location location) : base(color, pieceType.ROOK, location)
 {
 }
Example #16
0
 internal Bishop(colors color, pieceType piece, Location location) : base(color, pieceType.BISHOP, location)
 {
 }
        private static string getImageForPiece(pieceType type, pieceColour colour)
        {
            string url = @"images/";

            switch (type)
            {
                case pieceType.none:
                    url += "none";
                    break;
                case pieceType.queen:
                    url += "queen";
                    break;
                case pieceType.pawn:
                    url += "pawn";
                    break;
                case pieceType.bishop:
                    url += "bishop";
                    break;
                case pieceType.rook:
                    url += "rook";
                    break;
                case pieceType.king:
                    url += "king";
                    break;
                case pieceType.knight:
                    url += "knight";
                    break;
                default:
                    throw new ArgumentOutOfRangeException("type");
            }

            url += "-" + colour;

            url += ".png";

            return url;
        }
Example #18
0
 public Knight(Tuple <int, int> piecePosition, pieceType type, pieceColor color) : base(piecePosition, type, color)
 {
 }
Example #19
0
 internal Queen(colors color, pieceType piece, Location location) : base(color, pieceType.QUEEN, location)
 {
 }
Example #20
0
 public Pawn(Tuple <int, int> piecePosition, pieceType type, pieceColor color) : base(piecePosition, type, color)
 {
     this.firstMove = true;
 }
Example #21
0
 public void setType(pieceType type)
 {
     p_pieceType = type;
 }
 public void placePiece(int row, int col, pieceType inPiece)
 {
     boardTable[row, col].setPieceType(inPiece);
     updateBoardWithNewPiece(row, col);
 }
Example #23
0
 internal Knight(colors color, pieceType piece, Location location) : base(color, pieceType.KNIGHT, location)
 {
 }
        protected override square addPiece(pieceType newType, pieceColour newColour, squarePos dstPos)
        {
            base.addPiece(newType, newColour, dstPos);

            addNewPieceToArrays(this[dstPos]);
            coverLevel.add(dstPos.x, dstPos.y);

            return this[dstPos];
        }
Example #25
0
 internal King(colors color, pieceType piece, Location location) : base(color, pieceType.KING, location)
 {
 }
Example #26
0
        /// <summary>
        /// Add a piece to the board
        /// </summary>
        /// <param name="newType">Type of piece to add</param>
        /// <param name="newColour">Colour of piece to add</param>
        /// <param name="dstPos">Location of piece to add</param>
        /// <returns></returns>
        protected virtual square addPiece(pieceType newType, pieceColour newColour, squarePos dstPos)
        {
            this[dstPos] = square.makeSquare(newType, newColour, dstPos);

            addToArrays(this[dstPos]);

            return this[dstPos];
        }
Example #27
0
        /// <summary>
        /// Add a piece to the board
        /// </summary>
        /// <param name="newType">Type of piece to add</param>
        /// <param name="newColour">Colour of piece to add</param>
        /// <param name="x">X location of piece to add</param>
        /// <param name="y">Y location of piece to add</param>
        /// <returns></returns>
        public virtual square addPiece(pieceType newType, pieceColour newColour, int x, int y)
        {
            square newSquare = addPiece(newType, newColour, new squarePos(x, y));

            return newSquare;
        }
Example #28
0
 public Piece(Tuple <int, int> piecePosition, pieceType type, pieceColor color)
 {
     this.piecePosition = piecePosition;
     this.type          = type;
     this.color         = color;
 }
Example #29
0
 internal Pawn(colors color, pieceType piece, Location location) : base(color, pieceType.PAWN, location)
 {
 }