예제 #1
0
 public bool canEat(int x, int y)
 {
     if (BOARD.getPiece(x, y).getClass2() == CheckersPiece.getClass())
     {
         return(true);
     }
     return(false);
 }
예제 #2
0
 public bool eat(int x, int y)
 {
     if (BOARD.getPiece(x, y).getClass2() == CheckersPiece.getClass())
     {
         if (BOARD.removePiece(x, y))
         {
             if (gameEnded())
             {
                 Console.WriteLine("End game. Winner: " + WINNER);
             }
             return(true);
         }
     }
     return(false);
 }
예제 #3
0
        private bool cannotMove(int Player)
        {
            if (EAT_MOVE)
            {
                return(false);
            }
            if (GAME_ENDED || WAITING_PLAYERS)
            {
                return(false);
            }
            if (Player != ACTUAL_PLAYER)
            {
                return(false);
            }

            for (int x1 = 0; x1 < 8; x1++)
            {
                for (int y1 = 0; y1 < 8; y1++)
                {
                    if (BOARD.getPiece(x1, y1).getClass2() != NullPiece.getClass())
                    {
                        CheckersPiece P1 = (CheckersPiece)BOARD.getPiece(x1, y1);
                        if (P1.getPlayer() == Player)
                        {
                            for (int dx = 1; dx <= 2; dx++)
                            {
                                for (int posNegX = -1; posNegX < 2; posNegX = posNegX + 2)
                                {
                                    for (int posNegY = -1; posNegY < 2; posNegY = posNegY + 2)
                                    {
                                        int destX = x1 + dx * posNegX;
                                        int destY = x1 + dx * posNegY;
                                        if (BOARD.validCell(destX, destY) && canMove(x1, y1, destX, destY, Player))
                                        {
                                            return(false);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(true);
        }
예제 #4
0
        public override bool canMove(int x1, int y1, int x2, int y2, int Player)
        {
            if (GAME_ENDED || WAITING_PLAYERS)
            {
                return(false);
            }
            if (Player != ACTUAL_PLAYER)
            {
                return(false);
            }

            if (!BOARD.validCell(x1, y1) || !BOARD.validCell(x2, y2))
            {
                return(false);
            }

            if (BOARD.getPiece(x1, y1).getClass2() == NullPiece.getClass())
            {
                return(false);
            }
            if (BOARD.getPiece(x2, y2).getClass2() != NullPiece.getClass())
            {
                return(false);
            }

            if (BOARD.getPiece(x1, y1).getClass2() == NullPiece.getClass())
            {
                return(false);
            }

            CheckersPiece P1 = (CheckersPiece)BOARD.getPiece(x1, y1);

            if (P1.getPlayer() != Player)
            {
                Console.WriteLine("player:" + P1.getPlayer());
                return(false);
            }



            if ((Math.Abs(x2 - x1) == 1 && Math.Abs(y2 - y1) == 1) && !EAT_MOVE)
            {
                if (P1.TYPE == CheckersPiece.CHECKER)
                {
                    return(true);
                }
                else if (P1.TYPE == CheckersPiece.SIMPLE)
                {
                    if (Player == PLAYER1)
                    {
                        if (x2 > x1)
                        {
                            return(true);
                        }
                    }
                    else if (Player == PLAYER2)
                    {
                        if (x2 < x1)
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Invalid player name: " + Player);
                    }
                }
                else
                {
                    Console.WriteLine("Invalid piece type: " + P1.TYPE);
                }
            }
            else
            {
                if ((Math.Abs(x2 - x1) == 2 && Math.Abs(y2 - y1) == 2) && (!EAT_MOVE || EAT_PIECE == BOARD.getPiece(x1, y1)))
                {
                    int x_adversary = x1 + (x2 - x1) / 2;
                    int y_adversary = y1 + (y2 - y1) / 2;
                    if (isAdversary((Piece)BOARD.getPiece(x_adversary, y_adversary), Player))
                    {
                        if (P1.TYPE == CheckersPiece.CHECKER)
                        {
                            if (canEat(x_adversary, y_adversary))
                            {
                                return(true);
                            }
                        }
                        else if (P1.TYPE == CheckersPiece.SIMPLE)
                        {
                            if (Player == PLAYER1)
                            {
                                if (x2 > x1)
                                {
                                    if (canEat(x_adversary, y_adversary))
                                    {
                                        return(true);
                                    }
                                }
                            }
                            else if (Player == PLAYER2)
                            {
                                if (x2 < x1)
                                {
                                    if (canEat(x_adversary, y_adversary))
                                    {
                                        return(true);
                                    }
                                }
                            }
                            else
                            {
                                Console.WriteLine("Invalid player name: " + Player);
                            }
                        }
                        else
                        {
                            Console.WriteLine("Invalid piece type: " + P1.TYPE);
                        }
                    }
                }
            }
            return(false);
        }