Esempio n. 1
0
        public override bool ValidMoves(int x, int y, GameBoard gameboard)
        {
            int CurrentX = this.getCurrentPosition().Item1;
            int CurrentY = this.getCurrentPosition().Item2;

            //to right
            if (y == CurrentY + 2 && (x == CurrentX + 1 || x == CurrentX - 1))
            {
                //whether stuck by other pieces ?
                if (gameboard.getPieces()[CurrentX, CurrentY + 1] == null)
                {
                    return(true);
                }
            }

            //to left
            if (y == CurrentY - 2 && (x == CurrentX + 1 || x == CurrentX - 1))
            {
                //whether stuck by other pieces ?
                if (gameboard.getPieces()[CurrentX, CurrentY - 1] == null)
                {
                    return(true);
                }
            }

            //to up
            if (x == CurrentX - 2 && (y == CurrentY + 1 || y == CurrentY - 1))
            {
                //whether stuck by other pieces ?
                if (gameboard.getPieces()[CurrentX - 1, CurrentY] == null)
                {
                    return(true);
                }
            }

            //to down
            if (x == CurrentX + 2 && (y == CurrentY + 1 || y == CurrentY - 1))
            {
                //whether stuck by other pieces ?
                if (gameboard.getPieces()[CurrentX + 1, CurrentY] == null)
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 2
0
        public override bool ValidMoves(int x, int y, GameBoard gameboard)
        {
            Piece[,] board = gameboard.getPieces();
            int temp_x;

            //Determining whether the current player is red or black
            if (player == "red")
            {
                temp_x = 0;
            }
            else
            {
                temp_x = 5;
            }

            //Determining compliance with the rules of moving pieces(田)
            if (x >= temp_x && x <= (temp_x + 4) && y >= 0 && y <= 8)
            {
                if (x - intX == 2 || x - intX == -2)
                {
                    if (y - intY == 2 || y - intY == -2)
                    {
                        //Determine if there are any pieces in the middle of "田"
                        if (board[(x + intX) / 2, (y + intY) / 2] == null)
                        {
                            //Determine if there are pawns in the target position
                            if (board[x, y] != null)
                            {
                                //Determine whether the piece in the target position is your own pawn
                                if (board[x, y].getPlayer() == this.player)
                                {
                                    return(false);
                                }
                            }
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Esempio n. 3
0
        public override bool ValidMoves(int x, int y, GameBoard gameboard)
        {
            Piece[,] board = gameboard.getPieces();
            int temp_x;

            //Determining whether the current player is red or black
            if (player == "red")
            {
                temp_x = 0;
            }
            else
            {
                temp_x = 7;
            }

            //Determine if the end point is in the palace
            if (x <= (temp_x + 2) && x >= temp_x && y <= 5 && y >= 3)
            {
                //Determining compliance with the rules of moving pieces (diagonal)
                if ((x - intX == 1 || x - intX == -1) && (y - intY == 1 || y - intY == -1))
                {
                    //Determine if there are pawns in the target position
                    if (board[x, y] != null)
                    {
                        //Determine whether the piece in the target position is your own pawn
                        if (board[x, y].getPlayer() == this.player)
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 4
0
        public override bool ValidMoves(int x, int y, GameBoard gameboard)
        {
            int CurrentX = this.getCurrentPosition().Item1;
            int CurrentY = this.getCurrentPosition().Item2;

            //to count how many pieces on the way it move forward
            int count = -1;

            //move horizontally
            if (x == CurrentX && y != CurrentY)
            {
                if (y > CurrentY)
                {
                    //to right
                    count = 0;
                    for (int i = CurrentY + 1; i < y; i++)
                    {
                        if (gameboard.getPieces()[x, i] != null)
                        {
                            count++;
                        }
                    }
                }
                if (y < CurrentY)
                {
                    //to left
                    count = 0;
                    for (int i = CurrentY - 1; i > y; i--)
                    {
                        if (gameboard.getPieces()[x, i] != null)
                        {
                            count++;
                        }
                    }
                }
            }
            //move vertically
            if (y == CurrentY && x != CurrentX)
            {
                //up
                if (x < CurrentX)
                {
                    count = 0;
                    for (int i = CurrentX - 1; i > x; i--)
                    {
                        if (gameboard.getPieces()[i, y] != null)
                        {
                            count++;
                        }
                    }
                }
                //down
                if (x > CurrentX)
                {
                    count = 0;
                    for (int i = CurrentX + 1; i < x; i++)
                    {
                        if (gameboard.getPieces()[i, y] != null)
                        {
                            count++;
                        }
                    }
                }
            }
            //move and eat the piece
            if (count == 1 && gameboard.getPieces()[x, y] != null)  //if count == 1 it means that there is only one piece on the way it move
            {
                return(true);                                       //forward and it must be the eaten piece
            }
            //just move the Cannon
            if (count == 0 && gameboard.getPieces()[x, y] == null)  //if count == 0 it means that there is no piece on the way it move forward
            {
                return(true);                                       //and the destination must of no piece
            }
            return(false);
        }
Esempio n. 5
0
        public override bool ValidMoves(int x, int y, GameBoard gameboard)
        {
            int intX = this.getCurrentPosition().Item1;
            int intY = this.getCurrentPosition().Item2;

            //judge the relative position between red and black
            if (gameboard.getPieces()[x, y] != null)
            {   //from red to black
                if (gameboard.getPieces()[x, y].getPieceWords() == "G" && gameboard.getPieces()[x, y].getPlayer() == "black" &&
                    x >= 7 && x <= 9 && y == intY)
                {
                    for (int i = intX + 1; i < x; i++)
                    {
                        if (gameboard.getPieces()[i, y] != null)
                        {
                            return(false);
                        }
                    }
                    return(true); //if true the general could eat the opponent general piece directly
                }//from black to red

                else if (gameboard.getPieces()[x, y].getPieceWords() == "G" && gameboard.getPieces()[x, y].getPlayer() == "red" &&
                         x >= 0 && x <= 2 && y == intY)
                {
                    for (int i = intX - 1; i > x; i--)
                    {
                        if (gameboard.getPieces()[i, y] != null)
                        {
                            return(false);
                        }
                    }
                    return(true); //if true the general could eat the opponent general piece directly
                }
            }

            if (player == "red")//Judge the player is  red or black
            {
                if (x < 0 || x > 2)
                {
                    return(false);
                }
            }

            else
            {
                if (x < 7 || x > 9)
                {
                    return(false);
                }
            }

            if (y < 3 || y > 5)
            {
                return(false);
            }

            //Judge the moving less than one
            if ((Math.Abs(intX - x) + Math.Abs(intY - y)) <= 1)
            {
                //go right
                if (gameboard.getPieces()[x, y] != null)                        // Judge the next position doesn't have piece
                {
                    if (gameboard.getPieces()[x, y].getPlayer() == this.player) // Judge the player is  red or black
                    {
                        return(false);
                    }
                }
                return(true);
            }

            else
            {
                return(false);
            }
        }
Esempio n. 6
0
        public override bool ValidMoves(int x, int y, GameBoard gameboard)
        {
            int CurrentX = this.getCurrentPosition().Item1;
            int CurrentY = this.getCurrentPosition().Item2;

            //make the rook move horizontally
            if (CurrentX == x && CurrentY != y)
            {
                //go right
                if (y > CurrentY)
                {
                    for (int i = CurrentY + 1; i < y; i++)
                    {
                        if (gameboard.getPieces()[x, i] != null)  //if there is a piece on the way of its moving forward, then return false
                        {
                            return(false);
                        }
                    }
                }
                else
                {
                    //go left
                    for (int i = CurrentY - 1; i > y; i--)
                    {
                        if (gameboard.getPieces()[x, i] != null)  //the same
                        {
                            return(false);
                        }
                    }
                }
                return(true);
            }

            //move vertically
            if (x != CurrentX && y == CurrentY)
            {
                //go down
                if (x > CurrentX)
                {
                    for (int i = CurrentX + 1; i < x; i++)
                    {
                        if (gameboard.getPieces()[i, y] != null)  //the same
                        {
                            return(false);
                        }
                    }
                }
                else
                {
                    //go up
                    for (int i = CurrentX - 1; i > x; i--)
                    {
                        if (gameboard.getPieces()[i, y] != null)  //the same
                        {
                            return(false);
                        }
                    }
                }
                return(true);
            }
            return(false);
        }