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); } } }
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); } }