public void TestKnightMoveFromInsideBoard()
        {
            var pos    = new Position(3, 3);
            var knight = new KnightMove();

            var moves = knight.ValidMovesFor(pos).ToArray();

            Assert.IsNotNull(moves);
            Assert.AreEqual(8, moves.Length);

            foreach (var move in moves)
            {
                switch (Math.Abs(move.X - pos.X))
                {
                case 1:
                    Assert.AreEqual(2, Math.Abs(move.Y - pos.Y));
                    break;

                case 2:
                    Assert.AreEqual(1, Math.Abs(move.Y - pos.Y));
                    break;

                default:
                    Assert.Fail();
                    break;
                }
            }
        }
Beispiel #2
0
        public void Play(int moves)
        {
            // TODO: Play the game moves here
            var Queen      = new QueenMove();
            var Knight     = new KnightMove();
            var Bishop     = new BishopMove();
            var Queen_pos  = _startPosition;
            var Knight_pos = _startPosition;
            var Bishop_pos = _startPosition;

            Console.WriteLine("0: My Inint position is {0}", _startPosition);


            for (var move = 1; move <= moves; move++)
            {
                int i = _rnd.Next(1, 4); //Randomly obtained 1 to 3, corresponding to three pieces of random movement.
                if (i == 1)
                {
                    var possibleMoves = Queen.ValidMovesFor(Queen_pos).ToList();
                    if (possibleMoves.Contains(Knight_pos))
                    {
                        possibleMoves.Remove(Knight_pos);
                    }
                    if (possibleMoves.Contains(Bishop_pos))
                    {
                        possibleMoves.Remove(Bishop_pos);
                    }
                    Queen_pos = possibleMoves[_rnd.Next(possibleMoves.Count)];
                    Console.WriteLine("{1}: My Queen position is {0}", Queen_pos, move);
                }
                if (i == 2)
                {
                    var possibleMoves = Knight.ValidMovesFor(Knight_pos).ToList();
                    if (possibleMoves.Contains(Queen_pos))
                    {
                        possibleMoves.Remove(Queen_pos);
                    }
                    if (possibleMoves.Contains(Bishop_pos))
                    {
                        possibleMoves.Remove(Bishop_pos);
                    }
                    Knight_pos = possibleMoves[_rnd.Next(possibleMoves.Count)];
                    Console.WriteLine("{1}: My Knight position is {0}", Knight_pos, move);
                }
                if (i == 3)
                {
                    var possibleMoves = Bishop.ValidMovesFor(Bishop_pos).ToList();
                    if (possibleMoves.Contains(Queen_pos))
                    {
                        possibleMoves.Remove(Queen_pos);
                    }
                    if (possibleMoves.Contains(Knight_pos))
                    {
                        possibleMoves.Remove(Knight_pos);
                    }
                    Bishop_pos = possibleMoves[_rnd.Next(possibleMoves.Count)];
                    Console.WriteLine("{1}: My Bishop_pos position is {0}", Bishop_pos, move);
                }
            }
        }
Beispiel #3
0
        public void Play(int moves)
        {
            var knight    = new KnightMove();
            var knightPos = knightStartPosition;

            var bishop    = new BishopMove();
            var bishopPos = bishopStartPosition;

            var queen    = new QueenMove();
            var queenPos = queenStartPosition;

            Console.WriteLine("0: Knight position is {0}, Bishop position is {1}, Queen position is {2}", knightPos, bishopPos, queenPos);

            for (var move = 1; move <= moves; move++)
            {
                var knightPossibleMoves = knight.ValidMovesFor(knightPos).ToArray();
                knightPos = knightPossibleMoves[_rnd.Next(knightPossibleMoves.Length)];

                var bishopPossibleMoves = bishop.ValidMovesFor(bishopPos).ToArray();
                do
                {
                    bishopPos = bishopPossibleMoves[_rnd.Next(bishopPossibleMoves.Length)];
                } while (bishopPos.Equals(knightPos));

                var queenPossibleMoves = queen.ValidMovesFor(queenPos).ToArray();
                do
                {
                    queenPos = queenPossibleMoves[_rnd.Next(queenPossibleMoves.Length)];
                } while (queenPos.Equals(knightPos) || queenPos.Equals(bishopPos));

                Console.WriteLine("{0}: Knight position is {1}, Bishop position is {2}, Queen position is {3}", move, knightPos, bishopPos, queenPos);
            }
        }
        public void Play(int moves)
        {
            var knight = new KnightMove();
            var pos    = _startPosition;

            Console.WriteLine("0: My position is {0}", pos);

            for (var move = 1; move <= moves; move++)
            {
                var possibleMoves = knight.ValidMovesFor(pos).ToArray();
                pos = possibleMoves[_rnd.Next(possibleMoves.Length)];
                Console.WriteLine("{1}: My position is {0}", pos, move);
            }
        }
        public void TestKnightMoveFromCorner()
        {
            var pos    = new Position(1, 1);
            var knight = new KnightMove();

            var moves = new HashSet <Position>(knight.ValidMovesFor(pos));

            Assert.IsNotNull(moves);
            Assert.AreEqual(2, moves.Count);

            var possibles = new[] { new Position(2, 3), new Position(3, 2) };

            foreach (var possible in possibles)
            {
                Assert.IsTrue(moves.Contains(possible));
            }
        }
        public override Position Play(Dictionary <string, Position> currPosDict)
        {
            //Play the game moves
            var knight = new KnightMove();
            var pos    = _startPosition;

            Console.WriteLine("(Knight)0 My old position is {0}", pos);

            for (var move = 1; move <= _moves; move++)
            {
                var possibleMovesList = knight.ValidMovesFor(pos).ToList();
                possibleMovesList.RemoveAll(x => currPosDict.Any(y => y.Value.X == x.X && y.Value.Y == x.Y));

                var possibleMoves = possibleMovesList.ToArray();
                pos             = possibleMoves[_rnd.Next(possibleMoves.Length)];
                CurrentPosition = pos;
                Console.WriteLine("(Knight){1}: My new position is {0}", pos, move);
            }

            return(CurrentPosition);
        }
Beispiel #7
0
 public override IEnumerable <Position> ValidMovesFor(Position pos)
 {
     return(_knight.ValidMovesFor(pos));
 }