Esempio n. 1
0
        public SweeperAgent(  IList<IList<MINEWND>> Mines, int XNum, int YNum)
        {
            KB = new SimpleList(XNum * YNum,3);
            Requested = new SimpleList(XNum * YNum,2);
            Output = new SimpleList(XNum * YNum,2);
            m_uXNum = XNum;
            m_uYNum = YNum;
            m_pMines = new MINEWND[m_uXNum][];
            foreach (var i in Enumerable.Range(0, m_uXNum))
                m_pMines[i] = new MINEWND[m_uYNum];

            foreach (var i in Enumerable.Range(0, m_uXNum))
            {
                foreach (var j in Enumerable.Range(0, m_uYNum))
                {
                    m_pMines[i][j] = Mines[i][j];
                }
            }
            //Now the m_PMines are bounded with the one in Game.cs!!!
            /*
            foreach (var i in Enumerable.Range(0, m_uXNum))
            {
                foreach (var j in Enumerable.Range(0, m_uYNum))
                {
                    m_pMines[i][j].uAttrib = Attrib.Mine;
                }
            }
             * */
        }
Esempio n. 2
0
 /// <summary>
 /// Initializes a new instance of the Game class using the specified board size
 /// </summary>
 public Game(int XNum, int YNum, int MineNum)
 {
     m_uXNum = XNum;
     m_uYNum = YNum;
     m_pMines = new MINEWND[m_uXNum][];
     m_uGameState = GameState.Normal;
     m_uMineNum = MineNum;
     m_nLeaveNum = m_uMineNum;
     InitializeBoard();
 }
Esempio n. 3
0
        /// <summary>
        /// Populates the m_pMines array and set up the inintial board state, set mines
        /// </summary>
        private void InitializeBoard()
        {
            foreach  (var i in Enumerable.Range(0,m_uXNum) )
                m_pMines[i] = new MINEWND[m_uYNum];
            foreach (var i in Enumerable.Range(0, m_uXNum))
            {
                foreach (var j in Enumerable.Range(0, m_uYNum))
                {
                    m_pMines[i][j] = new MINEWND();
                    m_pMines[i][j].uRow = i;
                    m_pMines[i][j].uCol = j;
                    m_pMines[i][j].uState = State.Normal;
                    m_pMines[i][j].uAttrib = Attrib.Empty;
                    m_pMines[i][j].uOldState = State.Normal;
                    m_pMines[i][j].uEstimation = Estimation.None;
                }
            }
            //随机布置地雷

            Random rnd = new Random();

            int k;
            for (k=0; k<m_uMineNum; k++)
            {
                int i = (int)Math.Floor(m_uXNum * rnd.NextDouble());
                int j = (int)Math.Floor(m_uYNum * rnd.NextDouble());
                if (m_pMines[i][j].uAttrib == Attrib.Mine) k--;
                else      m_pMines[i][j].uAttrib = Attrib.Mine;
            }
            //Agent
            sweeperAgent =new  SweeperAgent(m_pMines, m_uXNum,m_uYNum);
        }