예제 #1
0
 public void FlipPiece_PositiveTest()
 {
     m_board = new Board(8);
     m_board.SetFieldValue(FieldValue.Black, new Coords(0, 0));
     m_board.FlipPiece(new Coords(0, 0));
     Assert.AreEqual(FieldValue.White, m_board.GetFieldValue(new Coords(0, 0)));
 }
예제 #2
0
        public void GetFieldValue_NegativeTest()
        {
            m_board = new Board(8);
            bool exceptionThrown = false;

            try { m_board.GetFieldValue(new Coords(0, -1)); }
            catch (ArgumentOutOfRangeException) { exceptionThrown = true; }

            Assert.IsTrue(exceptionThrown);
            exceptionThrown = false;

            try { m_board.GetFieldValue(new Coords(-1, -1)); }
            catch (ArgumentOutOfRangeException) {exceptionThrown = true;}

            Assert.IsTrue(exceptionThrown);
            exceptionThrown = false;

            try { m_board.GetFieldValue(new Coords(-1, 0)); }
            catch (ArgumentOutOfRangeException) { exceptionThrown = true; }

            Assert.IsTrue(exceptionThrown);
            exceptionThrown = false;

            try { m_board.GetFieldValue(new Coords(8, 0)); }
            catch (ArgumentOutOfRangeException) { exceptionThrown = true; }

            Assert.IsTrue(exceptionThrown);
            exceptionThrown = false;

            try { m_board.GetFieldValue(new Coords(0, 8)); }
            catch (ArgumentOutOfRangeException) { exceptionThrown = true; }

            Assert.IsTrue(exceptionThrown);
            exceptionThrown = false;

            try { m_board.GetFieldValue(new Coords(8, 8)); }
            catch (ArgumentOutOfRangeException) { exceptionThrown = true; }

            Assert.IsTrue(exceptionThrown);
            exceptionThrown = false;

            try { m_board.GetFieldValue(new Coords(8, -1)); }
            catch (ArgumentOutOfRangeException) { exceptionThrown = true; }

            Assert.IsTrue(exceptionThrown);
            exceptionThrown = false;

            try { m_board.GetFieldValue(new Coords(-1, 8)); }
            catch (ArgumentOutOfRangeException) { exceptionThrown = true; }

            Assert.IsTrue(exceptionThrown);
        }
        /// <summary>
        /// Sets the board that should be shown in the GUI.
        /// 
        /// TODO: Remove listener for old board.
        /// </summary>
        public void SetBoard(Board board)
        {
            Rows = new ObservableCollection<ObservableCollection<GUIField>>();
                m_board = board;

                //Listen for new board
                m_board.BoardChanged += BoardChanged;

                for (int row = 0; row < m_board.Size; row++)
                {
                    var columns = new ObservableCollection<GUIField>();
                    for (int col = 0; col < m_board.Size; col++)
                    {
                        var coords = new Coords(col, row);
                        var field = new GUIField(board.GetFieldValue(coords), coords);
                        columns.Add(field);
                    }

                    Rows.Add(columns);
                }

                this.DataContext = Rows;
        }
        /// <summary>
        /// Sets the board that should be shown in the GUI.
        ///
        /// TODO: Remove listener for old board.
        /// </summary>
        public void SetBoard(Board board)
        {
            Rows    = new ObservableCollection <ObservableCollection <GUIField> >();
            m_board = board;

            //Listen for new board
            m_board.BoardChanged += BoardChanged;

            for (int row = 0; row < m_board.Size; row++)
            {
                var columns = new ObservableCollection <GUIField>();
                for (int col = 0; col < m_board.Size; col++)
                {
                    var coords = new Coords(col, row);
                    var field  = new GUIField(board.GetFieldValue(coords), coords);
                    columns.Add(field);
                }

                Rows.Add(columns);
            }

            this.DataContext = Rows;
        }
예제 #5
0
 public void SetStartValues_PositiveTest()
 {
     m_board = new Board(8);
     m_board.SetStartValues();
     Assert.AreEqual(2, m_board.CountWhites);
     Assert.AreEqual(2, m_board.CountBlacks);
     Assert.AreEqual(m_board.GetFieldValue(new Coords(4, 4)), m_board.GetFieldValue(new Coords(3, 3)));
     Assert.AreEqual(m_board.GetFieldValue(new Coords(3, 4)), m_board.GetFieldValue(new Coords(4, 3)));
 }