Ejemplo n.º 1
0
        public SimpleSquare FindTheKing(SimpleBoard board, bool quick)
        {
            if (quick)
            {
                return(board.kingSquare);
            }
            else
            {
                SimpleSquare kingSquare = null;
                for (int i = 0; i < board.OccupationArray.GetLength(0); i++)     //Rows
                {
                    for (int j = 0; j < board.OccupationArray.GetLength(1); j++) //Columns
                    {
                        if (board.OccupationArray[j, i] == Square.occupation_type.King)
                        {
                            kingSquare = new SimpleSquare(j, i, Square.occupation_type.King, board.SquareTypeArray[j, i]);
                            return(kingSquare);
                        }
                    }
                }
                if (kingSquare == null)
                {
                    return(null);
                }

                return(kingSquare);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Makes the move and process takes etc
        /// </summary>
        /// <param name="move"></param>
        public void  MakeMove(Move move, SimpleBoard initialBoard)
        {
            //Use copy contructor
            board = new SimpleBoard(initialBoard);
            //Determine who is making the move
            bool isDefender = false;
            bool isAttacker = false;
            bool isKing     = false;
            bool Error      = false;

            if (board.OccupationArray[move.startColumn, move.startRow] == Square.occupation_type.Defender)
            {
                isDefender = true;
            }
            if (board.OccupationArray[move.startColumn, move.startRow] == Square.occupation_type.Attacker)
            {
                isAttacker = true;
            }
            if (board.OccupationArray[move.startColumn, move.startRow] == Square.occupation_type.King)
            {
                isKing = true;
            }

            //Make the move
            if (board.OccupationArray[move.endColumn, move.endRow] != Square.occupation_type.Empty)
            {
                //Error somewhere
                Error = true;
                throw new Exception();
            }
            board.OccupationArray[move.endColumn, move.endRow]     = board.OccupationArray[move.startColumn, move.startRow];
            board.OccupationArray[move.startColumn, move.startRow] = Square.occupation_type.Empty;

            //Process takes
            CheckAndProcessTake();

            //Reassign kingSquare
            if (isKing)
            {
                board.kingSquare = new SimpleSquare(move.endColumn, move.endRow, Square.occupation_type.King, board.SquareTypeArray[move.endColumn, move.endRow]);
            }
        }
Ejemplo n.º 3
0
        //Copy constructor
        public SimpleBoard(SimpleBoard input)
        {
            int SizeX = input.OccupationArray.GetLength(0);
            int SizeY = input.OccupationArray.GetLength(1);

            Square.occupation_type[,] newOcc = new Square.occupation_type[SizeX, SizeY];
            Square.square_type[,] newTypes   = new Square.square_type[SizeX, SizeY];

            for (int i = 0; i < SizeY; i++)     //Rows
            {
                for (int j = 0; j < SizeX; j++) //Columns
                {
                    newOcc[j, i] = input.OccupationArray[j, i];
                    if (input.OccupationArray[j, i] == Square.occupation_type.King)
                    {
                        this.kingSquare = new SimpleSquare(j, i, Square.occupation_type.King, input.SquareTypeArray[j, i]);
                    }
                    newTypes[j, i] = input.SquareTypeArray[j, i];
                }
            }

            this.OccupationArray = newOcc;
            this.SquareTypeArray = newTypes;
        }