Esempio n. 1
0
        private void addNextLocationIfPossible(Soldier i_Soldier, eVertical i_VerticalDirection, eHorizontal i_HorizontalDirection, ref List <Location> io_Locations)
        {
            Location nextLocation = new Location(i_Soldier.Location.Row + (int)i_VerticalDirection, i_Soldier.Location.Col + (int)i_HorizontalDirection);

            if (locationExistInBoard(nextLocation))
            {
                io_Locations.Add(nextLocation);
            }
        }
Esempio n. 2
0
        private void addEatMoveIfExist(Soldier i_Soldier, eVertical i_VerticalDirection, eHorizontal i_HorizontalDirection, ref List <Move> io_EatMoves)
        {
            Move eatMove = getSingleEatMoveOfSoldier(i_Soldier, i_VerticalDirection, i_HorizontalDirection);

            if (eatMove != null)
            {
                io_EatMoves.Add(eatMove);
            }
        }
Esempio n. 3
0
        private List <Location> getNextPossibleLocationsOfSoldier(Soldier i_Soldier)
        {
            List <Location> locations         = new List <Location>();
            eVertical       verticalDirection = getVerticalDirection(i_Soldier.Owner);

            addNextLocationIfPossible(i_Soldier, verticalDirection, eHorizontal.Left, ref locations);
            addNextLocationIfPossible(i_Soldier, verticalDirection, eHorizontal.Right, ref locations);
            if (i_Soldier.SoldierType == eSoldierTypes.King)
            {
                verticalDirection = (eVertical)(((int)verticalDirection) * -1); // flip the vertical direction
                addNextLocationIfPossible(i_Soldier, verticalDirection, eHorizontal.Left, ref locations);
                addNextLocationIfPossible(i_Soldier, verticalDirection, eHorizontal.Right, ref locations);
            }

            return(locations);
        }
Esempio n. 4
0
        private List <Move> getLegalEatMovesOfSoldier(Soldier i_Soldier)
        {
            List <Move> finalEatMoves     = new List <Move>();
            eVertical   verticalDirection = getVerticalDirection(i_Soldier.Owner);

            addEatMoveIfExist(i_Soldier, verticalDirection, eHorizontal.Right, ref finalEatMoves);
            addEatMoveIfExist(i_Soldier, verticalDirection, eHorizontal.Left, ref finalEatMoves);

            if (i_Soldier.SoldierType == eSoldierTypes.King)
            {
                verticalDirection = (eVertical)(((int)verticalDirection) * -1); // flip the vertical direction
                addEatMoveIfExist(i_Soldier, verticalDirection, eHorizontal.Right, ref finalEatMoves);
                addEatMoveIfExist(i_Soldier, verticalDirection, eHorizontal.Left, ref finalEatMoves);
            }

            return(finalEatMoves);
        }
Esempio n. 5
0
        private Move getSingleEatMoveOfSoldier(Soldier i_Soldier, eVertical i_VerticalDirection, eHorizontal i_HorizontalDirection)
        {
            Location currentLocation         = i_Soldier.Location;
            Location opponentSoldierLocation = new Location(currentLocation.Row + (int)i_VerticalDirection, currentLocation.Col + (int)i_HorizontalDirection);
            Move     eatMove = null;

            if (locationExistInBoard(opponentSoldierLocation))
            {
                Cell cell = GetCellByLocation(opponentSoldierLocation);

                if (!cell.IsCellEmpty() && cell.Soldier.Owner != i_Soldier.Owner)
                {
                    Location jumppingLocation = new Location(opponentSoldierLocation.Row + (int)i_VerticalDirection, opponentSoldierLocation.Col + (int)i_HorizontalDirection);

                    if (locationExistInBoard(jumppingLocation) && GetCellByLocation(jumppingLocation).IsCellEmpty())
                    {
                        eatMove = new Move(currentLocation, jumppingLocation);
                    }
                }
            }

            return(eatMove);
        }