Example #1
0
        /// <summary>
        /// Reset the board to initial state (player one and two with pieces in start positions).
        /// </summary>
        public void Reset()
        {
            PlayerOnePieces = new List<CheckersPiece>();
            PlayerTwoPieces = new List<CheckersPiece>();

            for (int c = 0; c < Size; c++)
            {
                for (int r = 0; r < Size; r++)
                {
                    var square = new CheckersSquare(c, r);

                    if (square.State == CheckersSquareState.Free)
                    {
                        if (r < 3)
                        {
                            var piece = new CheckersPiece(CheckersPlayer.PlayerOne);
                            PlayerOnePieces.Add(piece);
                            square.PutPiece(piece);
                        }
                        else if (r >= Size - 3)
                        {
                            var piece = new CheckersPiece(CheckersPlayer.PlayerTwo);
                            PlayerTwoPieces.Add(piece);
                            square.PutPiece(piece);
                        }
                    }

                    m_squares[c, r] = square;
                }
            }
        }
Example #2
0
		public static GameObject CreateGameObject (CheckersSquare model)
		{
			var go = (GameObject)GameObject.Instantiate (s_squarePrefab);
			go.GetComponent<SquareController> ().Model = model;
			
			return go;
		}
        public void PutPiece_PlayerSquare_False()
        {
            var square = new CheckersSquare(3, 2);
            square.PutPiece(new CheckersPiece(CheckersPlayer.PlayerOne));

            Assert.IsFalse(square.PutPiece(new CheckersPiece(CheckersPlayer.PlayerOne)));
        }
        public void Equals_OtherEqualSquare_True()
        {
            var square = new CheckersSquare(3, 3);
            var other = new CheckersSquare(3, 3);

            Assert.IsTrue(square.Equals(other));
        }
        public void Equals_OtherDiffSquare_False()
        {
            var square = new CheckersSquare(3, 2);
            var other = new CheckersSquare(3, 3);

            Assert.IsFalse(square.Equals(other));
        }
        public void GetHashCode_DiffSquares_DiffHashes()
        {
            var square = new CheckersSquare(3, 3);
            var other = new CheckersSquare(3, 2);

            Assert.AreNotEqual (square.GetHashCode (), other.GetHashCode ());
        }
Example #7
0
        /// <summary>
        /// Reset the board to initial state (player one and two with pieces in start positions).
        /// </summary>
        public void Reset()
        {
            PlayerOnePieces = new List <CheckersPiece> ();
            PlayerTwoPieces = new List <CheckersPiece> ();

            for (int c = 0; c < Size; c++)
            {
                for (int r = 0; r < Size; r++)
                {
                    var square = new CheckersSquare(c, r);

                    if (square.State == CheckersSquareState.Free)
                    {
                        if (r < 3)
                        {
                            var piece = new CheckersPiece(CheckersPlayer.PlayerOne);
                            PlayerOnePieces.Add(piece);
                            square.PutPiece(piece);
                        }
                        else if (r >= Size - 3)
                        {
                            var piece = new CheckersPiece(CheckersPlayer.PlayerTwo);
                            PlayerTwoPieces.Add(piece);
                            square.PutPiece(piece);
                        }
                    }

                    m_squares[c, r] = square;
                }
            }
        }
        public void PutPiece_NoPlayableSquare_Exception()
        {
            var square = new CheckersSquare(0, 0);

            ExceptionAssert.IsThrowing(new ArgumentException("Attempt to put a piece in a not playable square."), () =>
            {
                square.PutPiece(new CheckersPiece(CheckersPlayer.PlayerOne));
            });
        }
Example #9
0
        private CheckersSquare GetPlayableSquare()
        {
            CheckersSquare square;
            var            rnd = RandomizationProvider.Current;

            do
            {
                square = new CheckersSquare(rnd.GetInt(0, m_boardSize), rnd.GetInt(0, m_boardSize));
            } while (square.State == CheckersSquareState.NotPlayable);

            return(square);
        }
Example #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GeneticSharp.Extensions.Checkers.CheckersMove"/> class.
        /// </summary>
        /// <param name="piece">The piece which will be moved.</param>
        /// <param name="toSquare">The target square.</param>
        public CheckersMove(CheckersPiece piece, CheckersSquare toSquare)
        {
            ExceptionHelper.ThrowIfNull("piece", piece);

            if (piece.CurrentSquare == null)
            {
                throw new ArgumentException("A piece for a move should have a current square defined.");
            }

            ExceptionHelper.ThrowIfNull("toSquare", toSquare);

            Piece = piece;
            ToSquare = toSquare;
        }
        private CheckersSquare FindPlayableSquare()
        {
            CheckersSquare square;
            var            rnd = RandomizationProvider.Current;

            do
            {
                var columnIndex = rnd.GetInt(0, m_boardSize);
                var rowIndex    = columnIndex % 2 == 0 ? rnd.GetOddInt(0, m_boardSize) : rnd.GetEvenInt(0, m_boardSize);
                square = new CheckersSquare(columnIndex, rowIndex);
            }while (square.State == CheckersSquareState.NotPlayable);

            return(square);
        }
Example #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GeneticSharp.Extensions.Checkers.CheckersMove"/> class.
        /// </summary>
        /// <param name="piece">The piece which will be moved.</param>
        /// <param name="toSquare">The target square.</param>
        public CheckersMove(CheckersPiece piece, CheckersSquare toSquare)
        {
            ExceptionHelper.ThrowIfNull("piece", piece);

            if (piece.CurrentSquare == null)
            {
                throw new ArgumentException("A piece for a move should have a current square defined.");
            }

            ExceptionHelper.ThrowIfNull("toSquare", toSquare);

            Piece    = piece;
            ToSquare = toSquare;
        }
Example #13
0
        private bool CanCapture(CheckersSquare to, CheckersSquare from, CheckersSquareState opponentState, int indexModifier)
        {
            if (to.RowIndex == from.RowIndex + (2 * indexModifier))
            {
                // To right or To left?
                if (to.ColumnIndex == from.ColumnIndex + (2 * indexModifier) &&
                    GetSquare(from.ColumnIndex + (1 * indexModifier), from.RowIndex + (1 * indexModifier)).State == opponentState)
                {
                    return(true);
                }
                else if (to.ColumnIndex == from.ColumnIndex - (2 * indexModifier) &&
                         GetSquare(from.ColumnIndex - (1 * indexModifier), from.RowIndex + (1 * indexModifier)).State == opponentState)
                {
                    return(true);
                }
            }

            return(false);
        }
        public void Constructor_ColumnAndRowIndex_FreeOrNotPlayable()
        {
            var target = new CheckersSquare(0, 0);
            Assert.AreEqual(CheckersSquareState.NotPlayable, target.State);

            target = new CheckersSquare(7, 7);
            Assert.AreEqual(CheckersSquareState.NotPlayable, target.State);

            target = new CheckersSquare(1, 0);
            Assert.AreEqual(CheckersSquareState.Free, target.State);

            target = new CheckersSquare(2, 0);
            Assert.AreEqual(CheckersSquareState.NotPlayable, target.State);

            target = new CheckersSquare(3, 0);
            Assert.AreEqual(CheckersSquareState.Free, target.State);

            target = new CheckersSquare(4, 0);
            Assert.AreEqual(CheckersSquareState.NotPlayable, target.State);
        }
Example #15
0
        /// <summary>
        /// Reset the board to initial state (player one and two with pieces in start positions).
        /// </summary>
        public void Reset()
        {
            // Creates the two lists of pieces por player one and two.ß
            PlayerOnePieces = new List <CheckersPiece>();
            PlayerTwoPieces = new List <CheckersPiece>();

            for (int c = 0; c < Size; c++)
            {
                for (int r = 0; r < Size; r++)
                {
                    // For each combinatino of collumn and row of the board
                    // Is create a new CheckersSquare.
                    var square = new CheckersSquare(c, r);

                    // If the sqaure is free.
                    if (square.State == CheckersSquareState.Free)
                    {
                        // If the actual line index is lower than 3,
                        // then is a square for player one.
                        if (r < 3)
                        {
                            var piece = new CheckersPiece(CheckersPlayer.PlayerOne);
                            PlayerOnePieces.Add(piece);
                            square.PutPiece(piece);
                        }
                        /// fi the actual line index is bigger than max lines index -3,
                        /// then it is a square for player two.
                        else if (r >= Size - 3)
                        {
                            var piece = new CheckersPiece(CheckersPlayer.PlayerTwo);
                            PlayerTwoPieces.Add(piece);
                            square.PutPiece(piece);
                        }
                    }

                    m_squares[c, r] = square;
                }
            }
        }
        private CheckersSquare FindPlayableSquare()
        {
            CheckersSquare square;
            var rnd = RandomizationProvider.Current;

            do
            {
                square = new CheckersSquare(rnd.GetInt(0, m_boardSize), rnd.GetInt(0, m_boardSize));
            }
            while (square.State == CheckersSquareState.NotPlayable);

            return square;
        }
        private CheckersSquare FindPlayableSquare()
        {
            CheckersSquare square;
            var rnd = RandomizationProvider.Current;

            do
            {
                var columnIndex = rnd.GetInt(0, m_boardSize);
                var rowIndex = columnIndex % 2 == 0 ? rnd.GetOddInt(0, m_boardSize) : rnd.GetEvenInt(0, m_boardSize);
                square = new CheckersSquare(columnIndex, rowIndex);
            }
            while (square.State == CheckersSquareState.NotPlayable);

            return square;
        }
        public void Equals_NotPiece_False()
        {
            var square = new CheckersSquare(3, 2);

            Assert.IsFalse(square.Equals("square"));
        }
        public void RemovePiece_CurrentSquareNull_False()
        {
            var square = new CheckersSquare(3, 2);

            Assert.IsFalse(square.RemovePiece());
        }