public void Play(int nrMoves) { var random = new Random(); while (nrMoves > 0) { var alivePieces = ChessPieces.Where(c => c.IsAlive); var randomPiece = alivePieces.ElementAt(random.Next(alivePieces.Count())); var commands = MovementCommands.Where(c => c.Item1 == randomPiece.GetType()).Select(c => c.Item2).ToList(); var validPositions = GetValidPositions(randomPiece, commands); if (validPositions.Count() == 0) { continue; } var appliedMove = validPositions.ElementAt(random.Next(validPositions.Count())); var existingPiece = PieceAlreadyExists(appliedMove); if (existingPiece != null) { AttackCommand.ExecuteCommnad(randomPiece, existingPiece); NotifyAllObservers(); } else { randomPiece.Position.X = appliedMove.X; randomPiece.Position.Y = appliedMove.Y; } nrMoves--; } }