Exemple #1
0
 public void InitWhiteTeam()
 {
     for (int i = 0; i < (this.m_Size - 2) / 2; i++)
     {
         for (int j = 0; j < this.m_Size; j++)
         {
             //if the row is even
             if (i % 2 == 0)
             {
                 if (j % 2 != 0)
                 {
                     Possition tempPossition = new Possition(j, i);
                     Soilder   tempSoilder   = new Soilder(Soilder.Group.White, tempPossition);
                     InsertSoilder(tempSoilder);
                 }
             }
             else
             {
                 if (j % 2 == 0)
                 {
                     Possition tempPossition = new Possition(j, i);
                     Soilder   tempSoilder   = new Soilder(Soilder.Group.White, tempPossition);
                     InsertSoilder(tempSoilder);
                 }
             }
         }
     }
 }
Exemple #2
0
        private List <Move> createWhitePlayerEatingMoves(Soilder i_Mover)
        {
            Move newLegalMove;
            //an empty list to hold possible moves
            List <Move> moves = new List <Move>();
            //create the two possible possitions in the right diriction and possions of the victim
            Possition double_right_down = new Possition((int)i_Mover.m_Possition.m_Column + 2, (int)i_Mover.m_Possition.m_Row + 2);
            Possition double_left_down  = new Possition((int)i_Mover.m_Possition.m_Column - 2, (int)i_Mover.m_Possition.m_Row + 2);
            Possition victem_right_down = new Possition((int)i_Mover.m_Possition.m_Column + 1, (int)i_Mover.m_Possition.m_Row + 1);
            Possition victem_left_down  = new Possition((int)i_Mover.m_Possition.m_Column - 1, (int)i_Mover.m_Possition.m_Row + 1);

            //check in both directions that the wanted square is empty on board , that victem existis, and is of a different group
            if (possitionOnBoardAndEmpty(double_right_down, m_Size) &&                 //if the sqare is on the board and free
                (soilderAt(victem_right_down) != null) &&                              //if the victim sqare is not null
                (i_Mover.Team != soilderAt(victem_right_down).Team))                   //if the victem is of a differnt team
            {
                newLegalMove = new Move(i_Mover.m_Possition, double_right_down, true); //set as eating move
                moves.Add(newLegalMove);
            }
            if (possitionOnBoardAndEmpty(double_left_down, m_Size) &&                 //if the sqare is on the board and free
                (soilderAt(victem_left_down) != null) &&                              //if the victim sqare is not null
                (i_Mover.Team != soilderAt(victem_left_down).Team))                   //if the victem is of a differnt team
            {
                newLegalMove = new Move(i_Mover.m_Possition, double_left_down, true); //set as eating move
                moves.Add(newLegalMove);
            }
            return(moves);
        }
Exemple #3
0
 public void InitBlackTeam()
 {
     for (int i = ((this.m_Size + 2) / 2); i < this.m_Size; i++)
     {
         for (int j = 0; j < this.m_Size; j++)
         {
             if (i % 2 != 0)
             {
                 if (j % 2 == 0)
                 {
                     Possition tempPossition = new Possition(j, i);
                     Soilder   tempSoilder   = new Soilder(Soilder.Group.Black, tempPossition);
                     InsertSoilder(tempSoilder);
                 }
             }
             else
             {
                 if (j % 2 != 0)
                 {
                     Possition tempPossition = new Possition(j, i);
                     Soilder   tempSoilder   = new Soilder(Soilder.Group.Black, tempPossition);
                     InsertSoilder(tempSoilder);
                 }
             }
         }
     }
 }
Exemple #4
0
        public void Move(Move i_Move)
        {
            //use move to change the board
            m_board[(int)i_Move.m_To.m_Row, (int)i_Move.m_To.m_Column] = m_board[(int)i_Move.m_From.m_Row, (int)i_Move.m_From.m_Column];
            //update the possition soilder
            Possition temp = i_Move.m_To;

            soilderAt(i_Move.m_To).Possition = temp;
            m_board[(int)i_Move.m_From.m_Row, (int)i_Move.m_From.m_Column] = null;
            //update is king field
            upDateIsKing(soilderAt(i_Move.m_To));
        }
Exemple #5
0
        private bool possitionOnBoardAndEmpty(Possition i_Possition, int i_SizeOfBoard)
        {
            Boolean answer = false;

            //check if possition is on board
            if (i_Possition.isOnBoard(i_SizeOfBoard))
            {
                answer = true;
            }
            if (answer)
            {
                answer = (m_board[(int)i_Possition.m_Row, (int)i_Possition.m_Column] == null); //checks if a given position on the board is empty
            }
            return(answer);
        }
        //list conatins move

        public Move strToMove(String i_MoveToPlay)
        {
            int       col1         = i_MoveToPlay[0] - 65;
            int       row1         = i_MoveToPlay[1] - 97;
            int       col2         = i_MoveToPlay[3] - 65;
            int       row2         = i_MoveToPlay[4] - 97;
            Boolean   isEatingMove = false;
            Possition from         = new Possition(col1, row1);
            Possition to           = new Possition(col2, row2);

            if (Math.Abs(col1 - col2) == 2 && Math.Abs(row1 - row2) == 2)
            {
                isEatingMove = true;
            }
            Move nextMove = new Move(from, to, isEatingMove);

            return(nextMove);
        }
Exemple #7
0
        private List <Move> createBlackPlayerMoves(Soilder i_Mover)
        {
            Move        newLegalMove;
            List <Move> moves = new List <Move>();        //an empty list to hold possible moves
            //create the two possible possitions in the right diriction
            Possition right_up = new Possition((int)i_Mover.m_Possition.m_Column + 1, (int)i_Mover.m_Possition.m_Row - 1);
            Possition left_up  = new Possition((int)i_Mover.m_Possition.m_Column - 1, (int)i_Mover.m_Possition.m_Row - 1);

            //check in both directions that the wanted square is empty
            if (possitionOnBoardAndEmpty(right_up, m_Size))
            {
                newLegalMove = new Move(i_Mover.m_Possition, right_up, false);//set as not eating move
                moves.Add(newLegalMove);
            }
            if (possitionOnBoardAndEmpty(left_up, m_Size))
            {
                newLegalMove = new Move(i_Mover.m_Possition, left_up, false);//set as not eating move
                moves.Add(newLegalMove);
            }
            return(moves);
        }
Exemple #8
0
        public void Eat(Move i_Move)
        {
            //move the to the eating piece
            m_board[(int)i_Move.m_To.m_Row, (int)i_Move.m_To.m_Column] = m_board[(int)i_Move.m_From.m_Row, (int)i_Move.m_From.m_Column];
            //update the possition soilder
            Possition temp = i_Move.m_To;

            soilderAt(i_Move.m_To).Possition = temp;
            m_board[(int)i_Move.m_From.m_Row, (int)i_Move.m_From.m_Column] = null;
            upDateIsKing(soilderAt(i_Move.m_To));
            //find the dead soilder - remove from board
            Soilder toBeRemoved;
            int     xVal = (int)i_Move.m_From.m_Row - (int)i_Move.m_To.m_Row;
            int     yVal = (int)i_Move.m_From.m_Column - (int)i_Move.m_To.m_Column;

            if (xVal < 0)     //this means we are eating down
            {
                if (yVal < 0) //this means we are eating down and right
                {
                    toBeRemoved = m_board[(int)i_Move.m_From.m_Row + 1, (int)i_Move.m_From.m_Column + 1];
                }
                else         //this means we are eating down and left
                {
                    toBeRemoved = m_board[(int)i_Move.m_From.m_Row + 1, (int)i_Move.m_From.m_Column - 1];
                }
            }
            else              //this means we are eating up
            {
                if (yVal < 0) //this means we are eating up and right
                {
                    toBeRemoved = m_board[(int)i_Move.m_From.m_Row - 1, (int)i_Move.m_From.m_Column + 1];
                }
                else         //this means we are eating up and left
                {
                    toBeRemoved = m_board[(int)i_Move.m_From.m_Row - 1, (int)i_Move.m_From.m_Column - 1];
                }
            }
            this.DeleteSoilder(toBeRemoved);
        }
Exemple #9
0
 public Soilder soilderAt(Possition i_Position)
 {
     return(m_board[(int)i_Position.m_Row, (int)i_Position.m_Column]);
 }
Exemple #10
0
        public Boolean   m_IsEatingMove; //marks a move as an eating move

        public Move(Possition i_From, Possition i_To, Boolean i_Eat)
        {
            this.m_From    = i_From;
            this.m_To      = i_To;
            m_IsEatingMove = i_Eat;
        }
Exemple #11
0
 //a counstractor for a soilder
 public Soilder(Group i_Team, Possition i_StartingLocation)
 {
     m_Group     = i_Team;
     m_Possition = i_StartingLocation;
     m_IsKing    = false;
 }