Esempio n. 1
0
 private moveset diagonalMoves(game.coord target)
 {
 }
Esempio n. 2
0
        //Return a list of all the coordinates that a single piece could move to, including taking
        public moveset getAllMoves(game.coord target)
        {
            piecePos = target;
            //The list containing valid moves that the piece can make
            List <game.coord> valid       = new List <game.coord>();
            List <game.coord> validTaking = new List <game.coord>();

            //The array to contain the "enemy" pieces to simplify code
            char[] enemies;
            //The current piece's character (ie. type)
            char pieceChar = piecePos.getPiece(toAnalyze);

            //Set the correct set of enemies
            if (game.whitePieces.Contains(pieceChar))
            {
                enemies = game.blackPieces;
            }
            else
            {
                enemies = game.whitePieces;
            }

            //Pawns
            if (Char.ToLower(pieceChar) == game.blackPieces[0])
            {
                game.coord ahead;
                game.coord left;
                game.coord right;
                if ((toAnalyze.attacker == team.black && pieceChar == 'p') || (!(toAnalyze.attacker == team.white) && pieceChar == 'P'))
                {
                    //Pawn moving up
                    int aheadY = piecePos.y + 1;
                    ahead = new game.coord(piecePos.x, aheadY);
                    left  = new game.coord(piecePos.x + 1, aheadY);
                    right = new game.coord(piecePos.x - 1, aheadY);
                }
                else
                {
                    //Pawn moving down
                    int aheadY = piecePos.y - 1;
                    ahead = new game.coord(piecePos.x, aheadY);
                    left  = new game.coord(piecePos.x + 1, aheadY);
                    right = new game.coord(piecePos.x - 1, aheadY);
                }
                //Check if ahead is clear
                if (ahead.getPiece(toAnalyze) == ' ')
                {
                    valid.Add(ahead);
                }
                //Check if sides are occupied by enemies
                //Left
                if (enemies.Contains(left.getPiece(toAnalyze)))
                {
                    valid.Add(left);
                    validTaking.Add(left);
                }
                //Right
                if (enemies.Contains(right.getPiece(toAnalyze)))
                {
                    valid.Add(right);
                    validTaking.Add(left);
                }
            }
            else
            {
                switch (Char.ToLower(pieceChar))
                {
                case game.blackPieces[1]:
                    //Rooks
                    return(straightMoves(piecePos));

                case game.blackPieces[2]:
                    //Knights
                    //Define the array of moves knights can make
                    game.coord[] knightMoves =
                    {
                        //Bottom left
                        new game.coord(piecePos.x - 2, piecePos.x - 1),
                        new game.coord(piecePos.x - 1, piecePos.y - 2),
                        //Bottom right
                        new game.coord(piecePos.x + 2, piecePos.y - 1),
                        new game.coord(piecePos.x + 1, piecePos.y - 2),
                        //Top right
                        new game.coord(piecePos.x + 2, piecePos.y + 1),
                        new game.coord(piecePos.x + 1, piecePos.y + 2),
                        //Top left
                        new game.coord(piecePos.x - 2, piecePos.y + 1),
                        new game.coord(piecePos.x - 1, piecePos.y + 2)
                    };
                    //Check them all for free spaces and enemies
                    foreach (game.coord current in knightMoves)
                    {
                        if (current.getPiece(toAnalyze) == ' ' || enemies.Contains(current.getPiece(toAnalyze)))
                        {
                            valid.Add(current);
                            validTaking.Add(current);
                        }
                    }
                    return(new moveset(piecePos, valid.ToArray(), validTaking.ToArray()));

                case game.blackPieces[3]:
                    //Bishops
                    return(diagonalMoves(piecePos));

                case game.blackPieces[4]:
                    //Queens
                    return(new moveset(diagonalMoves(piecePos), straightMoves(piecePos)));

                case game.blackPieces[5]:
                    //Kings
                    for (int i = -1; i < 2; i++)
                    {
                        for (int o = -1; o < 2; o++)
                        {
                            if (toAnalyze.board[i, o] == ' ' || enemies.Contains(toAnalyze.board[i, o]))
                            {
                                valid.Add(new game.coord(i, o));
                                validTaking.Add(new game.coord(i, o));
                            }
                        }
                    }
                    return(new moveset(piecePos, valid.ToArray(), validTaking.ToArray()));
                }
            }
        }
Esempio n. 3
0
 private moveset straightMoves(game.coord target)
 {
 }
Esempio n. 4
0
 //Make a new moveset from a target and two lists of moves
 public moveset(game.coord pieceTarget, game.coord[] nonTaking, game.coord[] taking)
 {
     activeMoves  = taking;
     passiveMoves = nonTaking;
     target       = pieceTarget;
 }