Esempio n. 1
0
        public bool virtualDoMove(string i_Move, Board i_Board, bool i_IsFirstMoveForChecker)
        {
            bool aMoveWasMade = false;

            Board.BoardCell sourceCell, destinationCell;

            int sourceCellX, sourceCellY, destinationCellX, destinationCellY;

            sourceCellX      = Convert.ToInt32(i_Move[0]) - 65;
            sourceCellY      = Convert.ToInt32(i_Move[1]) - 97;
            destinationCellX = Convert.ToInt32(i_Move[3]) - 65;
            destinationCellY = Convert.ToInt32(i_Move[4]) - 97;

            if (ValidationProcess.IsLegalMoveFormat(i_Move, i_Board.BoardSize))
            {
                sourceCell      = i_Board.BoardArray[sourceCellY, sourceCellX];
                destinationCell = i_Board.BoardArray[destinationCellY, destinationCellX];

                if (ValidationProcess.VirtualIsLegalMove(sourceCell, destinationCell, i_Board, Player1.MyTurn ? Player2.Name : Player1.Name))
                {
                    aMoveWasMade = true;
                }
            }

            return(aMoveWasMade);
        }
Esempio n. 2
0
        public bool DoMove(string i_Move, Board i_Board, bool i_IsFirstMoveForChecker)
        {
            bool aMoveWasMade       = false;
            bool aDoubleMoveWasMade = false;

            Board.BoardCell sourceCell, destinationCell;

            int sourceCellX, sourceCellY, destinationCellX, destinationCellY;

            sourceCellX      = Convert.ToInt32(i_Move[0]) - 65;
            sourceCellY      = Convert.ToInt32(i_Move[1]) - 97;
            destinationCellX = Convert.ToInt32(i_Move[3]) - 65;
            destinationCellY = Convert.ToInt32(i_Move[4]) - 97;

            eCheckerType checker = eCheckerType.EmptyCell;

            if (ValidationProcess.IsLegalMoveFormat(i_Move, i_Board.BoardSize))
            {
                sourceCell = i_Board.BoardArray[sourceCellY, sourceCellX];

                destinationCell = i_Board.BoardArray[destinationCellY, destinationCellX];

                if (ValidationProcess.IsLegalMove(sourceCell, destinationCell, i_Board, Player1.MyTurn ? Player2.Name : Player1.Name))
                {
                    aMoveWasMade                        = true;
                    destinationCell.Checker             = sourceCell.Checker;
                    destinationCell.Checker.Player.Name = sourceCell.Checker.Player.Name;
                    checker            = sourceCell.Checker.CheckerType;
                    sourceCell.Checker = null;

                    if (Math.Abs(destinationCellY - sourceCellY) == 2)
                    {
                        //eating down
                        if (destinationCellY - sourceCellY == 2)
                        {
                            //eating down & right
                            if (destinationCellX - sourceCellX == 2)
                            {
                                i_Board.BoardArray[sourceCellY + 1, sourceCellX + 1].Checker.Player.NumOfCheckersAlive--;
                                i_Board.BoardArray[sourceCellY + 1, sourceCellX + 1].Checker = null;
                                OnEatChecker(new Location(sourceCellY + 1, sourceCellX + 1));
                            }
                            //eating down & left
                            else
                            {
                                i_Board.BoardArray[sourceCellY + 1, sourceCellX - 1].Checker.Player.NumOfCheckersAlive--;
                                i_Board.BoardArray[sourceCellY + 1, sourceCellX - 1].Checker = null;
                                OnEatChecker(new Location(sourceCellY + 1, sourceCellX - 1));
                            }
                            string nextMoveDownAndRight = "" + i_Move[3] + i_Move[4] + ">" +
                                                          char.ConvertFromUtf32(Convert.ToInt32(i_Move[3]) + 2) +
                                                          char.ConvertFromUtf32(Convert.ToInt32(i_Move[4]) + 2);
                            aDoubleMoveWasMade = DoMove(nextMoveDownAndRight, i_Board, false);
                            if (aDoubleMoveWasMade)
                            {
                                OnDoubleEat(nextMoveDownAndRight);
                            }

                            string nextMoveDownAndLeft = "" + i_Move[3] + i_Move[4] + ">" +
                                                         char.ConvertFromUtf32(Convert.ToInt32(i_Move[3]) - 2) +
                                                         char.ConvertFromUtf32(Convert.ToInt32(i_Move[4]) + 2);
                            aDoubleMoveWasMade = DoMove(nextMoveDownAndLeft, i_Board, false);
                            if (aDoubleMoveWasMade)
                            {
                                OnDoubleEat(nextMoveDownAndLeft);
                            }
                        }
                        //eating up
                        else
                        {
                            //eating up & right
                            if (destinationCellX - sourceCellX == 2)
                            {
                                i_Board.BoardArray[sourceCellY - 1, sourceCellX + 1].Checker.Player.NumOfCheckersAlive--;
                                i_Board.BoardArray[sourceCellY - 1, sourceCellX + 1].Checker = null;
                                OnEatChecker(new Location(sourceCellY - 1, sourceCellX + 1));
                            }
                            //eating up & left
                            else
                            {
                                i_Board.BoardArray[sourceCellY - 1, sourceCellX - 1].Checker.Player.NumOfCheckersAlive--;
                                i_Board.BoardArray[sourceCellY - 1, sourceCellX - 1].Checker = null;
                                OnEatChecker(new Location(sourceCellY - 1, sourceCellX - 1));
                            }

                            string nextMoveUpAndRight = "" + i_Move[3] + i_Move[4] + ">" +
                                                        char.ConvertFromUtf32(Convert.ToInt32(i_Move[3]) + 2) +
                                                        char.ConvertFromUtf32(Convert.ToInt32(i_Move[4]) - 2);

                            aDoubleMoveWasMade = DoMove(nextMoveUpAndRight, i_Board, false);
                            if (aDoubleMoveWasMade)
                            {
                                OnDoubleEat(nextMoveUpAndRight);
                            }

                            string nextMoveUpAndLeft = "" + i_Move[3] + i_Move[4] + ">" +
                                                       char.ConvertFromUtf32(Convert.ToInt32(i_Move[3]) - 2) +
                                                       char.ConvertFromUtf32(Convert.ToInt32(i_Move[4]) - 2);

                            aDoubleMoveWasMade = DoMove(nextMoveUpAndLeft, i_Board, false);
                            if (aDoubleMoveWasMade)
                            {
                                OnDoubleEat(nextMoveUpAndLeft);
                            }
                        }
                    }
                }
            }

            Location destnationLocation = new Location(destinationCellY, destinationCellX);

            if (aMoveWasMade)
            {
                OnGameMove(destnationLocation, checker);
            }

            return(aMoveWasMade);
        }