Ejemplo n.º 1
0
 public static bool CheckPiece(PieceVM piece)
 {
     if (piece == null)
     {
         return(false);
     }
     if (piece.Piece.PieceColor == BoardVM.Player1.Color && BoardVM.Player1.HasTurn)
     {
         return(true);
     }
     if (piece.Piece.PieceColor == BoardVM.Player2.Color && BoardVM.Player2.HasTurn)
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 2
0
 public static void IsKing(PieceVM piece)
 {
     if (piece != null)
     {
         if (piece.Piece.PieceColor == Piece.Color.RED && piece.Piece.PieceLocation.Row == 0)
         {
             piece.Piece.PieceType = Piece.Type.KING;
             piece.IsKing          = true;
             return;
         }
         if (piece.Piece.PieceColor == Piece.Color.WHITE && piece.Piece.PieceLocation.Row == 7)
         {
             piece.Piece.PieceType = Piece.Type.KING;
             piece.IsKing          = true;
             return;
         }
     }
 }
Ejemplo n.º 3
0
 public static void IsKing(PieceVM piece)
 {
     if (piece != null)
     {
         if (piece.Piece.PieceColor == Piece.Color.RED && piece.Piece.PieceLocation.Row == 0)
         {
             piece.Piece.PieceType = Piece.Type.KING;
             piece.Path            = Services.redKing;
             return;
         }
         if (piece.Piece.PieceColor == Piece.Color.WHITE && piece.Piece.PieceLocation.Row == 7)
         {
             piece.Piece.PieceType = Piece.Type.KING;
             piece.Path            = Services.whiteKing;
             return;
         }
     }
 }
Ejemplo n.º 4
0
        private static List <Move> GetMovesKing(PieceVM piece, bool checksForFreeTiles = true, List <PieceVM> pastPiecesTaken = null)
        {
            var moves    = new List <Move>();
            var cameFrom = piece.Piece.PieceLocation;

            int x = piece.Piece.PieceLocation.Row;
            int y = piece.Piece.PieceLocation.Column;

            Location NorthWest = new Location(x + NORTH, y + WEST);
            Location NorthEast = new Location(x + NORTH, y + EAST);

            if (IsOnTable(NorthWest))
            {
                var NorthWestPiece = GetPieceByLocation(NorthWest);
                if (NorthWestPiece == null)
                {
                    if (checksForFreeTiles)
                    {
                        var plainMove = new Move(NorthWest);
                        moves.Add(plainMove);
                    }
                }
                else if (NorthWestPiece.Piece.PieceColor != piece.Piece.PieceColor)
                {
                    Location NextNW = new Location(NorthWest.Row + NORTH, NorthWest.Column + WEST);
                    if (IsOnTable(NextNW))
                    {
                        var PseudoNWPiece = GetPieceByLocation(NextNW);
                        if (PseudoNWPiece == null)
                        {
                            var simpleJumpMove = new Move(NextNW);

                            if (!checksForFreeTiles)
                            {
                                foreach (var pastPiece in pastPiecesTaken)
                                {
                                    simpleJumpMove.TakenPieces.Add(pastPiece);
                                }
                            }

                            simpleJumpMove.TakenPieces.Add(NorthWestPiece);
                            moves.Add(simpleJumpMove);

                            moves.AddRange(GetMovesKing(piece.GetPhantomAt(NextNW), false, simpleJumpMove.TakenPieces));
                        }
                    }
                }
            }

            if (IsOnTable(NorthEast))
            {
                var NorthEastPiece = GetPieceByLocation(NorthEast);
                if (NorthEastPiece == null)
                {
                    if (checksForFreeTiles)
                    {
                        var plainMove = new Move(NorthEast);
                        moves.Add(plainMove);
                    }
                }
                else if (NorthEastPiece.Piece.PieceColor != piece.Piece.PieceColor)
                {
                    Location NextNE = new Location(NorthEast.Row + NORTH, NorthEast.Column + EAST);
                    if (IsOnTable(NextNE))
                    {
                        var PseudoNEPiece = GetPieceByLocation(NextNE);
                        if (PseudoNEPiece == null)
                        {
                            var simpleJumpMove = new Move(NextNE);

                            if (!checksForFreeTiles)
                            {
                                foreach (var pastPiece in pastPiecesTaken)
                                {
                                    simpleJumpMove.TakenPieces.Add(pastPiece);
                                }
                            }

                            simpleJumpMove.TakenPieces.Add(NorthEastPiece);
                            moves.Add(simpleJumpMove);

                            moves.AddRange(GetMovesKing(piece.GetPhantomAt(NextNE), false, simpleJumpMove.TakenPieces));
                        }
                    }
                }
            }

            Location SouthWest = new Location(x + SOUTH, y + WEST);
            Location SouthEast = new Location(x + SOUTH, y + EAST);

            if (IsOnTable(SouthWest))
            {
                var SouthWestPiece = GetPieceByLocation(SouthWest);
                if (SouthWestPiece == null)
                {
                    if (checksForFreeTiles)
                    {
                        var plainMove = new Move(SouthWest);
                        moves.Add(plainMove);
                    }
                }
                else if (SouthWestPiece.Piece.PieceColor != piece.Piece.PieceColor)
                {
                    Location NextSW = new Location(SouthWest.Row + SOUTH, SouthWest.Column + WEST);
                    if (IsOnTable(NextSW))
                    {
                        var PseudoNWPiece = GetPieceByLocation(NextSW);
                        if (PseudoNWPiece == null)
                        {
                            var simpleJumpMove = new Move(NextSW);

                            if (!checksForFreeTiles)
                            {
                                foreach (var pastPiece in pastPiecesTaken)
                                {
                                    simpleJumpMove.TakenPieces.Add(pastPiece);
                                }
                            }

                            simpleJumpMove.TakenPieces.Add(SouthWestPiece);
                            moves.Add(simpleJumpMove);

                            moves.AddRange(GetMovesKing(piece.GetPhantomAt(NextSW), false, simpleJumpMove.TakenPieces));
                        }
                    }
                }
            }

            if (IsOnTable(SouthEast))
            {
                var SouthEastPiece = GetPieceByLocation(SouthEast);
                if (SouthEastPiece == null)
                {
                    if (checksForFreeTiles)
                    {
                        var plainMove = new Move(SouthEast);
                        moves.Add(plainMove);
                    }
                }
                else if (SouthEastPiece.Piece.PieceColor != piece.Piece.PieceColor)
                {
                    Location NextSE = new Location(SouthEast.Row + SOUTH, SouthEast.Column + EAST);
                    if (IsOnTable(NextSE))
                    {
                        var PseudoNEPiece = GetPieceByLocation(NextSE);
                        if (PseudoNEPiece == null)
                        {
                            var simpleJumpMove = new Move(NextSE);

                            if (!checksForFreeTiles)
                            {
                                foreach (var pastPiece in pastPiecesTaken)
                                {
                                    simpleJumpMove.TakenPieces.Add(pastPiece);
                                }
                            }

                            simpleJumpMove.TakenPieces.Add(SouthEastPiece);
                            moves.Add(simpleJumpMove);

                            moves.AddRange(GetMovesKing(piece.GetPhantomAt(NextSE), false, simpleJumpMove.TakenPieces));
                        }
                    }
                }
            }

            piece.Piece.PieceLocation = cameFrom;

            if (piece.IsPhantom)
            {
                Services.boardVM.Pieces.Remove(piece);
            }

            return(moves);
        }
Ejemplo n.º 5
0
 public SelectPieceCommand(PieceVM piece)
 {
     this.pieceVM = piece;
 }
Ejemplo n.º 6
0
        private static List <Move> GetMovesUp(PieceVM piece, bool checksForFreeTiles = true, List <PieceVM> pastPiecesTaken = null)
        {
            var moves    = new List <Move>();
            var cameFrom = piece.Piece.PieceLocation;

            int x = piece.Piece.PieceLocation.Row;
            int y = piece.Piece.PieceLocation.Column;


            Location NorthWest = new Location(x + NORTH, y + WEST);
            Location NorthEast = new Location(x + NORTH, y + EAST);

            if (IsOnTable(NorthWest))
            {
                var NorthWestPiece = GetPieceByLocation(NorthWest);
                if (NorthWestPiece == null)
                {
                    if (checksForFreeTiles)
                    {
                        //Add plain move
                        var plainMove = new Move(NorthWest);
                        moves.Add(plainMove);
                    }
                }
                else if (NorthWestPiece.Piece.PieceColor != piece.Piece.PieceColor)
                {
                    //if enemy piece
                    Location NextNW = new Location(NorthWest.Row + NORTH, NorthWest.Column + WEST);
                    if (IsOnTable(NextNW))
                    {
                        var PseudoNWPiece = GetPieceByLocation(NextNW);
                        if (PseudoNWPiece == null)
                        {
                            //if there's no piexe on NextNW
                            //add this Move
                            var simpleJumpMove = new Move(NextNW);

                            if (!checksForFreeTiles)
                            {
                                foreach (var pastPiece in pastPiecesTaken)
                                {
                                    simpleJumpMove.TakenPieces.Add(pastPiece);
                                }
                            }
                            //we then add the appropiate piece to be taken
                            simpleJumpMove.TakenPieces.Add(NorthWestPiece);
                            moves.Add(simpleJumpMove);
                            //Moves.addRange(call GetMovesUp() for NextNW with the already taken pieces);
                            moves.AddRange(GetMovesUp(piece.GetPhantomAt(NextNW), false, simpleJumpMove.TakenPieces));
                        }
                    }
                }
            }

            if (IsOnTable(NorthEast))
            {
                var NorthEastPiece = GetPieceByLocation(NorthEast);
                if (NorthEastPiece == null)
                {
                    if (checksForFreeTiles)
                    {
                        //Add plain move
                        var plainMove = new Move(NorthEast);
                        moves.Add(plainMove);
                    }
                }
                else if (NorthEastPiece.Piece.PieceColor != piece.Piece.PieceColor)
                {
                    //if enemy piece
                    Location NextNE = new Location(NorthEast.Row + NORTH, NorthEast.Column + EAST);
                    if (IsOnTable(NextNE))
                    {
                        var PseudoNEPiece = GetPieceByLocation(NextNE);
                        if (PseudoNEPiece == null)
                        {
                            //if there's no piexe on NextNE
                            //add this Move
                            var simpleJumpMove = new Move(NextNE);

                            if (!checksForFreeTiles)
                            {
                                foreach (var pastPiece in pastPiecesTaken)
                                {
                                    simpleJumpMove.TakenPieces.Add(pastPiece);
                                }
                            }
                            //we then add the appropiate piece to be taken
                            simpleJumpMove.TakenPieces.Add(NorthEastPiece);
                            moves.Add(simpleJumpMove);
                            //Moves.addRange(call GetMovesUp() for NextNE with the already taken pieces);
                            moves.AddRange(GetMovesUp(piece.GetPhantomAt(NextNE), false, simpleJumpMove.TakenPieces));
                        }
                    }
                }
            }
            piece.Piece.PieceLocation = cameFrom;

            if (piece.IsPhantom)
            {
                boardVM.Pieces.Remove(piece);
            }

            return(moves);
        }